stylistic changes

these are not mandated by nixpkgs-fmt
This commit is contained in:
zimbatm 2019-11-19 20:10:53 +00:00
parent d11a8a036c
commit 9a72012540
No known key found for this signature in database
GPG key ID: 71BAF6D40C1D63D7
6 changed files with 203 additions and 227 deletions

260
build.nix
View file

@ -55,183 +55,169 @@ let
builtins // import ./builtins
{ inherit lib writeText remarshal runCommand; };
drv = stdenv.mkDerivation (
{
name = "${pname}-${version}";
inherit
src
doCheck
version
preBuild
;
drv = stdenv.mkDerivation {
name = "${pname}-${version}";
inherit
src
doCheck
version
preBuild
;
cargoconfig = builtinz.toTOML
{
source =
{
crates-io = { replace-with = "nix-sources"; };
nix-sources =
{
directory = symlinkJoin
{
name = "crates-io";
paths = map (v: unpackCrate v.name v.version v.sha256)
crateDependencies;
};
};
};
cargoconfig = builtinz.toTOML {
source = {
crates-io = { replace-with = "nix-sources"; };
nix-sources = {
directory = symlinkJoin {
name = "crates-io";
paths = map (v: unpackCrate v.name v.version v.sha256)
crateDependencies;
};
};
};
};
outputs = [ "out" ] ++ lib.optional (doDoc && copyDocsToSeparateOutput) "doc";
preInstallPhases = lib.optional doDoc [ "docPhase" ];
outputs = [ "out" ] ++ lib.optional (doDoc && copyDocsToSeparateOutput) "doc";
preInstallPhases = lib.optional doDoc [ "docPhase" ];
# Otherwise specifying CMake as a dep breaks the build
dontUseCmakeConfigure = true;
# Otherwise specifying CMake as a dep breaks the build
dontUseCmakeConfigure = true;
nativeBuildInputs =
[
cargo
# needed at various steps in the build
jq
rsync
];
nativeBuildInputs = [
cargo
# needed at various steps in the build
jq
rsync
];
buildInputs =
stdenv.lib.optionals stdenv.isDarwin
[
darwin.Security
darwin.apple_sdk.frameworks.CoreServices
darwin.cf-private
] ++ buildInputs;
buildInputs = stdenv.lib.optionals stdenv.isDarwin [
darwin.Security
darwin.apple_sdk.frameworks.CoreServices
darwin.cf-private
] ++ buildInputs;
# iff not in a shell
inherit builtDependencies;
# iff not in a shell
inherit builtDependencies;
RUSTC = "${rustc}/bin/rustc";
RUSTC = "${rustc}/bin/rustc";
configurePhase =
''
cargo_release=( ${lib.optionalString release "--release" } )
configurePhase = ''
cargo_release=( ${lib.optionalString release "--release" } )
runHook preConfigure
runHook preConfigure
logRun() {
echo "$@"
eval "$@"
}
logRun() {
echo "$@"
eval "$@"
}
mkdir -p target
mkdir -p target
for dep in $builtDependencies; do
echo pre-installing dep $dep
if [ -d "$dep/target" ]; then
rsync -rl \
--no-perms \
--no-owner \
--no-group \
--chmod=+w \
--executability $dep/target/ target
fi
if [ -f "$dep/target.tar.zst" ]; then
${zstd}/bin/zstd -d "$dep/target.tar.zst" --stdout | tar -x
fi
for dep in $builtDependencies; do
echo pre-installing dep $dep
if [ -d "$dep/target" ]; then
rsync -rl \
--no-perms \
--no-owner \
--no-group \
--chmod=+w \
--executability $dep/target/ target
fi
if [ -f "$dep/target.tar.zst" ]; then
${zstd}/bin/zstd -d "$dep/target.tar.zst" --stdout | tar -x
fi
if [ -d "$dep/target" ]; then
chmod +w -R target
fi
done
if [ -d "$dep/target" ]; then
chmod +w -R target
fi
done
export CARGO_HOME=''${CARGO_HOME:-$PWD/.cargo-home}
mkdir -p $CARGO_HOME
export CARGO_HOME=''${CARGO_HOME:-$PWD/.cargo-home}
mkdir -p $CARGO_HOME
echo "$cargoconfig" > $CARGO_HOME/config
echo "$cargoconfig" > $CARGO_HOME/config
# TODO: figure out why "1" works whereas "0" doesn't
find . -type f -exec touch --date=@1 {} +
# TODO: figure out why "1" works whereas "0" doesn't
find . -type f -exec touch --date=@1 {} +
runHook postConfigure
'';
runHook postConfigure
'';
buildPhase =
''
runHook preBuild
buildPhase = ''
runHook preBuild
logRun ${cargoBuild}
logRun ${cargoBuild}
runHook postBuild
'';
runHook postBuild
'';
checkPhase =
''
runHook preCheck
checkPhase = ''
runHook preCheck
${lib.concatMapStringsSep "\n" (cmd: "logRun ${cmd}") cargoTestCommands}
${lib.concatMapStringsSep "\n" (cmd: "logRun ${cmd}") cargoTestCommands}
runHook postCheck
'';
runHook postCheck
'';
docPhase = lib.optionalString doDoc ''
runHook preDoc
docPhase = lib.optionalString doDoc ''
runHook preDoc
logRun cargo doc --offline "''${cargo_release[*]}" || ${if doDocFail then "false" else "true" }
logRun cargo doc --offline "''${cargo_release[*]}" || ${if doDocFail then "false" else "true" }
${lib.optionalString removeReferencesToSrcFromDocs ''
# Remove references to the source derivation to reduce closure size
match='<meta name="description" content="Source to the Rust file `${builtins.storeDir}[^`]*`.">'
replacement='<meta name="description" content="Source to the Rust file removed to reduce Nix closure size.">'
find target/doc -name "*\.rs\.html" -exec sed -i "s|$match|$replacement|" {} +
${lib.optionalString removeReferencesToSrcFromDocs ''
# Remove references to the source derivation to reduce closure size
match='<meta name="description" content="Source to the Rust file `${builtins.storeDir}[^`]*`.">'
replacement='<meta name="description" content="Source to the Rust file removed to reduce Nix closure size.">'
find target/doc -name "*\.rs\.html" -exec sed -i "s|$match|$replacement|" {} +
''}
runHook postDoc
'';
installPhase =
''
runHook preInstall
${lib.optionalString copyBins ''
if [ -d out ]; then
mkdir -p $out/bin
find out -type f -executable -exec cp {} $out/bin \;
fi
''}
runHook postDoc
'';
installPhase =
${lib.optionalString copyTarget ''
mkdir -p $out
${if compressTarget then
''
runHook preInstall
${lib.optionalString copyBins ''
if [ -d out ]; then
mkdir -p $out/bin
find out -type f -executable -exec cp {} $out/bin \;
fi
tar -c target | ${zstd}/bin/zstd -o $out/target.tar.zst
'' else
''
cp -r target $out
''}
''}
${lib.optionalString copyTarget ''
mkdir -p $out
${if compressTarget then
''
tar -c target | ${zstd}/bin/zstd -o $out/target.tar.zst
'' else
''
cp -r target $out
''}
''}
${lib.optionalString (doDoc && copyDocsToSeparateOutput) ''
cp -r target/doc $doc
''}
${lib.optionalString (doDoc && copyDocsToSeparateOutput) ''
cp -r target/doc $doc
''}
runHook postInstall
'';
passthru = {
# Handy for debugging
inherit builtDependencies;
};
}
)
;
runHook postInstall
'';
passthru = {
# Handy for debugging
inherit builtDependencies;
};
};
# 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
unpackCrate = name: version: sha256:
let
crate = builtins.fetchurl
{
url = "https://crates.io/api/v1/crates/${name}/${version}/download";
inherit sha256;
};
crate = builtins.fetchurl {
url = "https://crates.io/api/v1/crates/${name}/${version}/download";
inherit sha256;
};
in
runCommand "unpack-${name}-${version}" {}
''

View file

@ -33,8 +33,7 @@ rec
)
);
writeJSON = name: attrs: writeText name
(builtins.toJSON attrs);
writeJSON = name: attrs: writeText name (builtins.toJSON attrs);
# Returns `true` if `path` exists.
# TODO: use `builtins.pathExists` once

View file

@ -10,6 +10,7 @@ let
concatMapStringsSep
mapAttrsToList
;
inherit (builtins)
abort
match
@ -52,11 +53,11 @@ let
vals = map quoteString v;
valsStr = concatStringsSep ", " vals;
in
"[ ${valsStr} ]" else
"[ ${valsStr} ]"
else
if ty == "set" then
abort "unsupported set for not-inner value"
else abort "Not implemented: type ${ty}"
;
else abort "Not implemented: type ${ty}";
outputKeyValInner = k: v:
let
@ -96,8 +97,7 @@ let
[ "${quoteKey k} = [ ${valsStr} ]" ] else
if ty == "set" then
[ "[${k}]" ] ++ (concatLists (mapAttrsToList outputKeyValInner v))
else abort "Not implemented: type ${ty} for key ${k}"
;
else abort "Not implemented: type ${ty} for key ${k}";
tomlTy = x:
if typeOf x == "string" then "string" else

View file

@ -13,34 +13,32 @@ let
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;
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;
release = attrs.release or true;
override = attrs.override or (x: x);
override = attrs.override or (x: x);
cargoBuild = attrs.cargoBuild or ''
cargo build "''${cargo_release}" -j $NIX_BUILD_CORES -Z unstable-options --out-dir out
'';
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;
};
# 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
{
buildPlanConfig = rec {
inherit (attrs) src;
# Whether we skip pre-building the deps
isSingleStep = attrs.singleStep or false;
@ -70,7 +68,6 @@ let
let
readTOML = builtinz.readTOML usePureFromTOML;
in
{ "." = toplevelCargotoml; } // lib.optionalAttrs isWorkspace
(
lib.listToAttrs
@ -128,7 +125,6 @@ let
copyBins = attrs.copyBins or true;
copyDocsToSeparateOutput = attrs.copyDocsToSeparateOutput or true;
};
in
buildPlanConfig // { inherit buildConfig; }

View file

@ -14,34 +14,35 @@
let
libb = import ./lib.nix { inherit lib writeText runCommand remarshal; };
defaultBuildAttrs =
{
inherit
jq
runCommand
lib
darwin
writeText
stdenv
rsync
remarshal
symlinkJoin
cargo
rustc
zstd
;
};
builtinz =
builtins // import ./builtins
{ inherit lib writeText remarshal runCommand; };
defaultBuildAttrs = {
inherit
jq
runCommand
lib
darwin
writeText
stdenv
rsync
remarshal
symlinkJoin
cargo
rustc
zstd
;
};
builtinz = builtins // import ./builtins
{ inherit lib writeText remarshal runCommand; };
in
# Crate building
let
mkConfig = arg:
import ./config.nix { inherit lib arg libb builtinz; };
buildPackage = arg:
let
config = (mkConfig arg);
config = mkConfig arg;
in
import ./build.nix
(
@ -61,19 +62,15 @@ let
import ./build.nix
(
{
src =
(
libb.dummySrc
{
cargoconfig =
if builtinz.pathExists (toString config.src + "/.cargo/config")
then builtins.readFile (config.src + "/.cargo/config")
else null;
cargolock = config.cargolock;
cargotomls = config.cargotomls;
inherit (config) patchedSources;
}
);
src = libb.dummySrc {
cargoconfig =
if builtinz.pathExists (toString config.src + "/.cargo/config")
then builtins.readFile (config.src + "/.cargo/config")
else null;
cargolock = config.cargolock;
cargotomls = config.cargotomls;
inherit (config) patchedSources;
};
} // (
defaultBuildAttrs // {
pname = "${config.packageName}-deps";

View file

@ -27,26 +27,24 @@ rec
{ buildInputs = [ ripgrep-all ]; }
"rga --help && touch $out";
lorri = naersk.buildPackage
{
src = sources.lorri;
override = _oldAttrs:
{
BUILD_REV_COUNT = 1;
RUN_TIME_CLOSURE = "${sources.lorri}/nix/runtime.nix";
};
doCheck = false;
lorri = naersk.buildPackage {
src = sources.lorri;
override = _oldAttrs: {
BUILD_REV_COUNT = 1;
RUN_TIME_CLOSURE = "${sources.lorri}/nix/runtime.nix";
};
doCheck = false;
};
lorri_test = pkgs.runCommand "lorri-test" { buildInputs = [ lorri ]; }
"lorri --help && touch $out";
talent-plan-1 = naersk.buildPackage "${sources.talent-plan}/rust/projects/project-1";
talent-plan-2 = naersk.buildPackage "${sources.talent-plan}/rust/projects/project-2";
talent-plan-3 = naersk.buildPackage
{
src = "${sources.talent-plan}/rust/projects/project-3";
doCheck = false;
};
talent-plan-3 = naersk.buildPackage {
src = "${sources.talent-plan}/rust/projects/project-3";
doCheck = false;
};
# TODO: support for git deps
#test_talent-plan-4 = buildPackage "${sources.talent-plan}/rust/projects/project-4" {};
@ -83,20 +81,20 @@ rec
simple-dep-patched = naersk.buildPackage ./test/simple-dep-patched;
dummyfication = naersk.buildPackage ./test/dummyfication;
dummyfication_test = pkgs.runCommand "dummyfication-test" { buildInputs = [ dummyfication ]; }
dummyfication_test = pkgs.runCommand
"dummyfication-test"
{ buildInputs = [ dummyfication ]; }
"my-bin > $out";
workspace = naersk.buildPackage
{
src = pkgs.lib.cleanSource ./test/workspace;
doDoc = false;
};
workspace = naersk.buildPackage {
src = pkgs.lib.cleanSource ./test/workspace;
doDoc = false;
};
workspace-patched = naersk.buildPackage
{
src = pkgs.lib.cleanSource ./test/workspace-patched;
doDoc = false;
};
workspace-patched = naersk.buildPackage {
src = pkgs.lib.cleanSource ./test/workspace-patched;
doDoc = false;
};
# Fails with some remarshal error
#servo = naersk.buildPackage