mirror of
https://github.com/nix-community/naersk
synced 2025-02-17 03:38:24 +00:00
POC of incrementality
This commit is contained in:
parent
59642e1e3b
commit
0068d11d38
5 changed files with 212 additions and 26 deletions
61
build.nix
61
build.nix
|
@ -2,17 +2,18 @@ src:
|
|||
{ cargoBuild ? "cargo build --frozen --release -j $NIX_BUILD_CORES"
|
||||
, cargoTest ? "cargo test --release"
|
||||
, doCheck ? true
|
||||
, patchCrate ? (_: _: x: x)
|
||||
, name ? null
|
||||
, rustc ? rustPackages
|
||||
, cargo ? rustPackages
|
||||
, override ? null
|
||||
, buildInputs ? []
|
||||
, nativeBuildInputs ? []
|
||||
, builtDependencies ? []
|
||||
, rustPackages
|
||||
, stdenv
|
||||
, lib
|
||||
, llvmPackages
|
||||
, rsync
|
||||
, jq
|
||||
, darwin
|
||||
, writeText
|
||||
|
@ -21,12 +22,23 @@ src:
|
|||
}:
|
||||
|
||||
with
|
||||
{ libb = import ./lib.nix { inherit lib; }; };
|
||||
{ libb = import ./lib.nix { inherit lib; };
|
||||
readTOML = f: builtins.fromTOML (builtins.readFile f);
|
||||
};
|
||||
|
||||
with rec
|
||||
{
|
||||
drv = stdenv.mkDerivation
|
||||
{ inherit src doCheck nativeBuildInputs cratePaths;
|
||||
{ inherit src doCheck nativeBuildInputs;
|
||||
|
||||
# The list of paths to Cargo.tomls. If this is a workspace, the paths
|
||||
# are the members. Otherwise, there is a single path, ".".
|
||||
cratePaths =
|
||||
with rec
|
||||
{ workspaceMembers = cargotoml.workspace.members or null;
|
||||
};
|
||||
|
||||
if isNull workspaceMembers then "." else lib.concatStringsSep "\n" workspaceMembers;
|
||||
|
||||
# Otherwise specifying CMake as a dep breaks the build
|
||||
dontUseCmakeConfigure = true;
|
||||
|
@ -52,25 +64,31 @@ with rec
|
|||
|
||||
# needed for "cc"
|
||||
jq
|
||||
|
||||
rsync
|
||||
] ++ (stdenv.lib.optionals stdenv.isDarwin
|
||||
[ darwin.Security
|
||||
darwin.apple_sdk.frameworks.CoreServices
|
||||
darwin.cf-private
|
||||
]) ++ buildInputs;
|
||||
|
||||
LIBCLANG_PATH="${llvmPackages.libclang.lib}/lib";
|
||||
CXX="clang++";
|
||||
RUSTC="${rustc}/bin/rustc";
|
||||
|
||||
crateNames = lib.concatStringsSep "\n" crateNames;
|
||||
|
||||
configurePhase =
|
||||
''
|
||||
runHook preConfigure
|
||||
cat ${writeText "deps" (builtins.toJSON dependencies)} |\
|
||||
|
||||
mkdir -p target
|
||||
|
||||
cat ${writeText "deps" (builtins.toJSON builtDependencies)} |\
|
||||
jq -r '.[]' |\
|
||||
while IFS= read -r dep
|
||||
do
|
||||
echo dep $dep
|
||||
echo pre-installing dep $dep
|
||||
rsync -rl --executability $dep/target/ target
|
||||
chmod +w -R target
|
||||
done
|
||||
|
||||
export CARGO_HOME=''${CARGO_HOME:-$PWD/.cargo-home}
|
||||
|
@ -78,7 +96,8 @@ with rec
|
|||
|
||||
cp --no-preserve mode ${cargoconfig} $CARGO_HOME/config
|
||||
|
||||
export CARGO_TARGET_DIR="$out/target"
|
||||
# TODO: figure out why "1" works whereas "0" doesn't
|
||||
find . -type f -exec touch --date=@1 {} +
|
||||
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
@ -119,16 +138,16 @@ with rec
|
|||
mkdir -p $out/lib
|
||||
|
||||
# TODO: .../debug if debug
|
||||
cp -vr $CARGO_TARGET_DIR/release/deps/* $out/lib ||\
|
||||
cp -vr target/release/deps/* $out/lib ||\
|
||||
echo "WARNING: couldn't copy libs"
|
||||
|
||||
mkdir -p $out
|
||||
cp -r target $out
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
|
||||
# List of built crates this crate depends on
|
||||
dependencies = [];
|
||||
|
||||
# XXX: the actual crate format is not documented but in practice is a
|
||||
# gzipped tar; we simply unpack it and introduce a ".cargo-checksum.json"
|
||||
# file that cargo itself uses to double check the sha256
|
||||
|
@ -152,28 +171,18 @@ with rec
|
|||
# pretty fast so this is not too bad. In the future we'll want to pre-build
|
||||
# the crates and give cargo a pre-populated ./target directory.
|
||||
# TODO: this should most likely take more than one packageName
|
||||
mkSnapshotForest = patchCrate: packageName: cargolock:
|
||||
mkSnapshotForest = packageName: cargolock:
|
||||
symlinkJoin
|
||||
{ name = "crates-io";
|
||||
paths =
|
||||
map
|
||||
(v: patchCrate v.name v (unpackCrate v.name v.version v.sha256))
|
||||
(libb.mkVersions packageName cargolock);
|
||||
paths = map (v: unpackCrate v.name v.version v.sha256)
|
||||
(libb.mkVersions packageName cargolock);
|
||||
};
|
||||
|
||||
readTOML = f: builtins.fromTOML (builtins.readFile f);
|
||||
cargolock = readTOML "${src}/Cargo.lock";
|
||||
|
||||
# The top-level Cargo.toml
|
||||
cargotoml = readTOML "${src}/Cargo.toml";
|
||||
|
||||
cratePaths =
|
||||
with rec
|
||||
{ workspaceMembers = cargotoml.workspace.members or null;
|
||||
};
|
||||
|
||||
if isNull workspaceMembers then "." else lib.concatStringsSep "\n" workspaceMembers;
|
||||
|
||||
# All the Cargo.tomls, including the top-level one
|
||||
cargotomls =
|
||||
with rec
|
||||
|
@ -194,7 +203,7 @@ with rec
|
|||
replace-with = 'nix-sources'
|
||||
|
||||
[source.nix-sources]
|
||||
directory = '${mkSnapshotForest patchCrate (lib.head crateNames) cargolock}'
|
||||
directory = '${mkSnapshotForest (lib.head crateNames) cargolock}'
|
||||
'';
|
||||
};
|
||||
if isNull override then drv else drv.overrideAttrs override
|
||||
|
|
26
default.nix
26
default.nix
|
@ -16,6 +16,7 @@ with rec
|
|||
, writeText ? _pkgs.writeText
|
||||
, llvmPackages ? _pkgs.llvmPackages
|
||||
, jq ? _pkgs.jq
|
||||
, rsync ? _pkgs.rsync
|
||||
, darwin ? _pkgs.darwin
|
||||
, rustPackages ?
|
||||
with sources;
|
||||
|
@ -40,6 +41,7 @@ with rec
|
|||
darwin
|
||||
writeText
|
||||
stdenv
|
||||
rsync
|
||||
symlinkJoin ;
|
||||
} ;
|
||||
};
|
||||
|
@ -59,6 +61,30 @@ with
|
|||
ripgrep-all = buildPackage sources.ripgrep-all {};
|
||||
|
||||
rustfmt = buildPackage sources.rustfmt {};
|
||||
|
||||
simple-dep =
|
||||
with rec
|
||||
{ rand = buildPackage ./test/simple-dep
|
||||
{ cargoBuild = "cargo build --release --frozen -p rand -j $NIX_BUILD_CORES";
|
||||
doCheck = false;
|
||||
#override = _oldAttrs:
|
||||
#{ installPhase = "echo no install"; };
|
||||
};
|
||||
|
||||
};
|
||||
buildPackage ./test/simple-dep
|
||||
{ builtDependencies = [ rand ];
|
||||
cargoBuild = "cargo build --release --frozen -j $NIX_BUILD_CORES";
|
||||
#override = _oldAttrs:
|
||||
#{ preBuild =
|
||||
#''
|
||||
#echo $PWD
|
||||
#sleep infinity
|
||||
|
||||
|
||||
#'';
|
||||
#};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
|
140
test/simple-dep/Cargo.lock
generated
Normal file
140
test/simple-dep/Cargo.lock
generated
Normal file
|
@ -0,0 +1,140 @@
|
|||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "c2-chacha"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cloudabi"
|
||||
version = "0.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-cprng"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.7.0-pre.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"getrandom 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_chacha 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"getrandom 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simple-dep"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand 0.7.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf"
|
||||
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
|
||||
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
"checksum getrandom 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8d1dffef07351aafe6ef177e4dd2b8dcf503e6bc765dea3b0de9ed149a3db1ec"
|
||||
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
|
||||
"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319"
|
||||
"checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b"
|
||||
"checksum rand 0.7.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)" = "866531c9bb6613da04a1e6ad99d27a7c8acd488020d7a8b177b058a10c900eec"
|
||||
"checksum rand_chacha 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e193067942ef6f485a349a113329140d0ab9e2168ce92274499bb0e9a4190d9d"
|
||||
"checksum rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "615e683324e75af5d43d8f7a39ffe3ee4a9dc42c5c701167a71dc59c3a493aca"
|
||||
"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
|
||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
8
test/simple-dep/Cargo.toml
Normal file
8
test/simple-dep/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "simple-dep"
|
||||
version = "0.1.0"
|
||||
authors = ["nicolas <nicolas@nmattia.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.7.0-pre.1"
|
3
test/simple-dep/src/main.rs
Normal file
3
test/simple-dep/src/main.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Loading…
Add table
Reference in a new issue