diff options
author | Andreas Rammhold <andreas@rammhold.de> | 2019-11-20 07:30:06 +0100 |
---|---|---|
committer | Andreas Rammhold <andreas@rammhold.de> | 2019-11-26 15:05:01 +0100 |
commit | 1b748554d53d1d4bc5c220b673ed6ef202329abf (patch) | |
tree | 3eab8a8d797a07235dc924ce8129884d70ef0e87 /pkgs/build-support/rust | |
parent | 5b2b82c821a061cfcc544bc38eab48df1a499ae4 (diff) | |
download | nixpkgs-1b748554d53d1d4bc5c220b673ed6ef202329abf.tar nixpkgs-1b748554d53d1d4bc5c220b673ed6ef202329abf.tar.gz nixpkgs-1b748554d53d1d4bc5c220b673ed6ef202329abf.tar.bz2 nixpkgs-1b748554d53d1d4bc5c220b673ed6ef202329abf.tar.lz nixpkgs-1b748554d53d1d4bc5c220b673ed6ef202329abf.tar.xz nixpkgs-1b748554d53d1d4bc5c220b673ed6ef202329abf.tar.zst nixpkgs-1b748554d53d1d4bc5c220b673ed6ef202329abf.zip |
buildRustCrate: add lib output
This cuts down the dependency tree on some rust builds where a crate not just exposes a binary but also a library. `$out/lib` contained a bunch of extra support files that among other information carry linker flags (including the full path to link-time dependencies). Worst case this led to some binary outputs depending on the full build closure of rust crates. Moving all the `$out/lib` files to `$lib/lib` solves this nicely. `lib` might be a bit weird here as they are most of the time just rlib files (rust libraries). Those are essential only required during compilation but they can also be shared objects (like with traditional C-style packages). Which is why I went with `lib` for the new output. One of the caveats we are running into here is that we do not (always) know ahead of time of a crate produces just a library or just a binary. Cargo allows for some ambiguity regarding whether or not a crate provides one, two, … binaries and libraries as it's outputs. Ideally we would be able to rely on the `crateType` entirely but so far that isn't the case. More work on that area might show how difficult that actually is.
Diffstat (limited to 'pkgs/build-support/rust')
3 files changed, 25 insertions, 20 deletions
diff --git a/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/pkgs/build-support/rust/build-rust-crate/build-crate.nix index e0a52e62561..2537b722cdc 100644 --- a/pkgs/build-support/rust/build-rust-crate/build-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/build-crate.nix @@ -91,18 +91,18 @@ echo "$EXTRA_LINK_SEARCH" | while read i; do if [[ ! -z "$i" ]]; then - for lib in $i; do - echo "-L $lib" >> target/link - L=$(echo $lib | sed -e "s#$(pwd)/target/build#$out/lib#") + for library in $i; do + echo "-L $library" >> target/link + L=$(echo $library | sed -e "s#$(pwd)/target/build#$lib/lib#") echo "-L $L" >> target/link.final done fi done echo "$EXTRA_LINK" | while read i; do if [[ ! -z "$i" ]]; then - for lib in $i; do - echo "-l $lib" >> target/link - echo "-l $lib" >> target/link.final + for library in $i; do + echo "-l $library" >> target/link + echo "-l $library" >> target/link.final done fi done diff --git a/pkgs/build-support/rust/build-rust-crate/default.nix b/pkgs/build-support/rust/build-rust-crate/default.nix index 6534e21c0f0..381485e3752 100644 --- a/pkgs/build-support/rust/build-rust-crate/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/default.nix @@ -22,9 +22,9 @@ let else extern; in (if lib.lists.any (x: x == "lib") dep.crateType then - " --extern ${name}=${dep.out}/lib/lib${extern}-${dep.metadata}.rlib" + " --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}.rlib" else - " --extern ${name}=${dep.out}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}") + " --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}") ) dependencies); echo_build_heading = colors: '' @@ -96,12 +96,12 @@ stdenv.mkDerivation (rec { buildInputs = (crate.buildInputs or []) ++ buildInputs_; dependencies = builtins.map - (dep: dep.override { rust = rust; release = release; verbose = verbose; crateOverrides = crateOverrides; }) + (dep: lib.getLib (dep.override { rust = rust; release = release; verbose = verbose; crateOverrides = crateOverrides; })) dependencies_; buildDependencies = builtins.map - (dep: dep.override { rust = rust; release = release; verbose = verbose; crateOverrides = crateOverrides; }) + (dep: lib.getLib (dep.override { rust = rust; release = release; verbose = verbose; crateOverrides = crateOverrides; })) buildDependencies_; completeDeps = lib.lists.unique (dependencies ++ lib.lists.concatMap (dep: dep.completeDeps) dependencies); @@ -160,6 +160,9 @@ stdenv.mkDerivation (rec { }; installPhase = installCrate crateName metadata; + outputs = [ "out" "lib" ]; + outputDev = [ "lib" ]; + } // extraDerivationAttrs )) { rust = rustc; diff --git a/pkgs/build-support/rust/build-rust-crate/install-crate.nix b/pkgs/build-support/rust/build-rust-crate/install-crate.nix index 3b0282621ea..934c3a03176 100644 --- a/pkgs/build-support/rust/build-rust-crate/install-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/install-crate.nix @@ -1,24 +1,26 @@ crateName: metadata: '' runHook preInstall - mkdir -p $out + # always create $out even if we do not have binaries. We are detecting binary targets during compilation, if those are missing there is no way to only have $lib + mkdir $out if [[ -s target/env ]]; then - cp target/env $out/env + mkdir -p $lib + cp target/env $lib/env fi if [[ -s target/link.final ]]; then - mkdir -p $out/lib - cp target/link.final $out/lib/link + mkdir -p $lib/lib + cp target/link.final $lib/lib/link fi if [[ "$(ls -A target/lib)" ]]; then - mkdir -p $out/lib - cp target/lib/* $out/lib #*/ - for lib in $out/lib/*.so $out/lib/*.dylib; do #*/ - ln -s $lib $(echo $lib | sed -e "s/-${metadata}//") + mkdir -p $lib/lib + cp target/lib/* $lib/lib #*/ + for library in $lib/lib/*.so $lib/lib/*.dylib; do #*/ + ln -s $library $(echo $library | sed -e "s/-${metadata}//") done fi if [[ "$(ls -A target/build)" ]]; then # */ - mkdir -p $out/lib - cp -r target/build/* $out/lib # */ + mkdir -p $lib/lib + cp -r target/build/* $lib/lib # */ fi if [[ -d target/bin ]]; then if [[ "$(ls -A target/bin)" ]]; then |