2021-04-25 03:57:28 +00:00
|
|
|
{ lib, stdenv
|
|
|
|
, fetchurl
|
|
|
|
, mrustc
|
|
|
|
, mrustc-minicargo
|
2023-04-29 16:46:19 +00:00
|
|
|
, llvm_12
|
|
|
|
, llvmPackages_12
|
2021-04-25 03:57:28 +00:00
|
|
|
, libffi
|
|
|
|
, cmake
|
|
|
|
, python3
|
|
|
|
, zlib
|
|
|
|
, libxml2
|
|
|
|
, openssl
|
|
|
|
, pkg-config
|
|
|
|
, curl
|
|
|
|
, which
|
|
|
|
, time
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2023-04-29 16:46:19 +00:00
|
|
|
mrustcTargetVersion = "1.54";
|
|
|
|
rustcVersion = "1.54.0";
|
2021-04-25 03:57:28 +00:00
|
|
|
rustcSrc = fetchurl {
|
|
|
|
url = "https://static.rust-lang.org/dist/rustc-${rustcVersion}-src.tar.gz";
|
2023-04-29 16:46:19 +00:00
|
|
|
sha256 = "0xk9dhfff16caambmwij67zgshd8v9djw6ha0fnnanlv7rii31dc";
|
2021-04-25 03:57:28 +00:00
|
|
|
};
|
|
|
|
rustcDir = "rustc-${rustcVersion}-src";
|
2023-04-29 16:46:19 +00:00
|
|
|
outputDir = "output-${rustcVersion}";
|
2021-04-25 03:57:28 +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-29 16:46:19 +00:00
|
|
|
./patches/0001-dont-download-rustc.patch
|
2021-04-25 03:57:28 +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-29 16:46:19 +00:00
|
|
|
llvm_12 libffi zlib libxml2
|
2021-04-25 03:57:28 +00:00
|
|
|
# for cargo
|
2022-09-14 18:05:37 +00:00
|
|
|
openssl
|
|
|
|
(curl.override { inherit openssl; })
|
2021-04-25 03:57:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
makeFlags = [
|
|
|
|
# Use shared mrustc/minicargo/llvm instead of rebuilding them
|
|
|
|
"MRUSTC=${mrustc}/bin/mrustc"
|
2023-04-29 16:46:19 +00:00
|
|
|
#"MINICARGO=${mrustc-minicargo}/bin/minicargo" # FIXME: we need to rebuild minicargo locally so --manifest-overrides is applied
|
|
|
|
"LLVM_CONFIG=${llvm_12.dev}/bin/llvm-config"
|
2023-11-16 04:20:00 +00:00
|
|
|
"RUSTC_TARGET=${stdenv.targetPlatform.rust.rustcTarget}"
|
2021-04-25 03:57:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
local flagsArray=(
|
|
|
|
PARLEVEL=$NIX_BUILD_CORES
|
|
|
|
${toString makeFlags}
|
|
|
|
)
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
touch ${rustcDir}/dl-version
|
|
|
|
export OUTDIR_SUF=-${rustcVersion}
|
|
|
|
export RUSTC_VERSION=${rustcVersion}
|
|
|
|
export MRUSTC_TARGET_VER=${mrustcTargetVersion}
|
|
|
|
export MRUSTC_PATH=${mrustc}/bin/mrustc
|
|
|
|
|
2021-04-25 03:57:28 +00:00
|
|
|
echo minicargo.mk: libs
|
|
|
|
make -f minicargo.mk "''${flagsArray[@]}" LIBS
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
echo test
|
|
|
|
make "''${flagsArray[@]}" test
|
|
|
|
|
|
|
|
# disabled because it expects ./bin/mrustc
|
|
|
|
#echo local_tests
|
|
|
|
#make "''${flagsArray[@]}" local_tests
|
2021-04-25 03:57:28 +00:00
|
|
|
|
|
|
|
echo minicargo.mk: rustc
|
2023-04-29 16:46:19 +00:00
|
|
|
make -f minicargo.mk "''${flagsArray[@]}" ${outputDir}/rustc
|
2021-04-25 03:57:28 +00:00
|
|
|
|
|
|
|
echo minicargo.mk: cargo
|
2023-04-29 16:46:19 +00:00
|
|
|
make -f minicargo.mk "''${flagsArray[@]}" ${outputDir}/cargo
|
2021-04-25 03:57:28 +00:00
|
|
|
|
|
|
|
echo run_rustc
|
|
|
|
make -C run_rustc "''${flagsArray[@]}"
|
|
|
|
|
|
|
|
unset flagsArray
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
checkPhase = ''
|
|
|
|
runHook preCheck
|
2023-04-29 16:46:19 +00:00
|
|
|
run_rustc/${outputDir}/prefix/bin/hello_world | grep "hello, world"
|
2021-04-25 03:57:28 +00:00
|
|
|
runHook postCheck
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out/bin/ $out/lib/
|
2023-04-29 16:46:19 +00:00
|
|
|
cp run_rustc/${outputDir}/prefix/bin/cargo $out/bin/cargo
|
|
|
|
cp run_rustc/${outputDir}/prefix/bin/rustc_binary $out/bin/rustc
|
2021-04-25 03:57:28 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
cp -r run_rustc/${outputDir}/prefix/lib/* $out/lib/
|
2023-11-16 04:20:00 +00:00
|
|
|
cp $out/lib/rustlib/${stdenv.targetPlatform.rust.rustcTarget}/lib/*.so $out/lib/
|
2021-04-25 03:57:28 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
inherit (src.meta) homepage;
|
2024-06-20 14:57:18 +00:00
|
|
|
description = "Minimal build of Rust";
|
2021-04-25 03:57:28 +00:00
|
|
|
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" ];
|
|
|
|
};
|
|
|
|
}
|