1
hermetic_cc_toolchain/toolchain/toolchain/defs.bzl
laurynasl 4d65b80903 Add libc constraint and libc aware toolchains
- Also get rid of @bazel_skylib dependency
2022-04-14 14:29:06 +00:00

47 lines
2.0 KiB
Python

load("@bazel-zig-cc//toolchain/private:defs.bzl", "target_structs")
def declare_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.
extra_constraints = []
if hasattr(target_config, "libc_constraint"):
extra_constraints = ["@zig_sdk//libc:unconstrained"]
_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,
toolchain = "@zig_sdk//private:%s_cc" % zigtarget,
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,
toolchain = "@zig_sdk//private:%s_cc" % zigtarget,
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)