Skip to content

Commit

Permalink
fix: remove hard coded .dll extension
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Oct 5, 2023
1 parent 89db41d commit 6754db4
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions ecsact/private/ecsact_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolcha
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load("//ecsact/private:ecsact_build_recipe.bzl", "EcsactBuildRecipeInfo")

def _ecsact_binary(ctx):
def _ecsact_binary_impl(ctx):
cc_toolchain = find_cc_toolchain(ctx)

temp_dir = ctx.actions.declare_directory(ctx.attr.name)
Expand All @@ -27,8 +27,9 @@ def _ecsact_binary(ctx):

ecsact_toolchain = ctx.toolchains["//ecsact:toolchain_type"].ecsact_info

# TODO(zaucy): derive runtime library extension based on ctx and cc_toolchain
runtime_output_file = ctx.actions.declare_file("{}.dll".format(ctx.attr.name))
preferred_output_extension = ctx.attr.lib_extension

runtime_output_file = ctx.actions.declare_file("{}{}".format(ctx.attr.name, preferred_output_extension))
outputs = [runtime_output_file]
tools = [] + ecsact_toolchain.tool_files

Expand All @@ -40,9 +41,6 @@ def _ecsact_binary(ctx):
args.add("--temp_dir", temp_dir.path)
args.add("-f", "text")

# TODO(zaucy): detect shared library extension
preferred_output_extension = ".dll"

compiler_config = {
"compiler_type": "auto",
"compiler_path": cc_toolchain.compiler_executable,
Expand Down Expand Up @@ -91,8 +89,8 @@ def _ecsact_binary(ctx):
),
]

ecsact_binary = rule(
implementation = _ecsact_binary,
_ecsact_binary = rule(
implementation = _ecsact_binary_impl,
attrs = {
"srcs": attr.label_list(
allow_files = [".ecsact"],
Expand All @@ -107,7 +105,22 @@ ecsact_binary = rule(
"@rules_cc//cc:current_cc_toolchain",
),
),
"lib_extension": attr.string(
mandatory = True,
),
},
toolchains = ["//ecsact:toolchain_type"] + use_cc_toolchain(),
fragments = ["cpp"],
)

def ecsact_binary(**kwargs):
_ecsact_binary(
lib_extension = select({
"@platforms//os:windows": ".dll",
"@platforms//os:linux": ".so",
"@platforms//os:macos": ".dylib",
"@platforms//os:wasi": ".wasm",
"@platforms//os:none": ".wasm", # for non-wasi
}),
**kwargs
)

0 comments on commit 6754db4

Please sign in to comment.