diff --git a/README.md b/README.md index 0ea4e0e..c48ca24 100644 --- a/README.md +++ b/README.md @@ -130,24 +130,8 @@ 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. -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:`. 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`, and should be moved +to `@zig_sdk//: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: diff --git a/ci/test b/ci/test index 1b84922..1913b40 100755 --- a/ci/test +++ b/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 diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index 372cf59..693e2da 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -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, + )