naersk/default.nix

100 lines
2.9 KiB
Nix
Raw Normal View History

2019-07-02 10:50:32 +00:00
{ lib
, runCommand
, symlinkJoin
, stdenv
, writeText
, jq
, rsync
, darwin
, remarshal
, cargo
, rustc
2019-11-13 14:18:08 +00:00
, zstd
2019-11-21 09:34:16 +00:00
, fetchurl
2019-06-13 11:26:19 +00:00
}:
2019-08-28 17:21:13 +00:00
let
2019-11-18 15:16:46 +00:00
libb = import ./lib.nix { inherit lib writeText runCommand remarshal; };
defaultBuildAttrs = {
inherit
jq
runCommand
lib
darwin
writeText
stdenv
rsync
remarshal
symlinkJoin
cargo
rustc
zstd
2019-11-21 09:34:16 +00:00
fetchurl
;
};
builtinz = builtins // import ./builtins
{ inherit lib writeText remarshal runCommand; };
2019-11-18 15:16:46 +00:00
in
# Crate building
2019-11-18 13:59:14 +00:00
let
2019-11-18 13:49:27 +00:00
mkConfig = arg:
import ./config.nix { inherit lib arg libb builtinz; };
2019-11-18 13:49:27 +00:00
buildPackage = arg:
let
config = mkConfig arg;
gitDependencies =
2019-12-17 16:03:10 +00:00
libb.findGitDependencies { inherit (config) cargotomls; };
in
import ./build.nix
(
defaultBuildAttrs // {
pname = config.packageName;
version = config.packageVersion;
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) src cargoTestCommands copyTarget copyBins copyDocsToSeparateOutput;
inherit gitDependencies;
} // config.buildConfig // {
builtDependencies = lib.optional (! config.isSingleStep)
2019-11-18 13:49:27 +00:00
(
import ./build.nix
(
{
inherit gitDependencies;
src = libb.dummySrc {
cargoconfig =
2019-11-21 09:35:00 +00:00
if builtinz.pathExists (toString config.root + "/.cargo/config")
then builtins.readFile (config.root + "/.cargo/config")
else null;
cargolock = config.cargolock;
cargotomls = config.cargotomls;
inherit (config) patchedSources;
};
} // (
defaultBuildAttrs // {
pname = "${config.packageName}-deps";
version = config.packageVersion;
} // config.buildConfig // {
preBuild = "";
# TODO: custom cargoTestCommands should not be needed here
cargoTestCommands = map (cmd: "${cmd} || true") config.cargoTestCommands;
copyTarget = true;
copyBins = false;
copyDocsToSeparateOutput = false;
builtDependencies = [];
}
)
)
);
}
);
in
{ inherit buildPackage; }