2022-09-26 10:14:08 +03:00
|
|
|
load(":defs.bzl", "target_structs", "zig_tool_path")
|
2023-04-21 17:00:03 +03:00
|
|
|
load("@hermetic_cc_toolchain//toolchain:zig_toolchain.bzl", "zig_cc_toolchain_config")
|
2022-04-07 13:15:34 +03:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2022-11-21 06:08:22 +02:00
|
|
|
def declare_cc_toolchains(os, zig_sdk_path):
|
2022-04-07 13:15:34 +03:00
|
|
|
for target_config in target_structs():
|
|
|
|
gotarget = target_config.gotarget
|
|
|
|
zigtarget = target_config.zigtarget
|
|
|
|
|
|
|
|
cxx_builtin_include_directories = []
|
|
|
|
absolute_tool_paths = {}
|
|
|
|
for name, path in target_config.tool_paths.items() + DEFAULT_TOOL_PATHS:
|
|
|
|
if path[0] == "/":
|
|
|
|
absolute_tool_paths[name] = path
|
|
|
|
continue
|
2022-10-01 14:26:45 +03:00
|
|
|
tool_path = zig_tool_path(os).format(
|
|
|
|
zig_tool = path,
|
|
|
|
zigtarget = zigtarget,
|
|
|
|
)
|
2022-09-21 13:14:29 +03:00
|
|
|
absolute_tool_paths[name] = tool_path
|
2022-04-07 13:15:34 +03:00
|
|
|
|
2022-05-25 03:14:35 +03:00
|
|
|
dynamic_library_linkopts = target_config.dynamic_library_linkopts
|
2022-04-07 13:15:34 +03:00
|
|
|
copts = target_config.copts
|
2023-04-19 00:49:23 +03:00
|
|
|
linkopts = target_config.linkopts
|
2022-04-07 13:15:34 +03:00
|
|
|
|
2022-12-18 01:27:21 +02:00
|
|
|
# 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]
|
|
|
|
|
2022-04-07 13:15:34 +03:00
|
|
|
zig_cc_toolchain_config(
|
|
|
|
name = zigtarget + "_cc_config",
|
|
|
|
target = zigtarget,
|
|
|
|
tool_paths = absolute_tool_paths,
|
|
|
|
cxx_builtin_include_directories = cxx_builtin_include_directories,
|
|
|
|
copts = copts,
|
|
|
|
linkopts = linkopts,
|
2022-05-25 03:14:35 +03:00
|
|
|
dynamic_library_linkopts = dynamic_library_linkopts,
|
2022-04-07 13:15:34 +03:00
|
|
|
target_cpu = target_config.bazel_target_cpu,
|
|
|
|
target_system_name = "unknown",
|
|
|
|
target_libc = "unknown",
|
|
|
|
compiler = "clang",
|
|
|
|
abi_version = "unknown",
|
|
|
|
abi_libc_version = "unknown",
|
2022-12-18 01:27:21 +02:00
|
|
|
artifact_name_patterns = artifact_name_pattern_strings,
|
2022-09-26 10:14:08 +03:00
|
|
|
visibility = ["//visibility:private"],
|
2022-04-07 13:15:34 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
native.cc_toolchain(
|
|
|
|
name = zigtarget + "_cc",
|
|
|
|
toolchain_identifier = zigtarget + "-toolchain",
|
|
|
|
toolchain_config = ":%s_cc_config" % zigtarget,
|
2022-12-13 14:38:51 +02:00
|
|
|
all_files = "@zig_sdk//:%s_all_files" % zigtarget,
|
2022-12-13 17:19:42 +02:00
|
|
|
ar_files = "@zig_sdk//:%s_ar_files" % zigtarget,
|
2022-12-13 14:38:51 +02:00
|
|
|
compiler_files = "@zig_sdk//:%s_compiler_files" % zigtarget,
|
|
|
|
linker_files = "@zig_sdk//:%s_linker_files" % zigtarget,
|
2022-04-07 13:15:34 +03:00
|
|
|
dwp_files = "@zig_sdk//:empty",
|
|
|
|
objcopy_files = "@zig_sdk//:empty",
|
|
|
|
strip_files = "@zig_sdk//:empty",
|
|
|
|
supports_param_files = 0,
|
2022-09-26 10:14:08 +03:00
|
|
|
visibility = ["//visibility:private"],
|
2022-04-07 13:15:34 +03:00
|
|
|
)
|