1

Move toolchainss under @zig_sdk//platform:

This commit is contained in:
laurynasl 2022-04-06 19:46:15 +00:00 committed by Motiejus Jakštys
parent d1b0dddf8c
commit 723e6f051d
7 changed files with 57 additions and 41 deletions

View File

@ -6,10 +6,10 @@ build --worker_sandboxing
build --compilation_mode=opt
build --incompatible_enable_cc_toolchain_resolution
build --extra_toolchains @zig_sdk//:linux_amd64_gnu.2.19_toolchain
build --extra_toolchains @zig_sdk//:linux_arm64_gnu.2.28_toolchain
build --extra_toolchains @zig_sdk//:darwin_amd64_toolchain
build --extra_toolchains @zig_sdk//:darwin_arm64_toolchain
build --extra_toolchains @zig_sdk//toolchain:linux_amd64_gnu.2.19
build --extra_toolchains @zig_sdk//toolchain:linux_arm64_gnu.2.28
build --extra_toolchains @zig_sdk//toolchain:darwin_amd64
build --extra_toolchains @zig_sdk//toolchain:darwin_arm64
test:qemu-aarch64 --test_env=QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/
test:qemu-aarch64 --run_under=qemu-aarch64-static

View File

@ -41,10 +41,10 @@ And this to `.bazelrc`:
```
build --incompatible_enable_cc_toolchain_resolution
build --extra_toolchains @zig_sdk//:linux_amd64_gnu.2.19_toolchain
build --extra_toolchains @zig_sdk//:linux_arm64_gnu.2.28_toolchain
build --extra_toolchains @zig_sdk//:darwin_amd64_toolchain
build --extra_toolchains @zig_sdk//:darwin_arm64_toolchain
build --extra_toolchains @zig_sdk//toolchain:linux_amd64_gnu.2.19
build --extra_toolchains @zig_sdk//toolchain:linux_arm64_gnu.2.28
build --extra_toolchains @zig_sdk//toolchain:darwin_amd64
build --extra_toolchains @zig_sdk//toolchain:darwin_arm64
```
The snippets above will download the zig toolchain and register it for the
@ -80,7 +80,7 @@ different one is registered using `--extra_toolchains <toolchain>` in
tests) on linux/amd64/musl, you may specify:
```
--extra_toolchains @zig_sdk//:linux_amd64_musl_toolchain
--extra_toolchains @zig_sdk//toolchain:linux_amd64_musl
```
## UBSAN and "SIGILL: Illegal Instruction"
@ -108,12 +108,6 @@ how to contribute.
Currently zig cache is in `$HOME`, so `bazel clean --expunge` does not clear
the zig cache. Zig's cache should be stored somewhere in the project's path.
## Toolchain and platform target locations
The path to Bazel toolchains is `@zig_sdk//:<toolchain>_toolchain`. It should
be moved to `@zig_sdk//toolchain:<toolchain>` or similar; so the user-facing
targets are in their own namespace.
## OSX: sysroot
For non-trivial programs (and for all darwin/arm64 cgo programs) MacOS SDK may
@ -174,7 +168,7 @@ hello, world
$ bazel test \
--config=qemu-aarch64 \
--platforms @zig_sdk//platform:linux_arm64 \
--extra_toolchains @zig_sdk//:linux_arm64_musl_toolchain //test/...
--extra_toolchains @zig_sdk//toolchain:linux_arm64_musl //test/...
...
INFO: Build completed successfully, 10 total actions
//test/go:go_test PASSED in 0.2s

View File

@ -19,7 +19,7 @@ while read -r action platform toolchain config; do
args+=(\
--platforms "@zig_sdk//platform:${platform}" \
--extra_toolchains "@zig_sdk//:${toolchain}_toolchain" \
--extra_toolchains "@zig_sdk//toolchain:${toolchain}" \
//test/... \
)

View File

@ -1,11 +1,10 @@
load("@bazel-zig-cc//toolchain:defs.bzl", "zig_build_macro")
load("@bazel-zig-cc//toolchain:defs.bzl", "declare_files")
package(
default_visibility = ["//visibility:public"],
)
zig_build_macro(
absolute_path = {absolute_path},
declare_files(
zig_include_root = {zig_include_root},
)

View File

@ -189,7 +189,7 @@ def register_toolchains(
},
)
toolchains = ["@zig_sdk//:%s_toolchain" % t for t in register]
toolchains = ["@zig_sdk//:toolchain:%s" % t for t in register]
native.register_toolchains(*toolchains)
ZIG_TOOL_PATH = "tools/{zig_tool}"
@ -268,10 +268,18 @@ def _zig_repository_impl(repository_ctx):
Label("//toolchain/platform:BUILD"),
"platform/BUILD",
)
repository_ctx.template(
"BUILD",
Label("//toolchain:BUILD.sdk.bazel"),
executable = False,
substitutions = {
"{zig_include_root}": shell.quote(zig_include_root),
},
)
repository_ctx.template(
"BUILD.bazel",
Label("//toolchain:BUILD.sdk.bazel"),
"toolchain/BUILD",
Label("//toolchain/toolchain:BUILD.sdk.bazel"),
executable = False,
substitutions = {
"{absolute_path}": shell.quote(str(repository_ctx.path(""))),
@ -302,13 +310,21 @@ def filegroup(name, **kwargs):
native.filegroup(name = name, **kwargs)
return ":" + name
def zig_build_macro(absolute_path, zig_include_root):
def declare_files(zig_include_root):
filegroup(name = "empty")
native.exports_files(["zig"], visibility = ["//visibility:public"])
filegroup(name = "lib/std", srcs = native.glob(["lib/std/**"]))
lazy_filegroups = {}
for target_config in _target_structs():
for d in DEFAULT_INCLUDE_DIRECTORIES + target_config.includes:
d = zig_include_root + d
if d not in lazy_filegroups:
lazy_filegroups[d] = filegroup(name = d, srcs = native.glob([d + "/**"]))
def declare_toolchains(absolute_path, zig_include_root):
for target_config in _target_structs():
gotarget = target_config.gotarget
zigtarget = target_config.zigtarget
@ -316,8 +332,6 @@ def zig_build_macro(absolute_path, zig_include_root):
cxx_builtin_include_directories = []
for d in DEFAULT_INCLUDE_DIRECTORIES + target_config.includes:
d = zig_include_root + d
if d not in lazy_filegroups:
lazy_filegroups[d] = filegroup(name = d, srcs = native.glob([d + "/**"]))
cxx_builtin_include_directories.append(absolute_path + "/" + d)
for d in getattr(target_config, "toplevel_include", []):
cxx_builtin_include_directories.append(absolute_path + "/" + d)
@ -338,7 +352,7 @@ def zig_build_macro(absolute_path, zig_include_root):
copts = copts + ["-include", absolute_path + "/" + incl]
zig_cc_toolchain_config(
name = zigtarget + "_toolchain_cc_config",
name = zigtarget + "_cc_config",
target = zigtarget,
tool_paths = absolute_tool_paths,
cxx_builtin_include_directories = cxx_builtin_include_directories,
@ -353,35 +367,34 @@ def zig_build_macro(absolute_path, zig_include_root):
)
native.cc_toolchain(
name = zigtarget + "_toolchain_cc",
name = zigtarget + "_cc",
toolchain_identifier = zigtarget + "-toolchain",
toolchain_config = ":%s_toolchain_cc_config" % zigtarget,
all_files = ":zig",
ar_files = ":zig",
compiler_files = ":zig",
linker_files = ":zig",
dwp_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
toolchain_config = ":%s_cc_config" % zigtarget,
all_files = "@zig_sdk//:zig",
ar_files = "@zig_sdk//:zig",
compiler_files = "@zig_sdk//:zig",
linker_files = "@zig_sdk//:zig",
dwp_files = "@zig_sdk//:empty",
objcopy_files = "@zig_sdk//:empty",
strip_files = "@zig_sdk//:empty",
supports_param_files = 0,
)
# register two kinds of toolchain targets: Go and Zig conventions.
# Go convention: amd64/arm64, linux/darwin
native.toolchain(
name = gotarget + "_toolchain",
name = gotarget,
exec_compatible_with = None,
target_compatible_with = target_config.constraint_values,
toolchain = ":%s_toolchain_cc" % zigtarget,
toolchain = ":%s_cc" % zigtarget,
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
# Zig convention: x86_64/aarch64, linux/macos
native.toolchain(
name = zigtarget + "_toolchain",
name = zigtarget,
exec_compatible_with = None,
target_compatible_with = target_config.constraint_values,
toolchain = ":%s_toolchain_cc" % zigtarget,
toolchain = ":%s_cc" % zigtarget,
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

View File

View File

@ -0,0 +1,10 @@
load("@bazel-zig-cc//toolchain:defs.bzl", "declare_toolchains")
package(
default_visibility = ["//visibility:public"],
)
declare_toolchains(
absolute_path = {absolute_path},
zig_include_root = {zig_include_root},
)