Add libc constraint and libc aware toolchains
- Also get rid of @bazel_skylib dependency
This commit is contained in:
46
test/c/BUILD
Normal file
46
test/c/BUILD
Normal file
@@ -0,0 +1,46 @@
|
||||
load("@bazel-zig-cc//rules:platform.bzl", "platform_binary")
|
||||
|
||||
cc_binary(
|
||||
name = "which_libc",
|
||||
srcs = ["main.c"],
|
||||
target_compatible_with = [
|
||||
"@platforms//os:linux",
|
||||
],
|
||||
)
|
||||
|
||||
[
|
||||
(
|
||||
platform_binary(
|
||||
name = "which_libc_{}".format(name),
|
||||
src = "which_libc",
|
||||
extra_toolchains = [
|
||||
# toolchains for specific libc versions
|
||||
"//libc_aware/toolchain:linux_amd64_gnu.2.19",
|
||||
"//libc_aware/toolchain:linux_amd64_gnu.2.28",
|
||||
"//libc_aware/toolchain:linux_amd64_gnu.2.31",
|
||||
"//libc_aware/toolchain:linux_amd64_musl",
|
||||
# fallback toolchains
|
||||
"//toolchain:linux_amd64_gnu.2.19",
|
||||
"//toolchain:linux_arm64_gnu.2.28",
|
||||
],
|
||||
platform = platform,
|
||||
),
|
||||
sh_test(
|
||||
name = "test_libc_{}".format(name),
|
||||
srcs = ["test.sh"],
|
||||
data = ["which_libc_{}".format(name)],
|
||||
env = {
|
||||
"WANT": want,
|
||||
"BINARY": "$(location which_libc_{})".format(name),
|
||||
},
|
||||
),
|
||||
)
|
||||
for name, platform, want in [
|
||||
("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl", "non-glibc"),
|
||||
("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19", "glibc_2.19"),
|
||||
("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28", "glibc_2.28"),
|
||||
("linux_amd64_gnu.2.31", "//libc_aware/platform:linux_amd64_gnu.2.31", "glibc_2.31"),
|
||||
("linux_amd64", "//platform:linux_amd64", "glibc_2.19"),
|
||||
("linux_arm64", "//platform:linux_arm64", "glibc_2.28"),
|
||||
]
|
||||
]
|
||||
11
test/c/main.c
Normal file
11
test/c/main.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <features.h>
|
||||
|
||||
int main() {
|
||||
#ifdef __GLIBC__
|
||||
printf("glibc_%d.%d", __GLIBC__, __GLIBC_MINOR__);
|
||||
#else
|
||||
puts("non-glibc");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
16
test/c/test.sh
Executable file
16
test/c/test.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
want=$WANT
|
||||
binary=$BINARY
|
||||
|
||||
got=$($binary)
|
||||
|
||||
if [[ "$got" != "$want" ]]; then
|
||||
echo wanted:
|
||||
echo \ \ "$want"
|
||||
echo got:
|
||||
echo \ \ "$got"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user