cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.56k stars 259 forks source link

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

Closed onsails closed 1 year ago

onsails commented 1 year ago

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

domenkozar commented 1 year ago

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

onsails commented 1 year ago

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 commented 1 year ago

Also that's how devshell solves this.

domenkozar commented 1 year ago

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

onsails commented 1 year ago

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 commented 1 year ago

Can we reopen this? It breaks devenv buidls on darwin, see details at https://github.com/cachix/devenv/pull/283#discussion_r1070561727

domenkozar commented 1 year ago

Fixed!

hauleth commented 1 year ago

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 commented 1 year ago

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

hauleth commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Could you post the gist to reproduce this issue?

thedavidmeister commented 1 year ago

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 commented 1 year ago

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

thenonameguy commented 1 year ago

@domenkozar the problem lies with not running the setup-hooks (thanks to my naked shell change :sob: ). 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 commented 1 year ago

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