2023-04-21 17:00:03 +03:00
|
|
|
load("@hermetic_cc_toolchain//toolchain/private:defs.bzl", "target_structs")
|
2022-04-06 23:10:45 +03:00
|
|
|
|
2022-04-07 13:15:34 +03:00
|
|
|
def declare_toolchains():
|
2022-04-06 23:10:45 +03:00
|
|
|
for target_config in target_structs():
|
|
|
|
gotarget = target_config.gotarget
|
|
|
|
zigtarget = target_config.zigtarget
|
|
|
|
|
2022-04-13 17:52:25 +03:00
|
|
|
# if the toolchain is libc aware, create two variants for it: one that
|
|
|
|
# is only selected if libc is not expicitly set and another one that is
|
|
|
|
# only selected if the specific libc variant is selected.
|
|
|
|
extra_constraints = []
|
|
|
|
if hasattr(target_config, "libc_constraint"):
|
|
|
|
extra_constraints = ["@zig_sdk//libc:unconstrained"]
|
2022-04-06 23:10:45 +03:00
|
|
|
|
2022-04-13 17:52:25 +03:00
|
|
|
_declare_toolchain(gotarget, zigtarget, target_config.constraint_values + extra_constraints)
|
|
|
|
|
|
|
|
def declare_libc_aware_toolchains():
|
|
|
|
for target_config in target_structs():
|
|
|
|
gotarget = target_config.gotarget
|
|
|
|
zigtarget = target_config.zigtarget
|
|
|
|
|
|
|
|
# if the toolchain is libc aware, create two variants for it: one that
|
|
|
|
# is only selected if libc is not expicitly set and another one that is
|
|
|
|
# only selected if the specific libc variant is selected.
|
|
|
|
if hasattr(target_config, "libc_constraint"):
|
|
|
|
_declare_toolchain(gotarget, zigtarget, target_config.constraint_values + [target_config.libc_constraint])
|
|
|
|
|
|
|
|
def _declare_toolchain(gotarget, zigtarget, target_compatible_with):
|
|
|
|
# register two kinds of toolchain targets: Go and Zig conventions.
|
|
|
|
# Go convention: amd64/arm64, linux/darwin
|
|
|
|
native.toolchain(
|
|
|
|
name = gotarget,
|
|
|
|
exec_compatible_with = None,
|
|
|
|
target_compatible_with = target_compatible_with,
|
2022-09-21 13:14:29 +03:00
|
|
|
toolchain = "@zig_sdk//:%s_cc" % zigtarget,
|
2022-04-13 17:52:25 +03:00
|
|
|
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Zig convention: x86_64/aarch64, linux/macos
|
|
|
|
native.toolchain(
|
|
|
|
name = zigtarget,
|
|
|
|
exec_compatible_with = None,
|
|
|
|
target_compatible_with = target_compatible_with,
|
2022-09-21 13:14:29 +03:00
|
|
|
toolchain = "@zig_sdk//:%s_cc" % zigtarget,
|
2022-04-13 17:52:25 +03:00
|
|
|
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
|
|
|
)
|