rules_nixpkgs icon indicating copy to clipboard operation
rules_nixpkgs copied to clipboard

Example on bringing in Rust system dependencies (specifically OpenSSL)

Open igrekun opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. Axum brings in zlib dependency which could be solved by modifying shell.nix in rust toolchain example like this

{ pkgs ? import ./nixpkgs.nix { } }:

pkgs.mkShell { nativeBuildInputs = [ pkgs.bazel_4 pkgs.zlib ]; }

For example elasticsearch crate uses native-tls which requires libssl and fails to find it error while loading shared libraries: libssl.so.1.1 Using rusttsl in features weirdly results in the same error.

Describe the solution you'd like Include example on building Rust library / binary with OpenSSL, probably generic example for managing dynamically linked system dependencies.

Describe alternatives you've considered The same trick that I did with zlib didn't cut it for OpenSSL, besides OpenSSL seems present in default shell configuration, it just doesn't resolve with rust toolchain.

{ pkgs ? import ./nixpkgs.nix { } }:

pkgs.mkShell { nativeBuildInputs = [ pkgs.bazel_4 pkgs.zlib pkgs.openssl ]; }

Additional context Full list of Cargo.toml dependencies:

[dependencies]
axum = "0.4.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.68"
tokio = { version = "1.0", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
elasticsearch = "7.14.0-alpha.1"
url = { version = "2", features = ["serde"] }

igrekun avatar Mar 23 '22 16:03 igrekun

Thanks for raising this! Adding it to the Nix shell would not propagate it into the build actions themselves. For that the dependency needs to be declared in Bazel.

@AlexeiDrake didn't you have a working example of something like this?

aherrmann avatar Mar 24 '22 09:03 aherrmann

Could it have something to do with how cargo works under nix + bazel?

Adding zlib to nix shell fixed rust unable to find its headers. Missing zlib failed during nix-shell --command 'bazel build my_target' while with openssl it builds but fails on nix-shell --command 'bazel run my_target'

igrekun avatar Mar 24 '22 12:03 igrekun