register only gnu toolchain by default
musl can be specified with --extra_toolchains.
This commit is contained in:
parent
e94447bd83
commit
a3606b7404
1
.bazelversion
Normal file
1
.bazelversion
Normal file
@ -0,0 +1 @@
|
||||
4.1.0
|
30
.build.yml
30
.build.yml
@ -12,36 +12,36 @@ 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 \
|
||||
# //test:gognu
|
||||
- test_default: |
|
||||
cd bazel-zig-cc; ../bazel run \
|
||||
//test:hello
|
||||
- test_x86_64-linux-gnu: |
|
||||
cd bazel-zig-cc; ../bazel run \
|
||||
--platforms @zig_sdk//:x86_64-linux-gnu //test:gognu
|
||||
file $(./getpath @zig_sdk//:x86_64-linux-gnu //test:gognu) | \
|
||||
--platforms @zig_sdk//:x86_64-linux-gnu //test:hello
|
||||
file $(./getpath @zig_sdk//:x86_64-linux-gnu //test:hello) | \
|
||||
tee /dev/stderr | grep -q "ELF 64-bit.* x86-64.* dynamically linked"
|
||||
- test_x86_64-linux-musl: |
|
||||
cd bazel-zig-cc; ../bazel run \
|
||||
--platforms @zig_sdk//:x86_64-linux-musl //test:gomusl
|
||||
file $(./getpath @zig_sdk//:x86_64-linux-musl //test:gomusl) | \
|
||||
--platforms @zig_sdk//:x86_64-linux-musl //test:hello
|
||||
file $(./getpath @zig_sdk//:x86_64-linux-musl //test:hello) | \
|
||||
tee /dev/stderr | grep -q "ELF 64-bit.* x86-64.* statically linked"
|
||||
- test_aarch64-linux-gnu: |
|
||||
cd bazel-zig-cc; ../bazel build \
|
||||
--platforms @zig_sdk//:aarch64-linux-gnu //test:gognu
|
||||
file $(./getpath @zig_sdk//:aarch64-linux-gnu //test:gognu) | \
|
||||
--platforms @zig_sdk//:aarch64-linux-gnu //test:hello
|
||||
file $(./getpath @zig_sdk//:aarch64-linux-gnu //test:hello) | \
|
||||
tee /dev/stderr | grep -q "ELF 64-bit.* ARM aarch64.* dynamically linked"
|
||||
- test_aarch64-linux-musl: |
|
||||
cd bazel-zig-cc; ../bazel build \
|
||||
--platforms @zig_sdk//:aarch64-linux-musl //test:gomusl
|
||||
file $(./getpath @zig_sdk//:aarch64-linux-musl //test:gomusl) | \
|
||||
--platforms @zig_sdk//:aarch64-linux-musl //test:hello
|
||||
file $(./getpath @zig_sdk//:aarch64-linux-musl //test:hello) | \
|
||||
tee /dev/stderr | grep -q "ELF 64-bit.* ARM aarch64.* statically linked"
|
||||
- test_x86_64-macos-gnu: |
|
||||
cd bazel-zig-cc; ../bazel build \
|
||||
--platforms @zig_sdk//:x86_64-macos-gnu //test:gognu
|
||||
file $(./getpath @zig_sdk//:x86_64-macos-gnu //test:gognu) | \
|
||||
--platforms @zig_sdk//:x86_64-macos-gnu //test:hello
|
||||
file $(./getpath @zig_sdk//:x86_64-macos-gnu //test:hello) | \
|
||||
tee /dev/stderr | grep -q "Mach-O 64-bit x86_64 executable"
|
||||
- test_aarch64-macos-gnu: |
|
||||
cd bazel-zig-cc; ../bazel build \
|
||||
--platforms @zig_sdk//:aarch64-macos-gnu //test:gognu
|
||||
file $(./getpath @zig_sdk//:aarch64-macos-gnu //test:gognu) | \
|
||||
--platforms @zig_sdk//:aarch64-macos-gnu //test:hello
|
||||
file $(./getpath @zig_sdk//:aarch64-macos-gnu //test:hello) | \
|
||||
tee /dev/stderr | grep -q "Mach-O 64-bit arm64 executable"
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,7 +2,8 @@
|
||||
*.sw[op]
|
||||
|
||||
/bazel
|
||||
/bazel-bin
|
||||
/bazel-bazel-zig-cc
|
||||
/bazel-bin
|
||||
/bazel-out
|
||||
/bazel-testlogs
|
||||
/bazel-x
|
||||
|
@ -28,11 +28,11 @@ bazel-bin/test/gognu_/gognu: ELF 64-bit LSB executable, x86-64, version 1 (SYSV)
|
||||
## linux cgo + musl
|
||||
|
||||
```
|
||||
$ bazel build --platforms @zig_sdk//:x86_64-linux-musl //test:gomusl
|
||||
$ bazel build --extra_toolchains @zig_sdk//:x86_64-linux-musl_toolchain //test:hello
|
||||
...
|
||||
$ 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
|
||||
$ 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), statically linked, Go BuildID=redacted, with debug_info, not stripped
|
||||
$ ../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/hello_/hello
|
||||
hello, world
|
||||
```
|
||||
|
||||
|
22
test/BUILD
22
test/BUILD
@ -1,7 +1,7 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_lib",
|
||||
name = "hello_lib",
|
||||
srcs = ["hello.go"],
|
||||
cgo = True,
|
||||
importpath = "github.com/motiejus/bazel-zig-cc/test",
|
||||
@ -9,22 +9,16 @@ go_library(
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "gognu",
|
||||
embed = [":go_lib"],
|
||||
name = "hello",
|
||||
embed = [":hello_lib"],
|
||||
gc_linkopts = select({
|
||||
"@platforms//os:macos": ["-s", "-w", "-buildmode=pie"],
|
||||
"@platforms//os:macos": [
|
||||
"-s",
|
||||
"-w",
|
||||
"-buildmode=pie",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "gomusl",
|
||||
embed = [":go_lib"],
|
||||
static = "on",
|
||||
target_compatible_with = select({
|
||||
"@platforms//os:linux": ["@zig_sdk//:libc_musl"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
@ -53,7 +53,6 @@ TARGET_CONFIGS_LISTOFLISTS = [[
|
||||
constraint_values = [
|
||||
"@platforms//os:linux",
|
||||
"@platforms//cpu:{}".format(cpu),
|
||||
":libc_gnu",
|
||||
],
|
||||
tool_paths = {"ld": "ld.lld"},
|
||||
),
|
||||
@ -71,9 +70,9 @@ TARGET_CONFIGS_LISTOFLISTS = [[
|
||||
constraint_values = [
|
||||
"@platforms//os:linux",
|
||||
"@platforms//cpu:{}".format(cpu),
|
||||
":libc_musl",
|
||||
],
|
||||
tool_paths = {"ld": "ld.lld"},
|
||||
skip_register = True,
|
||||
),
|
||||
] for cpu in ("x86_64", "aarch64")]
|
||||
|
||||
@ -101,6 +100,7 @@ def toolchain_repositories():
|
||||
|
||||
def register_all_toolchains():
|
||||
for target_config in TARGET_CONFIGS:
|
||||
if not getattr(target_config, "skip_register", False):
|
||||
native.register_toolchains(
|
||||
"@zig_sdk//:%s_toolchain" % target_config.target,
|
||||
)
|
||||
@ -188,18 +188,6 @@ def zig_build_macro(absolute_path, zig_include_root):
|
||||
filegroup(name = "zig_compiler", srcs = ["zig"])
|
||||
filegroup(name = "lib/std", srcs = native.glob(["lib/std/**"]))
|
||||
|
||||
native.constraint_setting(name = "libc")
|
||||
|
||||
native.constraint_value(
|
||||
name = "libc_musl",
|
||||
constraint_setting = ":libc",
|
||||
)
|
||||
|
||||
native.constraint_value(
|
||||
name = "libc_gnu",
|
||||
constraint_setting = ":libc",
|
||||
)
|
||||
|
||||
lazy_filegroups = {}
|
||||
|
||||
for target_config in TARGET_CONFIGS:
|
||||
|
Loading…
Reference in New Issue
Block a user