rustPlatform: add buildAndTestSubdir
-argument
There are several tarballs (such as the `rust-lang/rust`-source) with a `Cargo.toml` at root and several sub-packages (with their own Cargo.toml) without using workspaces[1]. In such a case it's needed to move into a subdir to only build the specified sub-package (e.g. `rustfmt` or `rsl`), however the artifacts are at `/target` in the root-dir of the build environment. This breaks the build since `buildRustPackage` searches for executables in `target` (which is at the build-env's root) at the end of the `buildPhase`. With the optional `buildAndTestSubdir`-argument, the builder moves into the specified subdir using `pushd`/`popd` during `buildPhase` and `checkPhase`. Also moved the logic to find executables and libs to the end of the `buildPhase` from a custom `postBuild`-hook to fix packages with custom `build`/`install`-procedures such as `uutils-coreutils`. [1] https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html
This commit is contained in:
parent
736462d995
commit
6b23cfe689
@ -29,6 +29,12 @@
|
|||||||
, target ? null
|
, target ? null
|
||||||
, cargoVendorDir ? null
|
, cargoVendorDir ? null
|
||||||
, checkType ? buildType
|
, checkType ? buildType
|
||||||
|
|
||||||
|
# Needed to `pushd`/`popd` into a subdir of a tarball if this subdir
|
||||||
|
# contains a Cargo.toml, but isn't part of a workspace (which is e.g. the
|
||||||
|
# case for `rustfmt`/etc from the `rust-sources).
|
||||||
|
# Otherwise, everything from the tarball would've been built/tested.
|
||||||
|
, buildAndTestSubdir ? null
|
||||||
, ... } @ args:
|
, ... } @ args:
|
||||||
|
|
||||||
assert cargoVendorDir == null -> cargoSha256 != "unset";
|
assert cargoVendorDir == null -> cargoSha256 != "unset";
|
||||||
@ -162,6 +168,7 @@ stdenv.mkDerivation (args // {
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
buildPhase = with builtins; args.buildPhase or ''
|
buildPhase = with builtins; args.buildPhase or ''
|
||||||
|
${stdenv.lib.optionalString (buildAndTestSubdir != null) "pushd ${buildAndTestSubdir}"}
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -178,9 +185,8 @@ stdenv.mkDerivation (args // {
|
|||||||
)
|
)
|
||||||
|
|
||||||
runHook postBuild
|
runHook postBuild
|
||||||
'';
|
|
||||||
|
|
||||||
postBuild = args.postBuild or "" + ''
|
${stdenv.lib.optionalString (buildAndTestSubdir != null) "popd"}
|
||||||
|
|
||||||
# This needs to be done after postBuild: packages like `cargo` do a pushd/popd in
|
# This needs to be done after postBuild: packages like `cargo` do a pushd/popd in
|
||||||
# the pre/postBuild-hooks that need to be taken into account before gathering
|
# the pre/postBuild-hooks that need to be taken into account before gathering
|
||||||
@ -194,10 +200,12 @@ stdenv.mkDerivation (args // {
|
|||||||
checkPhase = args.checkPhase or (let
|
checkPhase = args.checkPhase or (let
|
||||||
argstr = "${stdenv.lib.optionalString (checkType == "release") "--release"} --target ${rustTarget} --frozen";
|
argstr = "${stdenv.lib.optionalString (checkType == "release") "--release"} --target ${rustTarget} --frozen";
|
||||||
in ''
|
in ''
|
||||||
|
${stdenv.lib.optionalString (buildAndTestSubdir != null) "pushd ${buildAndTestSubdir}"}
|
||||||
runHook preCheck
|
runHook preCheck
|
||||||
echo "Running cargo test ${argstr} -- ''${checkFlags} ''${checkFlagsArray+''${checkFlagsArray[@]}}"
|
echo "Running cargo test ${argstr} -- ''${checkFlags} ''${checkFlagsArray+''${checkFlagsArray[@]}}"
|
||||||
cargo test ${argstr} -- ''${checkFlags} ''${checkFlagsArray+"''${checkFlagsArray[@]}"}
|
cargo test ${argstr} -- ''${checkFlags} ''${checkFlagsArray+"''${checkFlagsArray[@]}"}
|
||||||
runHook postCheck
|
runHook postCheck
|
||||||
|
${stdenv.lib.optionalString (buildAndTestSubdir != null) "popd"}
|
||||||
'');
|
'');
|
||||||
|
|
||||||
doCheck = args.doCheck or true;
|
doCheck = args.doCheck or true;
|
||||||
|
@ -9,8 +9,7 @@ rustPlatform.buildRustPackage {
|
|||||||
|
|
||||||
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
|
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
|
||||||
cargoVendorDir = "vendor";
|
cargoVendorDir = "vendor";
|
||||||
preBuild = "pushd src/tools/cargo";
|
buildAndTestSubdir = "src/tools/cargo";
|
||||||
postBuild = "popd";
|
|
||||||
|
|
||||||
passthru.rustc = rustc;
|
passthru.rustc = rustc;
|
||||||
|
|
||||||
|
@ -5,8 +5,7 @@ rustPlatform.buildRustPackage {
|
|||||||
|
|
||||||
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
|
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
|
||||||
cargoVendorDir = "vendor";
|
cargoVendorDir = "vendor";
|
||||||
preBuild = "pushd src/tools/clippy";
|
buildAndTestSubdir = "src/tools/clippy";
|
||||||
postBuild = "popd";
|
|
||||||
|
|
||||||
# changes hash of vendor directory otherwise
|
# changes hash of vendor directory otherwise
|
||||||
dontUpdateAutotoolsGnuConfigScripts = true;
|
dontUpdateAutotoolsGnuConfigScripts = true;
|
||||||
|
@ -10,8 +10,9 @@ rustPlatform.buildRustPackage {
|
|||||||
dontUpdateAutotoolsGnuConfigScripts = true;
|
dontUpdateAutotoolsGnuConfigScripts = true;
|
||||||
|
|
||||||
cargoVendorDir = "vendor";
|
cargoVendorDir = "vendor";
|
||||||
|
buildAndTestSubdir = "src/tools/rls";
|
||||||
|
|
||||||
preBuild = ''
|
preBuild = ''
|
||||||
pushd src/tools/rls
|
|
||||||
# client tests are flaky
|
# client tests are flaky
|
||||||
rm tests/client.rs
|
rm tests/client.rs
|
||||||
'';
|
'';
|
||||||
@ -28,8 +29,6 @@ rustPlatform.buildRustPackage {
|
|||||||
|
|
||||||
doCheck = true;
|
doCheck = true;
|
||||||
|
|
||||||
preInstall = "popd";
|
|
||||||
|
|
||||||
doInstallCheck = true;
|
doInstallCheck = true;
|
||||||
installCheckPhase = ''
|
installCheckPhase = ''
|
||||||
$out/bin/rls --version
|
$out/bin/rls --version
|
||||||
|
@ -6,8 +6,7 @@ rustPlatform.buildRustPackage rec {
|
|||||||
|
|
||||||
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
|
# the rust source tarball already has all the dependencies vendored, no need to fetch them again
|
||||||
cargoVendorDir = "vendor";
|
cargoVendorDir = "vendor";
|
||||||
preBuild = "pushd src/tools/rustfmt";
|
buildAndTestSubdir = "src/tools/rustfmt";
|
||||||
preInstall = "popd";
|
|
||||||
|
|
||||||
# changes hash of vendor directory otherwise
|
# changes hash of vendor directory otherwise
|
||||||
dontUpdateAutotoolsGnuConfigScripts = true;
|
dontUpdateAutotoolsGnuConfigScripts = true;
|
||||||
@ -17,12 +16,6 @@ rustPlatform.buildRustPackage rec {
|
|||||||
# As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler
|
# As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler
|
||||||
RUSTC_BOOTSTRAP = 1;
|
RUSTC_BOOTSTRAP = 1;
|
||||||
|
|
||||||
# we run tests in debug mode so tests look for a debug build of
|
|
||||||
# rustfmt. Anyway this adds nearly no compilation time.
|
|
||||||
preCheck = ''
|
|
||||||
cargo build
|
|
||||||
'';
|
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with stdenv.lib; {
|
||||||
description = "A tool for formatting Rust code according to style guidelines";
|
description = "A tool for formatting Rust code according to style guidelines";
|
||||||
homepage = "https://github.com/rust-lang-nursery/rustfmt";
|
homepage = "https://github.com/rust-lang-nursery/rustfmt";
|
||||||
|
@ -15,9 +15,7 @@ rustPlatform.buildRustPackage {
|
|||||||
inherit rev sha256;
|
inherit rev sha256;
|
||||||
};
|
};
|
||||||
|
|
||||||
preBuild = "pushd crates/rust-analyzer";
|
buildAndTestSubdir = "crates/rust-analyzer";
|
||||||
# Do not checking other crates in checkPhase.
|
|
||||||
preInstall = "popd";
|
|
||||||
|
|
||||||
cargoBuildFlags = lib.optional useJemalloc "--features=jemalloc";
|
cargoBuildFlags = lib.optional useJemalloc "--features=jemalloc";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user