mirror of
https://github.com/nix-community/naersk
synced 2024-11-10 14:14:14 +00:00
Split build and build-plan configuration
This commit is contained in:
parent
9829b21bc1
commit
79ccb516e9
3 changed files with 98 additions and 102 deletions
|
@ -29,7 +29,6 @@ src:
|
|||
# Which drops the run-time dependency on the crates-io source thereby
|
||||
# significantly reducing the Nix closure size.
|
||||
, removeReferencesToSrcFromDocs
|
||||
, cratePaths
|
||||
, pname
|
||||
, version
|
||||
, rustc
|
||||
|
@ -64,7 +63,6 @@ let
|
|||
inherit
|
||||
src
|
||||
doCheck
|
||||
cratePaths
|
||||
version
|
||||
preBuild;
|
||||
|
||||
|
|
68
config.nix
68
config.nix
|
@ -1,10 +1,37 @@
|
|||
{ lib, libb, builtinz, src, attrs }:
|
||||
rec
|
||||
{ usePureFromTOML = attrs.usePureFromTOML or true;
|
||||
let
|
||||
usePureFromTOML = attrs.usePureFromTOML or true;
|
||||
readTOML = builtinz.readTOML usePureFromTOML;
|
||||
|
||||
# config used during build the prebuild and the final build
|
||||
buildConfig =
|
||||
{
|
||||
compressTarget = attrs.compressTarget or true;
|
||||
doCheck = attrs.doCheck or true;
|
||||
buildInputs = attrs.buildInputs or [];
|
||||
removeReferencesToSrcFromDocs = attrs.removeReferencesToSrcFromDocs or true;
|
||||
doDoc = attrs.doDoc or true;
|
||||
#| Whether or not the rustdoc can fail the build
|
||||
doDocFail = attrs.doDocFail or false;
|
||||
|
||||
release = attrs.release or true;
|
||||
|
||||
override = attrs.override or (x: x);
|
||||
|
||||
cargoBuild = attrs.cargoBuild or ''
|
||||
cargo build "''${cargo_release}" -j $NIX_BUILD_CORES -Z unstable-options --out-dir out
|
||||
'';
|
||||
|
||||
# The list of _all_ crates (incl. transitive dependencies) with name,
|
||||
# version and sha256 of the crate
|
||||
# Example:
|
||||
# [ { name = "wabt", version = "2.0.6", sha256 = "..." } ]
|
||||
crateDependencies = libb.mkVersions buildPlanConfig.cargolock;
|
||||
};
|
||||
|
||||
# config used when planning the builds
|
||||
buildPlanConfig = rec
|
||||
{
|
||||
# Whether we skip pre-building the deps
|
||||
isSingleStep = attrs.singleStep or false;
|
||||
|
||||
|
@ -63,55 +90,22 @@ rec
|
|||
# The cargo lock
|
||||
cargolock = readTOML (src + "/Cargo.lock");
|
||||
|
||||
# The list of paths to Cargo.tomls. If this is a workspace, the paths
|
||||
# are the members. Otherwise, there is a single path, ".".
|
||||
cratePaths = lib.concatStringsSep "\n" wantedMembers;
|
||||
|
||||
packageName = attrs.name or toplevelCargotoml.package.name or
|
||||
(if isWorkspace then "rust-workspace" else "rust-package");
|
||||
|
||||
packageVersion = attrs.version or toplevelCargotoml.package.version or
|
||||
"unknown";
|
||||
|
||||
# The list of _all_ crates (incl. transitive dependencies) with name,
|
||||
# version and sha256 of the crate
|
||||
# Example:
|
||||
# [ { name = "wabt", version = "2.0.6", sha256 = "..." } ]
|
||||
crateDependencies = libb.mkVersions cargolock;
|
||||
|
||||
preBuild = ''
|
||||
# Cargo uses mtime, and we write `src/lib.rs` and `src/main.rs`in
|
||||
# the dep build step, so make sure cargo rebuilds stuff
|
||||
if [ -f src/lib.rs ] ; then touch src/lib.rs; fi
|
||||
if [ -f src/main.rs ] ; then touch src/main.rs; fi
|
||||
'';
|
||||
|
||||
cargoBuild = attrs.cargoBuild or ''
|
||||
cargo build "''${cargo_release}" -j $NIX_BUILD_CORES -Z unstable-options --out-dir out
|
||||
'';
|
||||
cargoTestCommands = attrs.cargoTestCommands or [
|
||||
''cargo test "''${cargo_release}" -j $NIX_BUILD_CORES''
|
||||
];
|
||||
|
||||
override = attrs.override or (x: x);
|
||||
|
||||
release = attrs.release or true;
|
||||
|
||||
#| Whether or not to forward intermediate build artifacts to $out
|
||||
copyTarget = attrs.copyTarget or false;
|
||||
|
||||
#| Whether or not the rustdoc can fail the build
|
||||
doDocFail = attrs.doDocFail or false;
|
||||
|
||||
doDoc = attrs.doDoc or true;
|
||||
|
||||
copyBins = attrs.copyBins or true;
|
||||
|
||||
copyDocsToSeparateOutput = attrs.copyDocsToSeparateOutput or true;
|
||||
|
||||
removeReferencesToSrcFromDocs = attrs.removeReferencesToSrcFromDocs or true;
|
||||
|
||||
doCheck = attrs.doCheck or true;
|
||||
|
||||
buildInputs = attrs.buildInputs or [];
|
||||
}
|
||||
};
|
||||
in buildPlanConfig // { inherit buildConfig ; }
|
||||
|
|
16
default.nix
16
default.nix
|
@ -44,9 +44,14 @@ let
|
|||
(defaultBuildAttrs //
|
||||
{ pname = config.packageName;
|
||||
version = config.packageVersion;
|
||||
inherit (config) cratePaths crateDependencies preBuild cargoBuild cargoTestCommands compressTarget override release copyTarget doDocFail doDoc copyBins copyDocsToSeparateOutput removeReferencesToSrcFromDocs doCheck buildInputs;
|
||||
} //
|
||||
(removeAttrs attrs [ "usePureFromTOML" "cargotomls" "singleStep" ]) //
|
||||
preBuild = lib.optionalString (!config.isSingleStep) ''
|
||||
# Cargo uses mtime, and we write `src/lib.rs` and `src/main.rs`in
|
||||
# the dep build step, so make sure cargo rebuilds stuff
|
||||
if [ -f src/lib.rs ] ; then touch src/lib.rs; fi
|
||||
if [ -f src/main.rs ] ; then touch src/main.rs; fi
|
||||
'';
|
||||
inherit (config) cargoTestCommands copyTarget copyBins copyDocsToSeparateOutput ;
|
||||
} // config.buildConfig //
|
||||
{ builtDependencies = lib.optional (! config.isSingleStep)
|
||||
(
|
||||
import ./build.nix
|
||||
|
@ -63,10 +68,9 @@ let
|
|||
(defaultBuildAttrs //
|
||||
{ pname = "${config.packageName}-deps";
|
||||
version = config.packageVersion;
|
||||
inherit (config) cratePaths crateDependencies cargoBuild compressTarget override release doDocFail doDoc removeReferencesToSrcFromDocs doCheck buildInputs;
|
||||
} //
|
||||
(removeAttrs attrs [ "usePureFromTOML" "cargotomls" "singleStep"]) //
|
||||
} // config.buildConfig //
|
||||
{ preBuild = "";
|
||||
# TODO: custom cargoTestCommands should not be needed here
|
||||
cargoTestCommands = map (cmd: "${cmd} || true") config.cargoTestCommands;
|
||||
copyTarget = true;
|
||||
copyBins = false;
|
||||
|
|
Loading…
Reference in a new issue