Use artifact_name_pattern to specify proper macos and windows artifact names.
On macos, dynamic libraries are generated as "libfoo.dylib". On windows, executables end with ".exe", static libraries end with ".lib", and dynamic libraries end with ".dll".
This commit is contained in:
committed by
Motiejus Jakštys
parent
6ee01496be
commit
cc8f113489
@@ -39,6 +39,10 @@ def declare_cc_toolchains(os, zig_sdk_path):
|
||||
for incl in getattr(target_config, "compiler_extra_includes", []):
|
||||
copts = copts + ["-include", zig_sdk_path + "/" + incl]
|
||||
|
||||
# We can't pass a list of structs to a rule, so we use json encoding.
|
||||
artifact_name_patterns = getattr(target_config, "artifact_name_patterns", [])
|
||||
artifact_name_pattern_strings = [json.encode(p) for p in artifact_name_patterns]
|
||||
|
||||
zig_cc_toolchain_config(
|
||||
name = zigtarget + "_cc_config",
|
||||
target = zigtarget,
|
||||
@@ -53,6 +57,7 @@ def declare_cc_toolchains(os, zig_sdk_path):
|
||||
compiler = "clang",
|
||||
abi_version = "unknown",
|
||||
abi_libc_version = "unknown",
|
||||
artifact_name_patterns = artifact_name_pattern_strings,
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
|
||||
@@ -72,6 +72,13 @@ def _target_macos(gocpu, zigcpu):
|
||||
"@platforms//cpu:{}".format(zigcpu),
|
||||
],
|
||||
tool_paths = {"ld": "ld64.lld"},
|
||||
artifact_name_patterns = [
|
||||
{
|
||||
"category_name": "dynamic_library",
|
||||
"prefix": "lib",
|
||||
"extension": ".dylib",
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
def _target_windows(gocpu, zigcpu):
|
||||
@@ -92,6 +99,23 @@ def _target_windows(gocpu, zigcpu):
|
||||
"@platforms//cpu:{}".format(zigcpu),
|
||||
],
|
||||
tool_paths = {"ld": "ld64.lld"},
|
||||
artifact_name_patterns = [
|
||||
{
|
||||
"category_name": "static_library",
|
||||
"prefix": "",
|
||||
"extension": ".lib",
|
||||
},
|
||||
{
|
||||
"category_name": "dynamic_library",
|
||||
"prefix": "",
|
||||
"extension": ".dll",
|
||||
},
|
||||
{
|
||||
"category_name": "executable",
|
||||
"prefix": "",
|
||||
"extension": ".exe",
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
def _target_linux_gnu(gocpu, zigcpu, glibc_version):
|
||||
@@ -126,6 +150,7 @@ def _target_linux_gnu(gocpu, zigcpu, glibc_version):
|
||||
],
|
||||
libc_constraint = "@zig_sdk//libc:{}".format(glibc_suffix),
|
||||
tool_paths = {"ld": "ld.lld"},
|
||||
artifact_name_patterns = [],
|
||||
)
|
||||
|
||||
def _target_linux_musl(gocpu, zigcpu):
|
||||
@@ -151,4 +176,5 @@ def _target_linux_musl(gocpu, zigcpu):
|
||||
],
|
||||
libc_constraint = "@zig_sdk//libc:musl",
|
||||
tool_paths = {"ld": "ld.lld"},
|
||||
artifact_name_patterns = [],
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
|
||||
load(
|
||||
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
|
||||
"artifact_name_pattern",
|
||||
"feature",
|
||||
"feature_set",
|
||||
"flag_group",
|
||||
@@ -140,6 +141,11 @@ def _zig_cc_toolchain_config_impl(ctx):
|
||||
supports_dynamic_linker,
|
||||
] + _compilation_mode_features(ctx)
|
||||
|
||||
artifact_name_patterns = [
|
||||
artifact_name_pattern(**json.decode(p))
|
||||
for p in ctx.attr.artifact_name_patterns
|
||||
]
|
||||
|
||||
return cc_common.create_cc_toolchain_config_info(
|
||||
ctx = ctx,
|
||||
features = features,
|
||||
@@ -156,6 +162,7 @@ def _zig_cc_toolchain_config_impl(ctx):
|
||||
for name, path in ctx.attr.tool_paths.items()
|
||||
],
|
||||
cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories,
|
||||
artifact_name_patterns = artifact_name_patterns,
|
||||
)
|
||||
|
||||
zig_cc_toolchain_config = rule(
|
||||
@@ -174,6 +181,7 @@ zig_cc_toolchain_config = rule(
|
||||
"compiler": attr.string(),
|
||||
"abi_version": attr.string(),
|
||||
"abi_libc_version": attr.string(),
|
||||
"artifact_name_patterns": attr.string_list(),
|
||||
},
|
||||
provides = [CcToolchainConfigInfo],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user