ziglang/zig

Unexpected arguments in NIX_LDFLAGS and NIX_CFLAGS_COMPILE on Darwin

SkamDart opened this issue · 1 comments

Zig Version

0.13.0-dev.46+3648d7df1

Steps to Reproduce and Observed Output

System

$ uname -a
Darwin computer.lan 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:37 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6031 arm64 arm Darwin

Zig Version

$ zig version
0.13.0-dev.46+3648d7df1

Nix Tomfoolery

Pull in some nix provided 'system' dependency

$ nix-shell -p openssl.dev pkg-config

$ echo $NIX_CFLAGS_COMPILE 
-F/nix/store/sxzlz1jn2hxpvh4w2vylcqz4w1l1xf1f-apple-framework-CoreFoundation-11.0.0/Library/Frameworks -frandom-seed=2rlbpgnljj -isystem /nix/store/a0w1lbm1hf6w8s36b6pbfvhkgv9fxxwq-libcxx-16
.0.6-dev/include -isystem /nix/store/dyvg1p2bx86m5x842kxwcas8y7vgiakg-libcxxabi-16.0.6-dev/include -isystem /nix/store/id31ddm6rg89jsxhxa05vs4a6gjyk40j-compiler-rt-libc-16.0.6-dev/include -i
system /nix/store/g9mfln937f6i79m1ykxlsil26i9yyzwy-openssl-3.0.13-dev/include -iframework /nix/store/sxzlz1jn2hxpvh4w2vylcqz4w1l1xf1f-apple-framework-CoreFoundation-11.0.0/Library/Frameworks
 -isystem /nix/store/77wxca8aqv8dgp43z87i0rcisivr868a-libobjc-11.0.0/include -isystem /nix/store/a0w1lbm1hf6w8s36b6pbfvhkgv9fxxwq-libcxx-16.0.6-dev/include -isystem /nix/store/dyvg1p2bx86m5x
842kxwcas8y7vgiakg-libcxxabi-16.0.6-dev/include -isystem /nix/store/id31ddm6rg89jsxhxa05vs4a6gjyk40j-compiler-rt-libc-16.0.6-dev/include -isystem /nix/store/g9mfln937f6i79m1ykxlsil26i9yyzwy-
openssl-3.0.13-dev/include -iframework /nix/store/sxzlz1jn2hxpvh4w2vylcqz4w1l1xf1f-apple-framework-CoreFoundation-11.0.0/Library/Frameworks -isystem /nix/store/77wxca8aqv8dgp43z87i0rcisivr86
8a-libobjc-11.0.0/include

$ echo $NIX_LDFLAGS 
/nix/store/sxzlz1jn2hxpvh4w2vylcqz4w1l1xf1f-apple-framework-CoreFoundation-11.0.0/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd -L/nix/store/mn2x6j8b77pyrsxl3a46gvzm9wsy7001
-libcxx-16.0.6/lib -L/nix/store/9cjqpbaf338fmn0d3h4n10lv3658spvf-libcxxabi-16.0.6/lib -L/nix/store/wiz1przb5z0iki34qg6kp8yppmll51kv-compiler-rt-libc-16.0.6/lib -L/nix/store/gjgj1lkacgffqbgn7
9m25ckph3wfahka-openssl-3.0.13/lib -L/nix/store/77wxca8aqv8dgp43z87i0rcisivr868a-libobjc-11.0.0/lib -L/nix/store/mn2x6j8b77pyrsxl3a46gvzm9wsy7001-libcxx-16.0.6/lib -L/nix/store/9cjqpbaf338fm
n0d3h4n10lv3658spvf-libcxxabi-16.0.6/lib -L/nix/store/wiz1przb5z0iki34qg6kp8yppmll51kv-compiler-rt-libc-16.0.6/lib -L/nix/store/gjgj1lkacgffqbgn79m25ckph3wfahka-openssl-3.0.13/lib -L/nix/sto
re/77wxca8aqv8dgp43z87i0rcisivr868a-libobjc-11.0.0/lib

$ pkg-config --list-all
openssl   OpenSSL - Secure Sockets Layer and cryptography libraries and tools
libssl    OpenSSL-libssl - Secure Sockets Layer and cryptography libraries
libcrypto OpenSSL-libcrypto - OpenSSL cryptography library

Zig Tomfoolery

Create a new zig project and link against openssl.

$ zig init

Link against openssl in build.zig

diff --git a/build.zig b/build.zig
index 1aca853..8ea2200 100644
--- a/build.zig
+++ b/build.zig
@@ -36,6 +36,8 @@ pub fn build(b: *std.Build) void {
         .optimize = optimize,
     });
 
+    exe.linkSystemLibrary("openssl");
+
     // This declares intent for the executable to be installed into the
     // standard location when the user invokes the "install" step (the default
     // step when running `zig build`).

Build

[nix-shell:~/uhdz]$ zig build
install
└─ install project
   └─ zig build-exe project Debug native failure
error: warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: -F/nix/store/sxzlz1jn2hxpvh4w2vylcqz4w1l1xf1f-apple-framework-CoreFoundation-11.0.0/Library/Frameworks
warning: Unrecognized C flag from NIX_LDFLAGS: /nix/store/sxzlz1jn2hxpvh4w2vylcqz4w1l1xf1f-apple-framework-CoreFoundation-11.0.0/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tb
d

Run

$ zig run ./src/main.zig 
All your codebase are belong to us.
Run `zig build test` to run the tests.

Expected Output

Successful build.

$ zig build

[nix-shell:~/uhdz]$ echo $?
0

related #18998