Move toolchainss under @zig_sdk//platform:
This commit is contained in:
parent
d1b0dddf8c
commit
723e6f051d
8
.bazelrc
8
.bazelrc
@ -6,10 +6,10 @@ build --worker_sandboxing
|
|||||||
build --compilation_mode=opt
|
build --compilation_mode=opt
|
||||||
|
|
||||||
build --incompatible_enable_cc_toolchain_resolution
|
build --incompatible_enable_cc_toolchain_resolution
|
||||||
build --extra_toolchains @zig_sdk//:linux_amd64_gnu.2.19_toolchain
|
build --extra_toolchains @zig_sdk//toolchain:linux_amd64_gnu.2.19
|
||||||
build --extra_toolchains @zig_sdk//:linux_arm64_gnu.2.28_toolchain
|
build --extra_toolchains @zig_sdk//toolchain:linux_arm64_gnu.2.28
|
||||||
build --extra_toolchains @zig_sdk//:darwin_amd64_toolchain
|
build --extra_toolchains @zig_sdk//toolchain:darwin_amd64
|
||||||
build --extra_toolchains @zig_sdk//:darwin_arm64_toolchain
|
build --extra_toolchains @zig_sdk//toolchain:darwin_arm64
|
||||||
|
|
||||||
test:qemu-aarch64 --test_env=QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/
|
test:qemu-aarch64 --test_env=QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/
|
||||||
test:qemu-aarch64 --run_under=qemu-aarch64-static
|
test:qemu-aarch64 --run_under=qemu-aarch64-static
|
||||||
|
18
README.md
18
README.md
@ -41,10 +41,10 @@ And this to `.bazelrc`:
|
|||||||
|
|
||||||
```
|
```
|
||||||
build --incompatible_enable_cc_toolchain_resolution
|
build --incompatible_enable_cc_toolchain_resolution
|
||||||
build --extra_toolchains @zig_sdk//:linux_amd64_gnu.2.19_toolchain
|
build --extra_toolchains @zig_sdk//toolchain:linux_amd64_gnu.2.19
|
||||||
build --extra_toolchains @zig_sdk//:linux_arm64_gnu.2.28_toolchain
|
build --extra_toolchains @zig_sdk//toolchain:linux_arm64_gnu.2.28
|
||||||
build --extra_toolchains @zig_sdk//:darwin_amd64_toolchain
|
build --extra_toolchains @zig_sdk//toolchain:darwin_amd64
|
||||||
build --extra_toolchains @zig_sdk//:darwin_arm64_toolchain
|
build --extra_toolchains @zig_sdk//toolchain:darwin_arm64
|
||||||
```
|
```
|
||||||
|
|
||||||
The snippets above will download the zig toolchain and register it for the
|
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:
|
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"
|
## 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
|
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.
|
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
|
## OSX: sysroot
|
||||||
|
|
||||||
For non-trivial programs (and for all darwin/arm64 cgo programs) MacOS SDK may
|
For non-trivial programs (and for all darwin/arm64 cgo programs) MacOS SDK may
|
||||||
@ -174,7 +168,7 @@ hello, world
|
|||||||
$ bazel test \
|
$ bazel test \
|
||||||
--config=qemu-aarch64 \
|
--config=qemu-aarch64 \
|
||||||
--platforms @zig_sdk//platform:linux_arm64 \
|
--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
|
INFO: Build completed successfully, 10 total actions
|
||||||
//test/go:go_test PASSED in 0.2s
|
//test/go:go_test PASSED in 0.2s
|
||||||
|
2
ci/test
2
ci/test
@ -19,7 +19,7 @@ while read -r action platform toolchain config; do
|
|||||||
|
|
||||||
args+=(\
|
args+=(\
|
||||||
--platforms "@zig_sdk//platform:${platform}" \
|
--platforms "@zig_sdk//platform:${platform}" \
|
||||||
--extra_toolchains "@zig_sdk//:${toolchain}_toolchain" \
|
--extra_toolchains "@zig_sdk//toolchain:${toolchain}" \
|
||||||
//test/... \
|
//test/... \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
load("@bazel-zig-cc//toolchain:defs.bzl", "zig_build_macro")
|
load("@bazel-zig-cc//toolchain:defs.bzl", "declare_files")
|
||||||
|
|
||||||
package(
|
package(
|
||||||
default_visibility = ["//visibility:public"],
|
default_visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
zig_build_macro(
|
declare_files(
|
||||||
absolute_path = {absolute_path},
|
|
||||||
zig_include_root = {zig_include_root},
|
zig_include_root = {zig_include_root},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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)
|
native.register_toolchains(*toolchains)
|
||||||
|
|
||||||
ZIG_TOOL_PATH = "tools/{zig_tool}"
|
ZIG_TOOL_PATH = "tools/{zig_tool}"
|
||||||
@ -268,10 +268,18 @@ def _zig_repository_impl(repository_ctx):
|
|||||||
Label("//toolchain/platform:BUILD"),
|
Label("//toolchain/platform:BUILD"),
|
||||||
"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(
|
repository_ctx.template(
|
||||||
"BUILD.bazel",
|
"toolchain/BUILD",
|
||||||
Label("//toolchain:BUILD.sdk.bazel"),
|
Label("//toolchain/toolchain:BUILD.sdk.bazel"),
|
||||||
executable = False,
|
executable = False,
|
||||||
substitutions = {
|
substitutions = {
|
||||||
"{absolute_path}": shell.quote(str(repository_ctx.path(""))),
|
"{absolute_path}": shell.quote(str(repository_ctx.path(""))),
|
||||||
@ -302,13 +310,21 @@ def filegroup(name, **kwargs):
|
|||||||
native.filegroup(name = name, **kwargs)
|
native.filegroup(name = name, **kwargs)
|
||||||
return ":" + name
|
return ":" + name
|
||||||
|
|
||||||
def zig_build_macro(absolute_path, zig_include_root):
|
def declare_files(zig_include_root):
|
||||||
filegroup(name = "empty")
|
filegroup(name = "empty")
|
||||||
native.exports_files(["zig"], visibility = ["//visibility:public"])
|
native.exports_files(["zig"], visibility = ["//visibility:public"])
|
||||||
filegroup(name = "lib/std", srcs = native.glob(["lib/std/**"]))
|
filegroup(name = "lib/std", srcs = native.glob(["lib/std/**"]))
|
||||||
|
|
||||||
lazy_filegroups = {}
|
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():
|
for target_config in _target_structs():
|
||||||
gotarget = target_config.gotarget
|
gotarget = target_config.gotarget
|
||||||
zigtarget = target_config.zigtarget
|
zigtarget = target_config.zigtarget
|
||||||
@ -316,8 +332,6 @@ def zig_build_macro(absolute_path, zig_include_root):
|
|||||||
cxx_builtin_include_directories = []
|
cxx_builtin_include_directories = []
|
||||||
for d in DEFAULT_INCLUDE_DIRECTORIES + target_config.includes:
|
for d in DEFAULT_INCLUDE_DIRECTORIES + target_config.includes:
|
||||||
d = zig_include_root + d
|
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)
|
cxx_builtin_include_directories.append(absolute_path + "/" + d)
|
||||||
for d in getattr(target_config, "toplevel_include", []):
|
for d in getattr(target_config, "toplevel_include", []):
|
||||||
cxx_builtin_include_directories.append(absolute_path + "/" + d)
|
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]
|
copts = copts + ["-include", absolute_path + "/" + incl]
|
||||||
|
|
||||||
zig_cc_toolchain_config(
|
zig_cc_toolchain_config(
|
||||||
name = zigtarget + "_toolchain_cc_config",
|
name = zigtarget + "_cc_config",
|
||||||
target = zigtarget,
|
target = zigtarget,
|
||||||
tool_paths = absolute_tool_paths,
|
tool_paths = absolute_tool_paths,
|
||||||
cxx_builtin_include_directories = cxx_builtin_include_directories,
|
cxx_builtin_include_directories = cxx_builtin_include_directories,
|
||||||
@ -353,35 +367,34 @@ def zig_build_macro(absolute_path, zig_include_root):
|
|||||||
)
|
)
|
||||||
|
|
||||||
native.cc_toolchain(
|
native.cc_toolchain(
|
||||||
name = zigtarget + "_toolchain_cc",
|
name = zigtarget + "_cc",
|
||||||
toolchain_identifier = zigtarget + "-toolchain",
|
toolchain_identifier = zigtarget + "-toolchain",
|
||||||
toolchain_config = ":%s_toolchain_cc_config" % zigtarget,
|
toolchain_config = ":%s_cc_config" % zigtarget,
|
||||||
all_files = ":zig",
|
all_files = "@zig_sdk//:zig",
|
||||||
ar_files = ":zig",
|
ar_files = "@zig_sdk//:zig",
|
||||||
compiler_files = ":zig",
|
compiler_files = "@zig_sdk//:zig",
|
||||||
linker_files = ":zig",
|
linker_files = "@zig_sdk//:zig",
|
||||||
dwp_files = ":empty",
|
dwp_files = "@zig_sdk//:empty",
|
||||||
objcopy_files = ":empty",
|
objcopy_files = "@zig_sdk//:empty",
|
||||||
strip_files = ":empty",
|
strip_files = "@zig_sdk//:empty",
|
||||||
supports_param_files = 0,
|
supports_param_files = 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
# register two kinds of toolchain targets: Go and Zig conventions.
|
# register two kinds of toolchain targets: Go and Zig conventions.
|
||||||
# Go convention: amd64/arm64, linux/darwin
|
# Go convention: amd64/arm64, linux/darwin
|
||||||
native.toolchain(
|
native.toolchain(
|
||||||
name = gotarget + "_toolchain",
|
name = gotarget,
|
||||||
exec_compatible_with = None,
|
exec_compatible_with = None,
|
||||||
target_compatible_with = target_config.constraint_values,
|
target_compatible_with = target_config.constraint_values,
|
||||||
toolchain = ":%s_toolchain_cc" % zigtarget,
|
toolchain = ":%s_cc" % zigtarget,
|
||||||
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Zig convention: x86_64/aarch64, linux/macos
|
# Zig convention: x86_64/aarch64, linux/macos
|
||||||
native.toolchain(
|
native.toolchain(
|
||||||
name = zigtarget + "_toolchain",
|
name = zigtarget,
|
||||||
exec_compatible_with = None,
|
exec_compatible_with = None,
|
||||||
target_compatible_with = target_config.constraint_values,
|
target_compatible_with = target_config.constraint_values,
|
||||||
toolchain = ":%s_toolchain_cc" % zigtarget,
|
toolchain = ":%s_cc" % zigtarget,
|
||||||
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
0
toolchain/toolchain/BUILD
Normal file
0
toolchain/toolchain/BUILD
Normal file
10
toolchain/toolchain/BUILD.sdk.bazel
Normal file
10
toolchain/toolchain/BUILD.sdk.bazel
Normal 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},
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user