mirror of
https://github.com/nix-community/naersk
synced 2024-11-10 06:04:17 +00:00
Clean up git dependency code
This commit is contained in:
parent
e994e8692f
commit
cfbaf2a6f2
7 changed files with 11 additions and 67 deletions
|
@ -62,7 +62,6 @@ it is converted to an attribute set equivalent to `{ root = theArg; }`.
|
|||
| `compressTarget` | When true, the build output of intermediary builds is compressed with [`Zstandard`](https://facebook.github.io/zstd/). This reduces the size of closures. Default: `true` |
|
||||
| `copyTarget` | When true, the `target/` directory is copied to `$out`. Default: `false` |
|
||||
| `usePureFromTOML` | Whether to use the `fromTOML` built-in or not. When set to `false` the python package `remarshal` is used instead (in a derivation) and the JSON output is read with `builtins.fromJSON`. This is a workaround for old versions of Nix. May be used safely from Nix 2.3 onwards where all bugs in `builtins.fromTOML` seem to have been fixed. Default: `true` |
|
||||
| `allowGitDependencies` | Prefetch git dependencies with `builtins.fetchGit` and add `[patch.*]` sections to the `Cargo.toml`. This also removes all references to git links in the `Cargo.lock`. **Highly experimental.** Default: `false` |
|
||||
|
||||
## Comparison
|
||||
|
||||
|
@ -77,11 +76,6 @@ For the same reason, `naersk` does not need anything like `rustPlatform`'s
|
|||
`cargoSha256`. All crates are downloaded using the `sha256` checksums provided
|
||||
in the project's `Cargo.lock`.
|
||||
|
||||
Because `cargo` doesn't register checksums for `git` dependencies, **`naersk`'s
|
||||
support for `git` dependencies is experimental** and has to be enabled with
|
||||
`allowGitDependencies = true` (see the [configuration
|
||||
section](#configuration)).
|
||||
|
||||
Finally `naersk` supports incremental builds by first performing a
|
||||
dependency-only build, and _then_ a build that depends on the top-level crate's
|
||||
code and configuration.
|
||||
|
|
|
@ -54,11 +54,6 @@ For the same reason, `naersk` does not need anything like `rustPlatform`'s
|
|||
`cargoSha256`. All crates are downloaded using the `sha256` checksums provided
|
||||
in the project's `Cargo.lock`.
|
||||
|
||||
Because `cargo` doesn't register checksums for `git` dependencies, **`naersk`'s
|
||||
support for `git` dependencies is experimental** and has to be enabled with
|
||||
`allowGitDependencies = true` (see the [configuration
|
||||
section](#configuration)).
|
||||
|
||||
Finally `naersk` supports incremental builds by first performing a
|
||||
dependency-only build, and _then_ a build that depends on the top-level crate's
|
||||
code and configuration.
|
||||
|
|
52
build.nix
52
build.nix
|
@ -58,17 +58,17 @@ let
|
|||
builtins // import ./builtins
|
||||
{ inherit lib writeText remarshal runCommand; };
|
||||
|
||||
foo = lib.concatLists (lib.mapAttrsToList (
|
||||
_: ds: ds) gitDependencies);
|
||||
# All the git dependencies, as a list
|
||||
gitDependenciesList =
|
||||
lib.concatLists (lib.mapAttrsToList (_: ds: ds) gitDependencies);
|
||||
|
||||
# TODO: explain what this is and document
|
||||
unpackedGitDependencies = runCommand "git-deps"
|
||||
{ nativeBuildInputs = [ jq ]; }
|
||||
''
|
||||
|
||||
mkdir -p $out
|
||||
|
||||
while read -r dep; do
|
||||
echo "Got git dep: $dep"
|
||||
checkout=$(echo "$dep" | jq -cMr '.checkout')
|
||||
url=$(echo "$dep" | jq -cMr '.url')
|
||||
tomls=$(find $checkout -name Cargo.toml)
|
||||
|
@ -86,15 +86,13 @@ let
|
|||
echo '{"package":null,"files":{}}' > $out/$name/.cargo-checksum.json
|
||||
fi
|
||||
done <<< "$tomls"
|
||||
done < <(cat ${builtins.toFile "git-deps-json" (builtins.toJSON foo)} | jq -cMr '.[]')
|
||||
done < <(cat ${
|
||||
builtins.toFile "git-deps-json" (builtins.toJSON gitDependenciesList)
|
||||
} | jq -cMr '.[]')
|
||||
'';
|
||||
|
||||
drv = stdenv.mkDerivation {
|
||||
name = "${pname}-${version}";
|
||||
gitDependencies = "";
|
||||
#if gitDependencies != {}
|
||||
#then writeText "gitdeps.json" (builtins.toJSON gitDependencies)
|
||||
#else "";
|
||||
inherit
|
||||
src
|
||||
doCheck
|
||||
|
@ -102,8 +100,7 @@ let
|
|||
preBuild
|
||||
;
|
||||
|
||||
|
||||
|
||||
# TODO: explain what this is
|
||||
cargoconfig = builtinz.toTOML {
|
||||
source = {
|
||||
crates-io = { replace-with = "nix-sources"; };
|
||||
|
@ -111,7 +108,7 @@ let
|
|||
directory = symlinkJoin {
|
||||
name = "crates-io";
|
||||
paths = map (v: unpackCrate v.name v.version v.sha256)
|
||||
crateDependencies ++ [ unpackedGitDependencies ] ;
|
||||
crateDependencies ++ [ unpackedGitDependencies ] ;
|
||||
};
|
||||
};
|
||||
} // lib.listToAttrs ( map
|
||||
|
@ -122,7 +119,7 @@ let
|
|||
replace-with = "nix-sources";
|
||||
};
|
||||
})
|
||||
foo
|
||||
gitDependenciesList
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -190,35 +187,6 @@ let
|
|||
# TODO: figure out why "1" works whereas "0" doesn't
|
||||
find . -type f -exec touch --date=@1 {} +
|
||||
|
||||
if [ -n "$gitDependencies" ]; then
|
||||
echo "Git dependencies were set, patching Cargo.toml(s)"
|
||||
while read -r json; do
|
||||
echo "Got json: $json"
|
||||
dir=$(echo "$json" | jq -cMr '.dir')
|
||||
checkout=$(echo "$json" | jq -cMr '.checkout')
|
||||
name=$(echo "$json" | jq -cMr '.name')
|
||||
url=$(echo "$json" | jq -cMr '.url')
|
||||
echo "Found json:"
|
||||
echo " dir: $dir"
|
||||
echo " checkout: $checkout"
|
||||
echo " name: $name"
|
||||
echo " url: $url"
|
||||
echo >> Cargo.toml
|
||||
echo "[patch.\"$url\"]" >> $dir/Cargo.toml
|
||||
echo "$name = { path = \"$checkout\" }" >> $dir/Cargo.toml
|
||||
|
||||
echo "Cargo toml updated"
|
||||
done < <(cat "$gitDependencies" | jq -cMr ' '' +
|
||||
# This turns { ".": [ { "rev": "deadbeef" } ] } into
|
||||
# [ { "dir": ".", "rev": "deadbeef" } ]
|
||||
''
|
||||
to_entries | .[] | .key as $dir | .value | map(.+{ dir: $dir }) | .[]
|
||||
')
|
||||
sed -ri '/^"checksum [^ ]+ [^ ]+ [(]git[+]https/d' Cargo.lock
|
||||
sed -ri '/^source = "git/d' Cargo.lock
|
||||
sed -ri 's/ [(]git[+]https[^)]*[)]//g' Cargo.lock
|
||||
fi
|
||||
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
||||
|
|
|
@ -58,11 +58,6 @@ let
|
|||
# Nix 2.3 onwards where all bugs in `builtins.fromTOML` seem to have been
|
||||
# fixed.
|
||||
usePureFromTOML = attrs0.usePureFromTOML or true;
|
||||
|
||||
# Prefetch git dependencies with `builtins.fetchGit` and add `[patch.*]`
|
||||
# sections to the `Cargo.toml`. This also removes all references to git
|
||||
# links in the `Cargo.lock`. **Highly experimental.**
|
||||
allowGitDependencies = attrs0.allowGitDependencies or false;
|
||||
};
|
||||
|
||||
argIsAttrs =
|
||||
|
@ -144,8 +139,6 @@ let
|
|||
# Whether we skip pre-building the deps
|
||||
isSingleStep = attrs.singleStep;
|
||||
|
||||
patchGitDeps = attrs.allowGitDependencies;
|
||||
|
||||
# The members we want to build
|
||||
# (list of directory names)
|
||||
wantedMembers =
|
||||
|
|
|
@ -46,9 +46,7 @@ let
|
|||
let
|
||||
config = mkConfig arg;
|
||||
gitDependencies =
|
||||
if config.patchGitDeps
|
||||
then libb.findGitDependencies { inherit (config) cargotomls; }
|
||||
else {};
|
||||
libb.findGitDependencies { inherit (config) cargotomls; };
|
||||
in
|
||||
import ./build.nix
|
||||
(
|
||||
|
|
3
lib.nix
3
lib.nix
|
@ -89,9 +89,6 @@ rec
|
|||
in
|
||||
lib.mapAttrs (_: tomlDependencies) cargotomls;
|
||||
|
||||
#findGitDependenciesList =
|
||||
#{ cargot
|
||||
|
||||
# A very minimal 'src' which makes cargo happy nonetheless
|
||||
dummySrc =
|
||||
{ cargoconfig # string
|
||||
|
|
1
test.nix
1
test.nix
|
@ -118,7 +118,6 @@ rec
|
|||
git-dep = naersk.buildPackage {
|
||||
root = ./test/git-dep;
|
||||
cargoOptions = [ "--locked" ];
|
||||
allowGitDependencies = true;
|
||||
};
|
||||
|
||||
workspace = naersk.buildPackage {
|
||||
|
|
Loading…
Reference in a new issue