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

Rust language can't link with Security framework on darwin #267

Closed
onsails opened this issue Jan 2, 2023 · 16 comments · Fixed by #283
Closed

Rust language can't link with Security framework on darwin #267

onsails opened this issue Jan 2, 2023 · 16 comments · Fixed by #283
Labels
bug Something isn't working

Comments

@onsails
Copy link
Contributor

onsails commented Jan 2, 2023

Describe the bug
When compiling some rust code which requires openssl or other Security-related dependencies compilation fails with

  = note: ld: framework not found Security
          clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

To Reproduce
https://gist.github.com/onsails/d2d33a63d88a5e7d656048bd5fa5a6b9.

Version

0.5

@onsails onsails added the bug Something isn't working label Jan 2, 2023
@domenkozar
Copy link
Member

I'll look into it. By the way, you don't need fenix here at all :)

@onsails
Copy link
Contributor Author

onsails commented Jan 2, 2023

Figured out workaround:

              env.RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
                openssl.dev
              ]) ++ (lib.optionals stdenv.isDarwin (with darwin.apple_sdk; [
                "-L${libiconv}/lib"
                "-L framework=${frameworks.Security}/Library/Frameworks"
              ]));

@onsails
Copy link
Contributor Author

onsails commented Jan 2, 2023

Also that's how devshell solves this.

@domenkozar
Copy link
Member

Hey! Could you make a PR adding this to languages/rust.nix?

@onsails
Copy link
Contributor Author

onsails commented Jan 3, 2023

Hey! Sure, as soon as I figure out the most clean API design which lets user customize RUSTFLAGS predefined by the rust language module.

@smunix
Copy link

smunix commented Jan 15, 2023

Can we reopen this? It breaks devenv buidls on darwin, see details at #283 (comment)

@domenkozar domenkozar reopened this Jan 15, 2023
@domenkozar
Copy link
Member

Fixed!

@hauleth
Copy link
Contributor

hauleth commented Feb 15, 2023

I see problem with that solution, if RUSTFLAGS environment variable is set, then Rust will ignore rustflags defined in .cargo/config file, which mean that for example Elixir projects that use Rustler will not compile, as it is required to set some additional flags there.

@domenkozar
Copy link
Member

Is there a way to tell Rust to just prepend those?

@hauleth
Copy link
Contributor

hauleth commented Feb 15, 2023

AFAIK Rust will utilise regular LDFLAGS when available, this is how it worked in "regular Nix shells" with Rust as I never had such problem with these.

@hauleth
Copy link
Contributor

hauleth commented Feb 15, 2023

Ok, it seems more complex, but for whatever reason when I use "plain" Nixpkgs shell instead of Devenv it works perfectly fine. I cannot find the reason why this fails in Devenv so while I really like this idea, I cannot use it right now.

@domenkozar
Copy link
Member

Could you post the gist to reproduce this issue?

@thedavidmeister
Copy link

i see this issue when trying to install foundry

https://github.com/rainprotocol/binmaskflag

try this, devenv shell for me gives errors about security framework on imac M1

@domenkozar
Copy link
Member

Could you open a new issue - this one slipped my attention since it's closed.

@thenonameguy
Copy link
Contributor

@domenkozar the problem lies with not running the setup-hooks (thanks to my naked shell change 😭 ). Especially problematic is the lack of NIX_CFLAGS_COMPILE env var. As this env var is used to pass down configurations to the Rust-underlying Clang (MacOS) / gcc (Linux) compiler.
It's a really hard problem though, as this means that we must run the setup-hooks if we want to get to feature parity with normal nix-shell. Will have to think about this.

@thenonameguy
Copy link
Contributor

thenonameguy commented Mar 17, 2023

Figured this out via:

devenv shell
nix-shell -p darwin.apple_sdk.frameworks.Security
env | sort > nix-shell.env
exit
env | sort > devenv.env
diff devenv.env nix-shell.env

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants