diff --git a/test/cgo/BUILD b/test/cgo/BUILD index 71863ec..a65c350 100644 --- a/test/cgo/BUILD +++ b/test/cgo/BUILD @@ -6,7 +6,6 @@ go_library( name = "cgo_lib", srcs = ["cgo.go"], cgo = True, - clinkopts = ["-lresolv"], importpath = "git.sr.ht/~motiejus/bazel-zig-cc/test/cgo", visibility = ["//visibility:private"], ) diff --git a/test/cgo/cgo.go b/test/cgo/cgo.go index 77afdf6..5c654f8 100644 --- a/test/cgo/cgo.go +++ b/test/cgo/cgo.go @@ -1,13 +1,8 @@ package main -// #define _FILE_OFFSET_BITS 64 -// #include -// #include // #include -// #include // char* hello() { return "hello, world"; } -// void phello() { printf("%s, your lucky numbers are %p and %p\n", hello(), fcntl, res_search); } -// #cgo LDFLAGS: -lresolv +// void phello() { printf("%s\n", hello()); } import "C" func main() { diff --git a/test/glibc_hacks/BUILD b/test/glibc_hacks/BUILD new file mode 100644 index 0000000..4b458a9 --- /dev/null +++ b/test/glibc_hacks/BUILD @@ -0,0 +1,22 @@ +load("@bazel-zig-cc//rules:platform.bzl", "platform_binary") + +cc_binary( + name = "main", + srcs = ["main.c"], +) + +[ + ( + platform_binary( + name = "main_{}".format(name), + src = "main", + platform = platform, + ), + ) + for name, platform in [ + ("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl"), + ("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19"), + ("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28"), + ("linux_arm64_musl", "//libc_aware/platform:linux_arm64_musl"), + ] +] diff --git a/test/glibc_hacks/main.c b/test/glibc_hacks/main.c new file mode 100644 index 0000000..fd86b36 --- /dev/null +++ b/test/glibc_hacks/main.c @@ -0,0 +1,13 @@ +// This file tests that problematic functions (glibc-hacks) work. +// Also see https://github.com/ziglang/zig/issues/9485 + +#define _FILE_OFFSET_BITS 64 +#include +#include +#include +#include + +int main() { + printf("Your lucky numbers are %p and %p\n", fcntl, res_search); + return 0; +} diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index 08e1fc5..e50f5e3 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -208,9 +208,12 @@ def _zig_repository_impl(repository_ctx): fcntl_hack = _glibc_hack("fcntl64", "fcntl@GLIBC_2.2.5") repository_ctx.file("glibc-hacks/fcntl.map", content = fcntl_hack.mapfile) repository_ctx.file("glibc-hacks/fcntl.h", content = fcntl_hack.header) - res_search_hack = _glibc_hack("res_search", "__res_search@GLIBC_2.2.5") - repository_ctx.file("glibc-hacks/res_search.map", content = res_search_hack.mapfile) - repository_ctx.file("glibc-hacks/res_search.h", content = res_search_hack.header) + res_search_amd64 = _glibc_hack("res_search", "__res_search@GLIBC_2.2.5") + repository_ctx.file("glibc-hacks/res_search-amd64.map", content = res_search_amd64.mapfile) + repository_ctx.file("glibc-hacks/res_search-amd64.h", content = res_search_amd64.header) + res_search_arm64 = _glibc_hack("res_search", "__res_search@GLIBC_2.17") + repository_ctx.file("glibc-hacks/res_search-arm64.map", content = res_search_arm64.mapfile) + repository_ctx.file("glibc-hacks/res_search-arm64.h", content = res_search_arm64.header) zig_repository = repository_rule( attrs = { diff --git a/toolchain/private/defs.bzl b/toolchain/private/defs.bzl index cf1caca..f9589f7 100644 --- a/toolchain/private/defs.bzl +++ b/toolchain/private/defs.bzl @@ -128,8 +128,8 @@ def _target_linux_gnu(gocpu, zigcpu, glibc_version): compiler_extra_includes.append("glibc-hacks/fcntl.h") linker_version_scripts.append("glibc-hacks/fcntl.map") if glibc_version < "2.34": - compiler_extra_includes.append("glibc-hacks/res_search.h") - linker_version_scripts.append("glibc-hacks/res_search.map") + compiler_extra_includes.append("glibc-hacks/res_search-{}.h".format(gocpu)) + linker_version_scripts.append("glibc-hacks/res_search-{}.map".format(gocpu)) return struct( gotarget = "linux_{}_{}".format(gocpu, glibc_suffix),