jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
7.83k stars 187 forks source link

Rust doesn't compile openssl library on MacOSX #2167

Open ineiti opened 1 week ago

ineiti commented 1 week ago

What happened?

I have a rust project which uses openssl. Now I would like to have a reproducible build using devbox. But when I use rustup from devbox, the compilation fails at linking time.

I tried the same repo with flox and a locally installed rust, which compiles and runs fine!

Steps to reproduce

Clone the repo, start the shell, and compile parts of it:

git clone https://github.com/ineiti/fledger
cd fledger
devbox shell
cd cli/fledger
cargo build

The final output of the linker is this:

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

Command

shell

devbox.json

{
  "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.10.7/.schema/devbox.schema.json",
  "packages": [
    "which@latest",
    "rustup@latest",
    "libiconv@latest",
    "openssl@latest",
    "vscode",
  ],
  "shell": {
    "init_hook": [
      "if [ ! -d $RUSTUP_HOME/toolchains -o ! -d $RUSTUP_HOME/toolchains/stable ]; then rustup default stable; fi",
    ],
    "scripts": {
      "test": [
        "make cargo_test",
      ],
    },
  },
}

Devbox version

0.11.1

Nix version

nix (Nix) 2.23.0

What system does this bug occur on?

macOS (Apple Silicon)

Debug logs

No response

savil commented 1 week ago

@ineiti I'd suggest running devbox add "darwin.apple_sdk.frameworks.Security" --platform=x86_64-darwin,aarch64-darwin.

With that, I am able to run cargo build on my x86_64-darwin machine.

Let us know if that does, or does not, work for you?

ineiti commented 1 week ago

@savil Thanks a lot, that solves the problem and it compiles fine now! I did not know about this package, and I did spend 30 minutes on Google with the error message before opening this issue. How could I have discovered this?

Some questions:

savil commented 1 week ago

Those are great questions. I think Devbox should do better here, and in particular since this is a bit of an FAQ for Rust with Macs, we should make it Just Work ™️ . Lets leave this task open for a bit. I'll look into it more this week.

There are some considerations in my mind:

To your questions: