add @zig_sdk//:<os>_<arch>_platform values
This commit is contained in:
parent
6136c7059f
commit
bcd9731f92
26
README.md
26
README.md
@ -130,24 +130,8 @@ 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.
|
||||
|
||||
Currently, platform is not defined in `@zig_sdk`. As you may see in the
|
||||
examples, we are currently using the one provided by cgo. E.g.
|
||||
`@io_bazel_rules_go//go/toolchain:linux_amd64_cgo`. This is because we want to
|
||||
define it in `@zig_sdk//:platform:<platform>`. This is waiting for mine or a
|
||||
contributor's attention. You may work around this by sending a patch to
|
||||
bazel-zig-cc or specifying the platform in your project:
|
||||
|
||||
```
|
||||
platform(
|
||||
name = "linux_aarch64",
|
||||
constraint_values = [
|
||||
"@bazel_tools//platforms:linux",
|
||||
"@bazel_tools//platforms:aarch64",
|
||||
]
|
||||
)
|
||||
```
|
||||
|
||||
and `--platforms="//:linux_aarch64"`.
|
||||
Likewise, platforms are `@zig_sdk//:<platform>_platform`, and should be moved
|
||||
to `@zig_sdk//:platform:<platform>`.
|
||||
|
||||
# Known Issues In Upstream
|
||||
|
||||
@ -184,7 +168,7 @@ may apply to aarch64, but the author didn't find a need to test it (yet).
|
||||
## linux cgo + glibc 2.28
|
||||
|
||||
```
|
||||
$ bazel build --platforms @io_bazel_rules_go//go/toolchain:linux_amd64_cgo //test:hello
|
||||
$ bazel build --platforms @zig_sdk//:linux_amd64_platform //test:hello
|
||||
$ file bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/hello_/hello
|
||||
bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/hello_/hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.0.0, Go BuildID=redacted, with debug_info, not stripped
|
||||
```
|
||||
@ -193,7 +177,7 @@ bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/hello_/hello: ELF 64-bit LSB exe
|
||||
|
||||
```
|
||||
$ bazel build \
|
||||
--platforms @io_bazel_rules_go//go/toolchain:linux_amd64_cgo \
|
||||
--platforms @zig_sdk//:linux_amd64_platform \
|
||||
--extra_toolchains @zig_sdk//:linux_amd64_musl_toolchain //test:hello
|
||||
...
|
||||
$ file ../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/hello_/hello
|
||||
@ -205,7 +189,7 @@ hello, world
|
||||
## macos cgo
|
||||
|
||||
```
|
||||
$ bazel build --platforms @io_bazel_rules_go//go/toolchain:darwin_amd64_cgo //test:hello
|
||||
$ bazel build --platforms @zig_sdk//:darwin_amd64_platform //test:hello
|
||||
...
|
||||
$ file bazel-bin/test/hello_/hello
|
||||
bazel-bin/test/hello_/hello: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>
|
||||
|
12
ci/test
12
ci/test
@ -30,28 +30,28 @@ _test "Host" \
|
||||
|
||||
_test "darwin_amd64" \
|
||||
"Mach-O 64-bit x86_64 executable" \
|
||||
--platforms @io_bazel_rules_go//go/toolchain:darwin_amd64_cgo
|
||||
--platforms @zig_sdk//:darwin_amd64_platform
|
||||
|
||||
# hello world on darwin/arm64 requires OSX SDK via `zig cc --sysroot=<...>`.
|
||||
# see https://github.com/ziglang/zig/issues/10299#issuecomment-989595215
|
||||
#_test "darwin_arm64" \
|
||||
# "Mach-O 64-bit arm64 executable" \
|
||||
# --platforms @io_bazel_rules_go//go/toolchain:darwin_arm64_cgo
|
||||
# --platforms @zig_sdk//:darwin_arm64_platform
|
||||
|
||||
_test "linux_amd64_gnu" \
|
||||
"ELF 64-bit.* x86-64.* dynamically linked" \
|
||||
--platforms @io_bazel_rules_go//go/toolchain:linux_amd64_cgo
|
||||
--platforms @zig_sdk//:linux_amd64_platform
|
||||
|
||||
_test "linux_amd64_musl" \
|
||||
"ELF 64-bit.* x86-64.* statically linked" \
|
||||
--platforms @io_bazel_rules_go//go/toolchain:linux_amd64_cgo \
|
||||
--platforms @zig_sdk//:linux_amd64_platform \
|
||||
--extra_toolchains @zig_sdk//:linux_amd64_musl_toolchain
|
||||
|
||||
_test "linux_arm64_gnu" \
|
||||
"ELF 64-bit.* ARM aarch64.* dynamically linked" \
|
||||
--platforms @io_bazel_rules_go//go/toolchain:linux_arm64_cgo
|
||||
--platforms @zig_sdk//:linux_arm64_platform
|
||||
|
||||
_test "linux_arm64_musl" \
|
||||
"ELF 64-bit.* ARM aarch64.* statically linked" \
|
||||
--platforms @io_bazel_rules_go//go/toolchain:linux_arm64_cgo \
|
||||
--platforms @zig_sdk//:linux_arm64_platform \
|
||||
--extra_toolchains @zig_sdk//:linux_arm64_musl_toolchain
|
||||
|
@ -376,3 +376,20 @@ def zig_build_macro(absolute_path, zig_include_root):
|
||||
toolchain = ":%s_toolchain_cc" % zigtarget,
|
||||
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
||||
)
|
||||
|
||||
# create @zig_sdk//{os}_{arch}_platform entries with zig and go conventions
|
||||
for zigcpu, gocpu in (("x86_64", "amd64"), ("aarch64", "arm64")):
|
||||
for bzlos, oss in {"linux": ["linux"], "macos": ["macos", "darwin"]}.items():
|
||||
for os in oss:
|
||||
constraint_values = [
|
||||
"@platforms//os:{}".format(bzlos),
|
||||
"@platforms//cpu:{}".format(zigcpu),
|
||||
]
|
||||
native.platform(
|
||||
name = "{os}_{zigcpu}_platform".format(os = os, zigcpu = zigcpu),
|
||||
constraint_values = constraint_values,
|
||||
)
|
||||
native.platform(
|
||||
name = "{os}_{gocpu}_platform".format(os = os, gocpu = gocpu),
|
||||
constraint_values = constraint_values,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user