diff --git a/README.md b/README.md index 1c8e011..d855c78 100644 --- a/README.md +++ b/README.md @@ -114,9 +114,6 @@ The path to Bazel toolchains is `@zig_sdk//:_toolchain`. It should be moved to `@zig_sdk//toolchain:` or similar; so the user-facing targets are in their own namespace. -Likewise, platforms are `@zig_sdk//:_platform`, and should be moved -to `@zig_sdk//:platform:`. - ## OSX: sysroot 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 ``` -$ 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 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 @@ -176,7 +173,7 @@ hello, world ``` $ bazel test \ --config=qemu-aarch64 \ - --platforms @zig_sdk//:linux_arm64_platform \ + --platforms @zig_sdk//platform:linux_arm64 \ --extra_toolchains @zig_sdk//:linux_arm64_musl_toolchain //test/... ... INFO: Build completed successfully, 10 total actions @@ -186,7 +183,7 @@ INFO: Build completed successfully, 10 total actions ## 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 bazel-out/k8-opt-ST-d17813c235ce/bin/test/go/go_/go: Mach-O 64-bit x86_64 executable, flags: diff --git a/ci/test b/ci/test index e9a8e9a..5b9a4d7 100755 --- a/ci/test +++ b/ci/test @@ -18,7 +18,7 @@ while read -r action platform toolchain config; do fi args+=(\ - --platforms "@zig_sdk//:${platform}_platform" \ + --platforms "@zig_sdk//platform:${platform}" \ --extra_toolchains "@zig_sdk//:${toolchain}_toolchain" \ //test/... \ ) diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index 112a64a..eb005fe 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -264,6 +264,11 @@ def _zig_repository_impl(repository_ctx): content = _fcntl_h, ) + repository_ctx.symlink( + Label("//toolchain/platform:BUILD"), + "platform/BUILD", + ) + repository_ctx.template( "BUILD.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", ) +def declare_platforms(): # 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(): @@ -389,10 +395,10 @@ def zig_build_macro(absolute_path, zig_include_root): "@platforms//cpu:{}".format(zigcpu), ] native.platform( - name = "{os}_{zigcpu}_platform".format(os = os, zigcpu = zigcpu), + name = "{os}_{zigcpu}".format(os = os, zigcpu = zigcpu), constraint_values = constraint_values, ) native.platform( - name = "{os}_{gocpu}_platform".format(os = os, gocpu = gocpu), + name = "{os}_{gocpu}".format(os = os, gocpu = gocpu), constraint_values = constraint_values, ) diff --git a/toolchain/platform/BUILD b/toolchain/platform/BUILD new file mode 100644 index 0000000..b02436b --- /dev/null +++ b/toolchain/platform/BUILD @@ -0,0 +1,3 @@ +load("@bazel-zig-cc//toolchain:defs.bzl", "declare_platforms") + +declare_platforms()