Split out aggregation derivation and refactor

Fix #59
main
oxalica 3 years ago
parent f5a5eddda1
commit 1fd2dc01ee
No known key found for this signature in database
GPG Key ID: CED392DE0C483D00
  1. 55
      mk-aggregated.nix
  2. 25
      mk-component-set.nix
  3. 39
      rust-overlay.nix

@ -0,0 +1,55 @@
{ lib, stdenv, symlinkJoin, pkgsTargetTarget, bash, gcc }:
{ pname, version, components }:
let
inherit (lib) optional optionalString;
in
symlinkJoin {
name = pname + "-" + version;
inherit pname version;
paths = components;
# Ourselves have offset -1. In order to make these offset -1 dependencies of downstream derivation,
# they are offset 0 propagated.
# CC for build script linking.
# Workaround: should be `pkgsHostHost.cc` but `stdenv`'s cc itself have -1 offset.
depsHostHostPropagated = [ stdenv.cc ];
# CC for crate linking.
# Workaround: should be `pkgsHostTarget.cc` but `stdenv`'s cc itself have -1 offset.
propagatedBuildInputs = [ pkgsTargetTarget.stdenv.cc ];
# Link dependency for target, required by darwin std.
depsTargetTargetPropagated =
optional (stdenv.targetPlatform.isDarwin) [ pkgsTargetTarget.libiconv ];
postBuild = ''
# If rustc or rustdoc is in the derivation, we need to copy their
# executable into the final derivation. This is required
# for making them find the correct SYSROOT.
for target in $out/bin/{rustc,rustdoc,miri,cargo-miri}; do
if [ -e $target ]; then
cp --remove-destination "$(realpath -e $target)" $target
fi
done
if [ -e $out/bin/cargo-miri ]; then
mv $out/bin/{cargo-miri,.cargo-miri-wrapped}
cp -f ${./cargo-miri-wrapper.sh} $out/bin/cargo-miri
chmod +w $out/bin/cargo-miri
substituteInPlace $out/bin/cargo-miri \
--replace "@bash@" "${bash}/bin/bash" \
--replace "@cargo_miri@" "$out/bin/.cargo-miri-wrapped" \
--replace "@out@" "$out"
fi
# symlinkJoin doesn't automatically handle it. Thus do it manually.
mkdir $out/nix-support
echo "$depsHostHostPropagated " >$out/nix-support/propagated-host-host-deps
echo "$propagatedBuildInputs " >$out/nix-support/propagated-build-inputs
'' + optionalString (stdenv.targetPlatform.isDarwin) ''
echo "$depsTargetTargetPropagated " >$out/nix-support/propagated-target-target-deps
'';
meta.platforms = lib.platforms.all;
}

@ -1,5 +1,5 @@
# Define component derivations and special treatments.
{ lib, stdenv, buildPackages, gnutar, gcc, zlib, libiconv, autoPatchelfHook
{ lib, stdenv, gnutar, autoPatchelfHook, zlib
, toRustTarget, removeNulls
}:
# Release version of the whole set.
@ -16,7 +16,7 @@ let
inherit (stdenv) hostPlatform targetPlatform;
mkComponent = pname: src:
stdenv.mkDerivation {
stdenv.mkDerivation rec {
inherit pname version src;
name = "${pname}-${version}-${platform}";
@ -26,18 +26,11 @@ let
# entire unpacked contents after just a little twiddling.
preferLocalBuild = true;
nativeBuildInputs = [ gnutar autoPatchelfHook ];
buildInputs = [ zlib ] ++
# These components link to `librustc_driver-*.so`.
optional (elem pname [ "clippy-preview" "rls-preview" "miri-preview" ]) [ self.rustc ];
# Ourselves have offset -1. In order to make these offset -1 dependencies of downstream derivation,
# they are offset 0 propagated.
propagatedBuildInputs =
optional (pname == "rustc") [ stdenv.cc buildPackages.stdenv.cc ];
# This goes downstream packages' buildInputs.
depsTargetTargetPropagated =
optional (pname == "rustc" && targetPlatform.isDarwin) libiconv;
nativeBuildInputs = [ gnutar ] ++ optional (!dontFixup) autoPatchelfHook;
buildInputs =
optional (elem pname [ "rustc" "cargo" ]) zlib ++
# These components link to `librustc_driver*.so` or `libLLVM*.so`.
optional (elem pname [ "clippy-preview" "rls-preview" "miri-preview" "rustc-dev" ]) self.rustc;
dontConfigure = true;
dontBuild = true;
@ -71,8 +64,8 @@ let
fi
'';
# `rust-docs` only contains tons of html files. Don't waste time scanning files.
dontFixup = pname == "rust-docs";
# Only contain tons of html files. Don't waste time scanning files.
dontFixup = elem pname [ "rust-docs" "rustc-docs" ];
dontStrip = true;
};

@ -1,4 +1,4 @@
# Define component resolution, component aggregation and utility functions.
# Define component resolution and utility functions.
self: super:
let
@ -31,6 +31,8 @@ let
inherit toRustTarget removeNulls;
};
mkAggregated = self.callPackage ./mk-aggregated.nix {};
# Manifest selector.
selectManifest = { channel, date ? null }: let
inherit (self.rust-bin) manifests;
@ -127,37 +129,6 @@ let
in
self.fetchurl { inherit name sha256; url = url'; };
aggregateComponents = { pname, version, components }:
self.symlinkJoin {
name = pname + "-" + version;
inherit pname version;
paths = components;
postBuild = ''
# If rustc or rustdoc is in the derivation, we need to copy their
# executable into the final derivation. This is required
# for making them find the correct SYSROOT.
for target in $out/bin/{rustc,rustdoc,miri,cargo-miri}; do
if [ -e $target ]; then
cp --remove-destination "$(realpath -e $target)" $target
fi
done
if [ -e $out/bin/cargo-miri ]; then
mv $out/bin/{cargo-miri,.cargo-miri-wrapped}
cp -f ${./cargo-miri-wrapper.sh} $out/bin/cargo-miri
chmod +w $out/bin/cargo-miri
substituteInPlace $out/bin/cargo-miri \
--replace "@bash@" "${self.bash}/bin/bash" \
--replace "@cargo_miri@" "$out/bin/.cargo-miri-wrapped" \
--replace "@out@" "$out"
fi
'';
meta.platforms = self.lib.platforms.all;
};
# Resolve final components to install from mozilla-overlay style `extensions`, `targets` and `targetExtensions`.
#
# `componentSet` has a layout of `componentSet.<name>.<rust-target> : Derivation`.
@ -321,7 +292,7 @@ let
mkProfile = name: profileComponents:
makeOverridable ({ extensions, targets, targetExtensions }:
aggregateComponents {
mkAggregated {
pname = "rust-${name}";
version = manifest.version;
components = resolveComponents {
@ -410,7 +381,7 @@ let
srcs = mapAttrs hashToSrc components;
};
in
aggregateComponents {
mkAggregated {
inherit pname version;
components = attrValues components';
};

Loading…
Cancel
Save