1

move platforms under @zig_cc//platform:

This commit is contained in:
laurynasl 2022-04-06 19:16:53 +00:00 committed by Motiejus Jakštys
parent 22762ccc97
commit dd76e0b76f
4 changed files with 15 additions and 9 deletions

View File

@ -114,9 +114,6 @@ 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 be moved to `@zig_sdk//toolchain:<toolchain>` or similar; so the user-facing
targets are in their own namespace. targets are in their own namespace.
Likewise, platforms are `@zig_sdk//:<platform>_platform`, and should be moved
to `@zig_sdk//:platform:<platform>`.
## 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
@ -164,7 +161,7 @@ may apply to aarch64, but the author didn't find a need to test it (yet).
## build & run linux cgo + glibc ## build & run linux cgo + glibc
``` ```
$ bazel build --platforms @zig_sdk//:linux_amd64_platform //test/go:go $ bazel build --platforms @zig_sdk//platform:linux_amd64 //test/go:go
$ file bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go $ file bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go
bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go: 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 bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go: 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
$ bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go $ bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go
@ -176,7 +173,7 @@ hello, world
``` ```
$ bazel test \ $ bazel test \
--config=qemu-aarch64 \ --config=qemu-aarch64 \
--platforms @zig_sdk//:linux_arm64_platform \ --platforms @zig_sdk//platform:linux_arm64 \
--extra_toolchains @zig_sdk//:linux_arm64_musl_toolchain //test/... --extra_toolchains @zig_sdk//:linux_arm64_musl_toolchain //test/...
... ...
INFO: Build completed successfully, 10 total actions INFO: Build completed successfully, 10 total actions
@ -186,7 +183,7 @@ INFO: Build completed successfully, 10 total actions
## macos cgo ## macos cgo
``` ```
$ bazel build --platforms @zig_sdk//:darwin_amd64_platform //test/go:go $ bazel build --platforms @zig_sdk//platform:darwin_amd64 //test/go:go
... ...
$ file bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go $ file bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go
bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE|HAS_TLV_DESCRIPTORS> bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE|HAS_TLV_DESCRIPTORS>

View File

@ -18,7 +18,7 @@ while read -r action platform toolchain config; do
fi fi
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/... \
) )

View File

@ -264,6 +264,11 @@ def _zig_repository_impl(repository_ctx):
content = _fcntl_h, content = _fcntl_h,
) )
repository_ctx.symlink(
Label("//toolchain/platform:BUILD"),
"platform/BUILD",
)
repository_ctx.template( repository_ctx.template(
"BUILD.bazel", "BUILD.bazel",
Label("//toolchain:BUILD.sdk.bazel"), Label("//toolchain:BUILD.sdk.bazel"),
@ -380,6 +385,7 @@ def zig_build_macro(absolute_path, zig_include_root):
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
) )
def declare_platforms():
# create @zig_sdk//{os}_{arch}_platform entries with zig and go conventions # create @zig_sdk//{os}_{arch}_platform entries with zig and go conventions
for zigcpu, gocpu in (("x86_64", "amd64"), ("aarch64", "arm64")): for zigcpu, gocpu in (("x86_64", "amd64"), ("aarch64", "arm64")):
for bzlos, oss in {"linux": ["linux"], "macos": ["macos", "darwin"]}.items(): for bzlos, oss in {"linux": ["linux"], "macos": ["macos", "darwin"]}.items():
@ -389,10 +395,10 @@ def zig_build_macro(absolute_path, zig_include_root):
"@platforms//cpu:{}".format(zigcpu), "@platforms//cpu:{}".format(zigcpu),
] ]
native.platform( native.platform(
name = "{os}_{zigcpu}_platform".format(os = os, zigcpu = zigcpu), name = "{os}_{zigcpu}".format(os = os, zigcpu = zigcpu),
constraint_values = constraint_values, constraint_values = constraint_values,
) )
native.platform( native.platform(
name = "{os}_{gocpu}_platform".format(os = os, gocpu = gocpu), name = "{os}_{gocpu}".format(os = os, gocpu = gocpu),
constraint_values = constraint_values, constraint_values = constraint_values,
) )

3
toolchain/platform/BUILD Normal file
View File

@ -0,0 +1,3 @@
load("@bazel-zig-cc//toolchain:defs.bzl", "declare_platforms")
declare_platforms()