Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected arguments in NIX_LDFLAGS and NIX_CFLAGS_COMPILE on Darwin #19879

Open
SkamDart opened this issue May 7, 2024 · 1 comment
Open
Labels
error message This issue points out an error message that is unhelpful and should be improved.

Comments

@SkamDart
Copy link

SkamDart commented May 7, 2024

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
@SkamDart SkamDart added the error message This issue points out an error message that is unhelpful and should be improved. label May 7, 2024
@Cloudef
Copy link
Contributor

Cloudef commented May 8, 2024

related #18998

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

2 participants