27fe6c9ffb
motiejus@mtwork:/code/bazel-zig-cc$ bazel build --spawn_strategy=local --platforms @zig_sdk//libc_aware/platform:macos_aarch64_sdk.13.1 test/c:which_libc INFO: Analyzed target //test/c:which_libc (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //test/c:which_libc up-to-date: bazel-bin/test/c/which_libc INFO: Elapsed time: 0.071s, Critical Path: 0.00s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action motiejus@mtwork:/code/bazel-zig-cc$ file bazel-bin/test/c/which_libc bazel-bin/test/c/which_libc: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE> motiejus@mtwork:/code/bazel-zig-cc$
78 lines
3.2 KiB
Python
78 lines
3.2 KiB
Python
load(":defs.bzl", "target_structs", "zig_tool_path")
|
|
load("@bazel-zig-cc//toolchain:zig_toolchain.bzl", "zig_cc_toolchain_config")
|
|
|
|
DEFAULT_TOOL_PATHS = {
|
|
"ar": "ar",
|
|
"gcc": "c++", # https://github.com/bazelbuild/bazel/issues/4644
|
|
"cpp": "/usr/bin/false",
|
|
"gcov": "/usr/bin/false",
|
|
"nm": "/usr/bin/false",
|
|
"objdump": "/usr/bin/false",
|
|
"strip": "/usr/bin/false",
|
|
}.items()
|
|
|
|
def declare_cc_toolchains(os, zig_sdk_path, macos_sdk_versions):
|
|
for target_config in target_structs(macos_sdk_versions):
|
|
gotarget = target_config.gotarget
|
|
zigtarget = target_config.zigtarget
|
|
|
|
absolute_tool_paths = {}
|
|
for name, path in target_config.tool_paths.items() + DEFAULT_TOOL_PATHS:
|
|
if path[0] == "/":
|
|
absolute_tool_paths[name] = path
|
|
continue
|
|
tool_path = zig_tool_path(os).format(
|
|
zig_tool = path,
|
|
zigtarget = zigtarget,
|
|
)
|
|
absolute_tool_paths[name] = tool_path
|
|
|
|
dynamic_library_linkopts = target_config.dynamic_library_linkopts
|
|
copts = target_config.copts
|
|
linkopts = target_config.linkopts
|
|
for s in getattr(target_config, "linker_version_scripts", []):
|
|
linkopts.append("-Wl,--version-script,%s/%s" % (zig_sdk_path, s))
|
|
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,
|
|
tool_paths = absolute_tool_paths,
|
|
cxx_builtin_include_directories = getattr(
|
|
target_config,
|
|
"cxx_builtin_include_directories",
|
|
[],
|
|
),
|
|
copts = copts,
|
|
linkopts = linkopts,
|
|
dynamic_library_linkopts = dynamic_library_linkopts,
|
|
target_cpu = target_config.bazel_target_cpu,
|
|
target_system_name = "unknown",
|
|
target_libc = "unknown",
|
|
compiler = "clang",
|
|
abi_version = "unknown",
|
|
abi_libc_version = "unknown",
|
|
artifact_name_patterns = artifact_name_pattern_strings,
|
|
visibility = ["//visibility:private"],
|
|
)
|
|
|
|
native.cc_toolchain(
|
|
name = zigtarget + "_cc",
|
|
toolchain_identifier = zigtarget + "-toolchain",
|
|
toolchain_config = ":%s_cc_config" % zigtarget,
|
|
all_files = "@zig_sdk//:%s_all_files" % zigtarget,
|
|
ar_files = "@zig_sdk//:%s_ar_files" % zigtarget,
|
|
compiler_files = "@zig_sdk//:%s_compiler_files" % zigtarget,
|
|
linker_files = "@zig_sdk//:%s_linker_files" % zigtarget,
|
|
dwp_files = "@zig_sdk//:empty",
|
|
objcopy_files = "@zig_sdk//:empty",
|
|
strip_files = "@zig_sdk//:empty",
|
|
supports_param_files = 0,
|
|
visibility = ["//visibility:private"],
|
|
)
|