2020-04-18 13:43:58 +00:00
|
|
|
{ lib, stdenv
|
|
|
|
, fetchurl
|
|
|
|
, mrustc
|
|
|
|
, mrustc-minicargo
|
2023-04-06 09:26:26 +00:00
|
|
|
, llvm_12
|
|
|
|
, llvmPackages_12
|
2020-04-18 13:43:58 +00:00
|
|
|
, libffi
|
|
|
|
, cmake
|
|
|
|
, python3
|
|
|
|
, zlib
|
|
|
|
, libxml2
|
|
|
|
, openssl
|
|
|
|
, pkg-config
|
|
|
|
, curl
|
|
|
|
, which
|
|
|
|
, time
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2023-04-06 09:26:26 +00:00
|
|
|
mrustcTargetVersion = "1.54";
|
|
|
|
rustcVersion = "1.54.0";
|
2020-04-18 13:43:58 +00:00
|
|
|
rustcSrc = fetchurl {
|
|
|
|
url = "https://static.rust-lang.org/dist/rustc-${rustcVersion}-src.tar.gz";
|
2023-04-06 09:26:26 +00:00
|
|
|
sha256 = "0xk9dhfff16caambmwij67zgshd8v9djw6ha0fnnanlv7rii31dc";
|
2020-04-18 13:43:58 +00:00
|
|
|
};
|
|
|
|
rustcDir = "rustc-${rustcVersion}-src";
|
2023-04-06 09:26:26 +00:00
|
|
|
outputDir = "output-${rustcVersion}";
|
2020-04-18 13:43:58 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "mrustc-bootstrap";
|
|
|
|
version = "${mrustc.version}_${rustcVersion}";
|
|
|
|
|
|
|
|
inherit (mrustc) src;
|
|
|
|
postUnpack = "tar -xf ${rustcSrc} -C source/";
|
|
|
|
|
|
|
|
# the rust build system complains that nix alters the checksums
|
|
|
|
dontFixLibtool = true;
|
|
|
|
|
|
|
|
patches = [
|
2023-04-06 09:26:26 +00:00
|
|
|
./patches/0001-dont-download-rustc.patch
|
2020-04-18 13:43:58 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
echo "applying patch ./rustc-${rustcVersion}-src.patch"
|
|
|
|
patch -p0 -d ${rustcDir}/ < rustc-${rustcVersion}-src.patch
|
|
|
|
'';
|
|
|
|
|
|
|
|
# rustc unfortunately needs cmake to compile llvm-rt but doesn't
|
|
|
|
# use it for the normal build. This disables cmake in Nix.
|
|
|
|
dontUseCmakeConfigure = true;
|
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
mrustc
|
|
|
|
mrustc-minicargo
|
|
|
|
pkg-config
|
|
|
|
python3
|
|
|
|
time
|
|
|
|
which
|
|
|
|
];
|
|
|
|
buildInputs = [
|
|
|
|
# for rustc
|
2023-04-06 09:26:26 +00:00
|
|
|
llvm_12 libffi zlib libxml2
|
2020-04-18 13:43:58 +00:00
|
|
|
# for cargo
|
2022-09-11 21:28:36 +00:00
|
|
|
openssl
|
|
|
|
(curl.override { inherit openssl; })
|
2020-04-18 13:43:58 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
makeFlags = [
|
|
|
|
# Use shared mrustc/minicargo/llvm instead of rebuilding them
|
|
|
|
"MRUSTC=${mrustc}/bin/mrustc"
|
2023-04-16 19:59:07 +00:00
|
|
|
#"MINICARGO=${mrustc-minicargo}/bin/minicargo" # FIXME: we need to rebuild minicargo locally so --manifest-overrides is applied
|
2023-04-06 09:26:26 +00:00
|
|
|
"LLVM_CONFIG=${llvm_12.dev}/bin/llvm-config"
|
lib.systems: elaborate Rust metadata
We need this stuff to be available in lib so make-derivation.nix can
access it to construct the Meson cross file.
This has a couple of other advantages:
- It makes Rust less special. Now figuring out what Rust calls a
platform is the same as figuring out what Linux or QEMU call it.
- We can unify the schema used to define Rust targets, and the schema
used to access those values later. Just like you can set "config"
or "system" in a platform definition, and then access those same
keys on the elaborated platform, you can now set "rustcTarget" in
your crossSystem, and then access "stdenv.hostPlatform.rustcTarget"
in your code.
"rustcTarget", "rustcTargetSpec", "cargoShortTarget", and
"cargoEnvVarTarget" have the "rustc" and "cargo" prefixes because
these are not exposed to code by the compiler, and are not
standardized. The arch/os/etc. variables are all named to match the
forms in the Rust target spec JSON.
The new rust.target-family only takes a list, since we don't need to
worry about backwards compatibility when that name is used.
The old APIs are all still functional with no warning for now, so that
it's possible for external code to use a single API on both 23.05 and
23.11. We can introduce the warnings once 23.05 is EOL, and make them
hard errors when 23.11 is EOL.
2023-05-09 13:38:32 +00:00
|
|
|
"RUSTC_TARGET=${stdenv.targetPlatform.rust.rustcTarget}"
|
2020-04-18 13:43:58 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
local flagsArray=(
|
|
|
|
PARLEVEL=$NIX_BUILD_CORES
|
|
|
|
${toString makeFlags}
|
|
|
|
)
|
|
|
|
|
2023-04-06 09:26:26 +00:00
|
|
|
touch ${rustcDir}/dl-version
|
|
|
|
export OUTDIR_SUF=-${rustcVersion}
|
|
|
|
export RUSTC_VERSION=${rustcVersion}
|
|
|
|
export MRUSTC_TARGET_VER=${mrustcTargetVersion}
|
2023-04-08 08:56:35 +00:00
|
|
|
export MRUSTC_PATH=${mrustc}/bin/mrustc
|
2023-04-06 09:26:26 +00:00
|
|
|
|
2020-04-18 13:43:58 +00:00
|
|
|
echo minicargo.mk: libs
|
|
|
|
make -f minicargo.mk "''${flagsArray[@]}" LIBS
|
|
|
|
|
2023-04-06 09:26:26 +00:00
|
|
|
echo test
|
|
|
|
make "''${flagsArray[@]}" test
|
|
|
|
|
|
|
|
# disabled because it expects ./bin/mrustc
|
|
|
|
#echo local_tests
|
|
|
|
#make "''${flagsArray[@]}" local_tests
|
2020-04-18 13:43:58 +00:00
|
|
|
|
|
|
|
echo minicargo.mk: rustc
|
2023-04-06 09:26:26 +00:00
|
|
|
make -f minicargo.mk "''${flagsArray[@]}" ${outputDir}/rustc
|
2020-04-18 13:43:58 +00:00
|
|
|
|
|
|
|
echo minicargo.mk: cargo
|
2023-04-06 09:26:26 +00:00
|
|
|
make -f minicargo.mk "''${flagsArray[@]}" ${outputDir}/cargo
|
2020-04-18 13:43:58 +00:00
|
|
|
|
|
|
|
echo run_rustc
|
|
|
|
make -C run_rustc "''${flagsArray[@]}"
|
|
|
|
|
|
|
|
unset flagsArray
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
checkPhase = ''
|
|
|
|
runHook preCheck
|
2023-04-06 09:26:26 +00:00
|
|
|
run_rustc/${outputDir}/prefix/bin/hello_world | grep "hello, world"
|
2020-04-18 13:43:58 +00:00
|
|
|
runHook postCheck
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out/bin/ $out/lib/
|
2023-04-06 09:26:26 +00:00
|
|
|
cp run_rustc/${outputDir}/prefix/bin/cargo $out/bin/cargo
|
|
|
|
cp run_rustc/${outputDir}/prefix/bin/rustc_binary $out/bin/rustc
|
2020-04-18 13:43:58 +00:00
|
|
|
|
2023-04-06 09:26:26 +00:00
|
|
|
cp -r run_rustc/${outputDir}/prefix/lib/* $out/lib/
|
lib.systems: elaborate Rust metadata
We need this stuff to be available in lib so make-derivation.nix can
access it to construct the Meson cross file.
This has a couple of other advantages:
- It makes Rust less special. Now figuring out what Rust calls a
platform is the same as figuring out what Linux or QEMU call it.
- We can unify the schema used to define Rust targets, and the schema
used to access those values later. Just like you can set "config"
or "system" in a platform definition, and then access those same
keys on the elaborated platform, you can now set "rustcTarget" in
your crossSystem, and then access "stdenv.hostPlatform.rustcTarget"
in your code.
"rustcTarget", "rustcTargetSpec", "cargoShortTarget", and
"cargoEnvVarTarget" have the "rustc" and "cargo" prefixes because
these are not exposed to code by the compiler, and are not
standardized. The arch/os/etc. variables are all named to match the
forms in the Rust target spec JSON.
The new rust.target-family only takes a list, since we don't need to
worry about backwards compatibility when that name is used.
The old APIs are all still functional with no warning for now, so that
it's possible for external code to use a single API on both 23.05 and
23.11. We can introduce the warnings once 23.05 is EOL, and make them
hard errors when 23.11 is EOL.
2023-05-09 13:38:32 +00:00
|
|
|
cp $out/lib/rustlib/${stdenv.targetPlatform.rust.rustcTarget}/lib/*.so $out/lib/
|
2020-04-18 13:43:58 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
inherit (src.meta) homepage;
|
|
|
|
description = "Minimal build of Rust";
|
|
|
|
longDescription = ''
|
|
|
|
A minimal build of Rust, built from source using mrustc.
|
|
|
|
This is useful for bootstrapping the main Rust compiler without
|
|
|
|
an initial binary toolchain download.
|
|
|
|
'';
|
|
|
|
maintainers = with maintainers; [ progval r-burns ];
|
|
|
|
license = with licenses; [ mit asl20 ];
|
|
|
|
platforms = [ "x86_64-linux" ];
|
|
|
|
};
|
|
|
|
}
|