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
go: add CoreFoundation and Security frameworks for cgo on darwin #90592
Conversation
postInstall = optionalString stdenv.isDarwin (with darwin.apple_sdk.frameworks; '' | ||
wrapProgram $out/share/go/bin/go \ | ||
--suffix CGO_CFLAGS ' ' '-iframework ${CoreFoundation}/Library/Frameworks -iframework ${Security}/Library/Frameworks' \ | ||
--suffix CGO_LDFLAGS ' ' '-F${CoreFoundation}/Library/Frameworks -F${Security}/Library/Frameworks' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also use NIX_CFLAGS and NIX_LDFLAGS, not sure what's best?
I have not tried this yet, but I can confirm that this is a constant source of annoyance for us because Go crashes anytime we import something that uses C. On my end (at work) I have this snippet which works (copied only relevant parts, but you get the idea):
I'm not sure if we need all frameworks though. |
I looked through the go source, CoreFoundation and Security is all that's needed |
We already do in
This means in a |
Also cc @LnL7 and @Ericson2314 |
Yep, it works with nix-shell. Under the hood cgo uses $CC. I have somehow overlooked that those frameworks were already being propagated. But what I (and others) are running against is that you can't use the compiler directly outside of a nix-shell, since those NIX_LDFLAGS are not set. Another solution might be for nix-Darwin et al to add flags that are set through depsTargetTargetPropagated (and similar things) in the environment, so the user's shell picks them up. This would emulate being in a nix-shell at all times. I'd personally prefer the wrapper approach since it reduces the scope of where the flags get set. |
Closing in favor of #91347 |
Here I'm adding some CGO flags to ensure the c compiler is able to find system frameworks on Darwin. These frameworks need to be always available, to ensure some parts of the standard library (notably
crypto/x509
) can be compiled.I've also added a test that reproduces the issue.
Motivation for this change
See #56348 for background
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)