add explicit platforms
This commit is contained in:
parent
236cb178d1
commit
51b8a382e7
13
.build.yml
13
.build.yml
@ -10,9 +10,14 @@ tasks:
|
|||||||
curl -L https://github.com/bazelbuild/bazelisk/releases/download/v1.9.0/bazelisk-linux-amd64 \
|
curl -L https://github.com/bazelbuild/bazelisk/releases/download/v1.9.0/bazelisk-linux-amd64 \
|
||||||
-o bazel
|
-o bazel
|
||||||
chmod +x bazel
|
chmod +x bazel
|
||||||
|
- test_default: |
|
||||||
|
cd bazel-zig-cc; ../bazel run --toolchain_resolution_debug=true \
|
||||||
|
//test:gognu
|
||||||
- test_musl: |
|
- test_musl: |
|
||||||
cd bazel-zig-cc
|
cd bazel-zig-cc; ../bazel run --toolchain_resolution_debug=true \
|
||||||
../bazel run --platforms @com_github_ziglang_zig//:platform_linux-x86_64-musl //test:gomusl
|
--platforms @com_github_ziglang_zig//:platform_linux-x86_64-musl \
|
||||||
|
//test:gomusl
|
||||||
- test_gnu: |
|
- test_gnu: |
|
||||||
cd bazel-zig-cc
|
cd bazel-zig-cc; ../bazel run --toolchain_resolution_debug=true \
|
||||||
../bazel run --platforms @com_github_ziglang_zig//:platform_linux-x86_64-gnu //test:gognu
|
--platforms @com_github_ziglang_zig//:platform_linux-x86_64-gnu \
|
||||||
|
//test:gognu
|
||||||
|
26
README.md
26
README.md
@ -6,12 +6,24 @@ libraries:
|
|||||||
- glibc 2.19
|
- glibc 2.19
|
||||||
- musl
|
- 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
|
# Testing
|
||||||
|
|
||||||
## cgo + glibc 2.19
|
## 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
|
$ ../bazel-bin/test/gognu_/gognu
|
||||||
hello, world
|
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
|
../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
|
## 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
|
$ 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
|
../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
|
$ 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
|
# 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
|
# 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.
|
||||||
|
@ -32,7 +32,10 @@ TARGET_CONFIGS = [
|
|||||||
linkopts=[],
|
linkopts=[],
|
||||||
copts=[],
|
copts=[],
|
||||||
bazel_target_cpu="darwin",
|
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"},
|
tool_paths={"ld": "ld64.lld"},
|
||||||
),
|
),
|
||||||
struct(
|
struct(
|
||||||
@ -50,7 +53,6 @@ TARGET_CONFIGS = [
|
|||||||
constraint_values=[
|
constraint_values=[
|
||||||
"@platforms//os:linux",
|
"@platforms//os:linux",
|
||||||
"@platforms//cpu:x86_64",
|
"@platforms//cpu:x86_64",
|
||||||
":gnu_2_19",
|
|
||||||
],
|
],
|
||||||
tool_paths={"ld": "ld.lld"},
|
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_setting(name = "libc")
|
||||||
|
|
||||||
constraint_value(
|
|
||||||
name = "gnu_2_19",
|
|
||||||
constraint_setting = ":libc",
|
|
||||||
)
|
|
||||||
|
|
||||||
constraint_value(
|
constraint_value(
|
||||||
name = "musl",
|
name = "musl",
|
||||||
constraint_setting = ":libc",
|
constraint_setting = ":libc",
|
||||||
@ -134,20 +131,27 @@ constraint_value(
|
|||||||
|
|
||||||
|
|
||||||
platform(
|
platform(
|
||||||
name = "platform_linux-x86_64-musl",
|
name = "platform_x86_64-macos-gnu",
|
||||||
constraint_values = [
|
constraint_values = [
|
||||||
"@platforms//os:linux",
|
"@platforms//os:macos",
|
||||||
"@platforms//cpu:x86_64",
|
"@platforms//cpu:x86_64",
|
||||||
":musl",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
platform(
|
platform(
|
||||||
name = "platform_linux-x86_64-gnu",
|
name = "platform_x86_64-linux-gnu",
|
||||||
constraint_values = [
|
constraint_values = [
|
||||||
"@platforms//os:linux",
|
"@platforms//os:linux",
|
||||||
"@platforms//cpu:x86_64",
|
"@platforms//cpu:x86_64",
|
||||||
":gnu_2_19",
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
platform(
|
||||||
|
name = "platform_x86_64-linux-musl",
|
||||||
|
constraint_values = [
|
||||||
|
"@platforms//os:linux",
|
||||||
|
"@platforms//cpu:x86_64",
|
||||||
|
":musl",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user