rust icon indicating copy to clipboard operation
rust copied to clipboard

Using protoc-bin-vendored doesn't work when building on NixOS

Open aeblyve opened this issue 10 months ago • 3 comments

NixOS is a Linux distribution which does not obey the FHS, and as such, the protoc supplied by protoc-bin-vendored-linux will fail to run:

error: failed to run custom build command for `meshtastic v0.1.6`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `/home/ablyve/my/83e_meshtastic-bot/target/debug/build/meshtastic-bf53c0c18fbe98d1/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=src/protobufs/

  --- stderr
  thread 'main' panicked at /home/ablyve/.cargo/registry/src/index.crates.io-6f17d22bba15001f/meshtastic-0.1.6/build.rs:49:54:
  called `Result::unwrap()` on an `Err` value: Custom { kind: NotFound, error: "failed to invoke protoc (hint: https://docs.rs/prost-build/#sourcing-protoc): (path: \"/home/ablyve/.cargo/registry/src/index.crates.io-6f17d22bba15001f/protoc-bin-vendored-linux-x86_64-3.0.0/bin/protoc\"): No such file or directory (os error 2)" }

If we run the binary manually:

/home/ablyve/.cargo/registry/src/index.crates.io-6f17d22bba15001f/protoc-bin-vendored-linux-x86_64-3.0.0/bin/protoc
bash: /home/ablyve/.cargo/registry/src/index.crates.io-6f17d22bba15001f/protoc-bin-vendored-linux-x86_64-3.0.0/bin/protoc: cannot execute: required file not found

As a workaround, doing this patchelf manually on NixOS lets the build finish:

patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) /home/ablyve/.cargo/registry/src/index.crates.io-6f17d22bba15001f/protoc-bin-vendored-linux-x86_64-3.0.0/bin/protoc

aeblyve avatar Apr 20 '24 16:04 aeblyve