diff --git a/.build.yml b/.build.yml index 14eb5c1..de41c4e 100644 --- a/.build.yml +++ b/.build.yml @@ -10,9 +10,14 @@ tasks: curl -L https://github.com/bazelbuild/bazelisk/releases/download/v1.9.0/bazelisk-linux-amd64 \ -o bazel chmod +x bazel + - test_default: | + cd bazel-zig-cc; ../bazel run --toolchain_resolution_debug=true \ + //test:gognu - test_musl: | - cd bazel-zig-cc - ../bazel run --platforms @com_github_ziglang_zig//:platform_linux-x86_64-musl //test:gomusl + cd bazel-zig-cc; ../bazel run --toolchain_resolution_debug=true \ + --platforms @com_github_ziglang_zig//:platform_linux-x86_64-musl \ + //test:gomusl - test_gnu: | - cd bazel-zig-cc - ../bazel run --platforms @com_github_ziglang_zig//:platform_linux-x86_64-gnu //test:gognu + cd bazel-zig-cc; ../bazel run --toolchain_resolution_debug=true \ + --platforms @com_github_ziglang_zig//:platform_linux-x86_64-gnu \ + //test:gognu diff --git a/README.md b/README.md index 44b36ef..86d48fe 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,24 @@ libraries: - glibc 2.19 - musl +glibc 2.19 is the default. That means, glibc 2.19 toolchain is registered with +these basic constraints: + +``` +[ + "@platforms//os:linux", + "@platforms//cpu:x86_64", +] +``` + # Testing ## cgo + glibc 2.19 +Using the default toolchain: + ``` -$ bazel build //test:gognu +$ bazel build --toolchain_resolution_debug=true //test:gognu ... $ ../bazel-bin/test/gognu_/gognu hello, world @@ -19,10 +31,15 @@ $ file ../bazel-bin/test/gognu_/gognu ../bazel-bin/test/gognu_/gognu: 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 ``` +Explicitly specifying `-gnu`: +``` +$ bazel run --platforms @com_github_ziglang_zig//:platform_x86_64-linux-gnu //test:gognu +``` + ## cgo + musl ``` -$ bazel build --platforms @com_github_ziglang_zig//:platform_linux-x86_64-musl :gomusl +$ bazel build --platforms @com_github_ziglang_zig//:platform_x86_64-linux-musl :gomusl ... $ file ../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/gomusl_/gomusl ../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/gomusl_/gomusl: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=redacted, with debug_info, not stripped @@ -36,6 +53,7 @@ hello, world $ docker run -ti --rm -v $(pwd):/x -w /x debian:buster-slim # apt update && apt install curl ca-certificates -y && curl -L https://github.com/bazelbuild/bazelisk/releases/download/v1.7.5/bazelisk-linux-amd64 > /usr/local/bin/bazel && chmod +x /usr/local/bin/bazel # export CC=/usr/bin/false -# bazel run --platforms @com_github_ziglang_zig//:platform_linux-x86_64-musl //test:gomusl -# bazel run --platforms @com_github_ziglang_zig//:platform_linux-x86_64-gnu //test:gognu ``` + +And run the `bazel build` commands above. Take a look at `.build.yml` and see +how CI does it. diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index f26a425..687e4ad 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -32,7 +32,10 @@ TARGET_CONFIGS = [ linkopts=[], copts=[], bazel_target_cpu="darwin", - constraint_values=["@platforms//os:macos", "@platforms//cpu:x86_64"], + constraint_values=[ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], tool_paths={"ld": "ld64.lld"}, ), struct( @@ -50,7 +53,6 @@ TARGET_CONFIGS = [ constraint_values=[ "@platforms//os:linux", "@platforms//cpu:x86_64", - ":gnu_2_19", ], tool_paths={"ld": "ld.lld"}, ), @@ -122,11 +124,6 @@ zig_build_macro(absolute_path={absolute_path}, zig_include_root={zig_include_roo constraint_setting(name = "libc") -constraint_value( - name = "gnu_2_19", - constraint_setting = ":libc", -) - constraint_value( name = "musl", constraint_setting = ":libc", @@ -134,20 +131,27 @@ constraint_value( platform( - name = "platform_linux-x86_64-musl", + name = "platform_x86_64-macos-gnu", constraint_values = [ - "@platforms//os:linux", + "@platforms//os:macos", "@platforms//cpu:x86_64", - ":musl", ], ) platform( - name = "platform_linux-x86_64-gnu", + name = "platform_x86_64-linux-gnu", constraint_values = [ "@platforms//os:linux", "@platforms//cpu:x86_64", - ":gnu_2_19", + ], +) + +platform( + name = "platform_x86_64-linux-musl", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ":musl", ], )