zig
zig copied to clipboard
compile errors occur when the global cache is cleaned/wiped/deleted but the local cache is not because it has dangling references to global cache files
Zig Version
0.9.0-dev.1414+cde3dd365
Steps to Reproduce
Using bazel-zig-cc@361fc42b, build a cgo project with zig cc
and pure = off
.
go_binary(
name = "some",
embed = [":some_lib"],
goarch = "amd64",
goos = "linux",
pure = "off",
visibility = ["//visibility:public"],
)
Expected Behavior
It should build.
Actual Behavior
(11:17:01) ERROR: /private/var/tmp/_bazel_thomas/b6a3c999aae05297a54a9aa13d7a50c3/external/io_bazel_rules_go/BUILD.bazel:44:7: GoStdlib external/io_bazel_rules_go/stdlib_/pkg failed: (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder stdlib -sdk external/go_sdk -installsuffix linux_amd64 -out bazel-out/darwin-fastbuild-ST-64800c94ce45/bin/external/io_bazel_rules_go/stdlib_
Use --sandbox_debug to see verbose messages from the sandbox
# runtime/cgo
WARNING: flock not found, proceeding unsafely.
If build fails, retry it.
ld.lld: error: cannot open /var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T//bazel-zig-cc/o/fdb8c1e82b0cc8d72c53e7cb12c0ef9b/Scrt1.o: No such file or directory
ld.lld: error: cannot open /var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T//bazel-zig-cc/o/1e260ac65a7a7021ed17a6f508533e22/crti.o: No such file or directory
ld.lld: error: cannot open /var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T//bazel-zig-cc/o/965602877839941573a56b32b0c704a7/crtn.o: No such file or directory
Duplicate of #9439.
btw what is going on here?
WARNING: flock not found, proceeding unsafely.
zig is relying on flock() for correctness; is there some reason it's unable to call flock()?
Sorry @andrewrk, please ignore that warning. This is generated by the shell script wrapper as part of the Zig CC rules for Bazel.
https://git.sr.ht/~motiejus/bazel-zig-cc/tree/e4798822241ce838ab880817acb1cca4011510c0/item/toolchain/defs.bzl#L201
#9439 is fixed in 274555be21ea756d8480a586f771274a79a58d80. However, I'm not 100% sure this issue is resolved, and I have more cache system improvements planned, so I'm re-opening it now. I will double-check Scrt1.o and friends along with these improvements and check back in with this issue.
I've just been playing with 0.9.0-dev.1926+803178353
and things are looking way better, but I'm seeing some new (related?) issues. I'm building on a macOS x86-64 host targeting macOS x86-64.
ERROR: /Users/thomas/<REDACTED>_test failed: (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder link -sdk external/go_sdk -installsuffix darwin_amd64 -buildmode pie -arc ... (remaining 33 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
external/go_sdk/pkg/tool/darwin_amd64/link: running /private/var/tmp/_bazel_thomas/b6a3c999aae05297a54a9aa13d7a50c3/external/zig_sdk/tools/c++ failed: exit status 1
warning: unsupported linker arg: -S
warning: unsupported linker arg: --compress-debug-sections
warning: unsupported linker arg: zlib-gnu
warning(link): framework not found for '-framework CoreFoundation'
warning(link): framework not found for '-framework Security'
warning(link): Framework search paths:
error(link): undefined reference to symbol '_CFStringCreateWithBytes'
error(link): first referenced in '/private/var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T/go-link-3249669388/go.o'
error: UndefinedSymbolReference
link: error running subcommand external/go_sdk/pkg/tool/darwin_amd64/link: exit status 2
Possibly a shot in the dark, but you may be missing --sysroot
in zig cc. See this: https://github.com/ziglang/zig/issues/10299#issuecomment-989153750
This fix is possibly related to this issue: 77836e08a2384450b5e7933094511b61e3c22140
I imagine the original issue for this is probably resolved. I haven't seen it in a long time, but also have been using a caching strategy where each invocation of Zig CC starts from scratch. I am still seeing the error mentioned in https://github.com/ziglang/zig/issues/10158#issuecomment-989728346 though.
(10:13:05) ERROR: <REDACTED>/BUILD.bazel:10:8: GoLink <REDACTED>_test failed: (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder link -sdk external/go_sdk -installsuffix darwin_amd64 -buildmode pie -arc ... (remaining 35 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
external/go_sdk/pkg/tool/darwin_amd64/link: running /private/var/tmp/_bazel_thomas/b6a3c999aae05297a54a9aa13d7a50c3/external/zig_sdk/tools/c++ failed: exit status 1
warning: unsupported linker arg: -S
warning: unsupported linker arg: --compress-debug-sections
warning: unsupported linker arg: zlib-gnu
warning(link): framework not found for '-framework CoreFoundation'
warning(link): framework not found for '-framework Security'
warning(link): Framework search paths:
error(link): undefined reference to symbol '_CFStringCreateWithBytes'
error(link): first referenced in '/private/var/folders/d5/hqd0d3f17h7gmntg94k251z80000gn/T/go-link-758804375/go.o'
error: UndefinedSymbolReference
link: error running subcommand external/go_sdk/pkg/tool/darwin_amd64/link: exit status 2
I'll do some testing with a shared cache again and see how things go 😄
This looks like trying to cross compile something that depends on the symbol _CFStringCreateWithBytes
without linking CoreFoundation, which is where the symbol is provided. This is working as designed, and is not a problem with zig's cache system.
The only improvement to make here on zig's end would be:
error: framework not found for '-framework CoreFoundation'
info: searched for CoreFoundation in these paths: [...]
error: framework not found for '-framework Security'
info: searched for Security in these paths: [...]
...and then stop there, instead of mentioning undefined symbols.
However since you mentioned that your host and target are both x86_64-macos, I have to ask, what -target
argument are you passing to zig? If you do not pass -target
then you are building natively and I expect zig to pick up the CoreFoundation from your host system. However if you are passing -target x86_64-macos
then this is a cross-compiled build, and the above error messages are correct. In such case you could resolve the issue by using the host framework definitions by adding --sysroot $(xcrun --show-sdk-path)
to the zig cc
command line.
Ahhh you know what I bet I know what happened for the original issue that you reported.
Hmm, I'm not so sure that conclusion is correct. The ZIG_LOCAL_CACHE_DIR
and ZIG_GLOBAL_CACHE_DIR
environment variables were and always have been identical.
https://git.sr.ht/~motiejus/bazel-zig-cc/tree/361fc42b2e1282ed078bf9c1ad281642e19858d4/item/toolchain/defs.bzl#L191
Looks like this issue still shows up occasionally.
Version 0.10.0-dev.1393+291f5055f
.
Example:
ld.lld: error: cannot open /var/folders/3k/z0djtwqd4s5_xrwz0nlgfx700000gp/T//bazel-zig-cc/o/577b5020915dd149714a9b44041a9be8/Scrt1.o: No such file or directory
ld.lld: error: cannot open /var/folders/3k/z0djtwqd4s5_xrwz0nlgfx700000gp/T//bazel-zig-cc/o/ee268b08503a370b073e628082bd0a9d/crti.o: No such file or directory
ld.lld: error: cannot open /var/folders/3k/z0djtwqd4s5_xrwz0nlgfx700000gp/T//bazel-zig-cc/o/3ae3c7caf4ea05e4f0be12ff06b54095/crtn.o: No such file or directory