Add libc constraint and libc aware toolchains
- Also get rid of @bazel_skylib dependency
This commit is contained in:
@@ -1,25 +1,46 @@
|
||||
load("@bazel-zig-cc//toolchain/private:defs.bzl", "DEFAULT_INCLUDE_DIRECTORIES", "ZIG_TOOL_PATH", "target_structs")
|
||||
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
|
||||
|
||||
# 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_config.constraint_values,
|
||||
toolchain = "@zig_sdk//private:%s_cc" % zigtarget,
|
||||
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
||||
)
|
||||
# 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"]
|
||||
|
||||
# Zig convention: x86_64/aarch64, linux/macos
|
||||
native.toolchain(
|
||||
name = zigtarget,
|
||||
exec_compatible_with = None,
|
||||
target_compatible_with = target_config.constraint_values,
|
||||
toolchain = "@zig_sdk//private:%s_cc" % zigtarget,
|
||||
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
||||
)
|
||||
_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",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user