about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/mrustc
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-04-28 14:39:00 +0000
committerAlyssa Ross <hi@alyssa.is>2021-06-10 08:52:36 +0000
commit693e64ef7421374338ddb1dc12b9573feec75972 (patch)
tree2526ac075d248699c35d63e04499890ee4381f5f /nixpkgs/pkgs/development/compilers/mrustc
parent7014df2256694d97093d6f2bb1db340d346dea88 (diff)
parent8e4fe32876ca15e3d5eb3ecd3ca0b224417f5f17 (diff)
downloadnixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.gz
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.bz2
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.lz
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.xz
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.tar.zst
nixlib-693e64ef7421374338ddb1dc12b9573feec75972.zip
Merge commit '8e4fe32876ca15e3d5eb3ecd3ca0b224417f5f17'
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/mrustc')
-rw-r--r--nixpkgs/pkgs/development/compilers/mrustc/bootstrap.nix153
-rw-r--r--nixpkgs/pkgs/development/compilers/mrustc/default.nix53
-rw-r--r--nixpkgs/pkgs/development/compilers/mrustc/minicargo.nix39
-rw-r--r--nixpkgs/pkgs/development/compilers/mrustc/patches/0001-use-shared-llvm.patch12
-rw-r--r--nixpkgs/pkgs/development/compilers/mrustc/patches/0002-dont-build-llvm.patch14
-rw-r--r--nixpkgs/pkgs/development/compilers/mrustc/patches/0003-echo-newlines.patch13
-rw-r--r--nixpkgs/pkgs/development/compilers/mrustc/patches/0004-increase-parallelism.patch28
7 files changed, 312 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/compilers/mrustc/bootstrap.nix b/nixpkgs/pkgs/development/compilers/mrustc/bootstrap.nix
new file mode 100644
index 000000000000..35e7daaf2103
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/mrustc/bootstrap.nix
@@ -0,0 +1,153 @@
+{ lib, stdenv
+, fetchurl
+, mrustc
+, mrustc-minicargo
+, rust
+, llvm_7
+, llvmPackages_7
+, libffi
+, cmake
+, python3
+, zlib
+, libxml2
+, openssl
+, pkg-config
+, curl
+, which
+, time
+}:
+
+let
+  rustcVersion = "1.29.0";
+  rustcSrc = fetchurl {
+    url = "https://static.rust-lang.org/dist/rustc-${rustcVersion}-src.tar.gz";
+    sha256 = "1sb15znckj8pc8q3g7cq03pijnida6cg64yqmgiayxkzskzk9sx4";
+  };
+  rustcDir = "rustc-${rustcVersion}-src";
+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 = [
+    ./patches/0001-use-shared-llvm.patch
+    ./patches/0002-dont-build-llvm.patch
+    ./patches/0003-echo-newlines.patch
+    ./patches/0004-increase-parallelism.patch
+  ];
+
+  postPatch = ''
+    echo "applying patch ./rustc-${rustcVersion}-src.patch"
+    patch -p0 -d ${rustcDir}/ < rustc-${rustcVersion}-src.patch
+
+    for p in ${lib.concatStringsSep " " llvmPackages_7.compiler-rt.patches}; do
+      echo "applying patch $p"
+      patch -p1 -d ${rustcDir}/src/libcompiler_builtins/compiler-rt < $p
+    done
+  '';
+
+  # 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
+    llvm_7 libffi zlib libxml2
+    # for cargo
+    openssl curl
+  ];
+
+  makeFlags = [
+    # Use shared mrustc/minicargo/llvm instead of rebuilding them
+    "MRUSTC=${mrustc}/bin/mrustc"
+    "MINICARGO=${mrustc-minicargo}/bin/minicargo"
+    "LLVM_CONFIG=${llvm_7}/bin/llvm-config"
+    "RUSTC_TARGET=${rust.toRustTarget stdenv.targetPlatform}"
+  ];
+
+  buildPhase = ''
+    runHook preBuild
+
+    local flagsArray=(
+      PARLEVEL=$NIX_BUILD_CORES
+      ${toString makeFlags}
+    )
+
+    echo minicargo.mk: libs
+    make -f minicargo.mk "''${flagsArray[@]}" LIBS
+
+    echo minicargo.mk: deps
+    mkdir -p output/cargo-build
+    # minicargo has concurrency issues when running these; let's build them
+    # without parallelism
+    for crate in regex regex-0.2.11 curl-sys
+    do
+      echo "building $crate"
+      minicargo ${rustcDir}/src/vendor/$crate \
+        --vendor-dir ${rustcDir}/src/vendor \
+        --output-dir output/cargo-build -L output/
+    done
+
+    echo minicargo.mk: rustc
+    make -f minicargo.mk "''${flagsArray[@]}" output/rustc
+
+    echo minicargo.mk: cargo
+    make -f minicargo.mk "''${flagsArray[@]}" output/cargo
+
+    echo run_rustc
+    make -C run_rustc "''${flagsArray[@]}"
+
+    unset flagsArray
+
+    runHook postBuild
+  '';
+
+  doCheck = true;
+  checkPhase = ''
+    runHook preCheck
+    run_rustc/output/prefix/bin/hello_world | grep "hello, world"
+    runHook postCheck
+  '';
+
+  installPhase = ''
+    runHook preInstall
+    mkdir -p $out/bin/ $out/lib/
+    cp run_rustc/output/prefix/bin/cargo $out/bin/cargo
+    cp run_rustc/output/prefix/bin/rustc_binary $out/bin/rustc
+
+    cp -r run_rustc/output/prefix/lib/* $out/lib/
+    cp $out/lib/rustlib/${rust.toRustTarget stdenv.targetPlatform}/lib/*.so $out/lib/
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    inherit (src.meta) homepage;
+    description = "A 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" ];
+  };
+}
+
diff --git a/nixpkgs/pkgs/development/compilers/mrustc/default.nix b/nixpkgs/pkgs/development/compilers/mrustc/default.nix
new file mode 100644
index 000000000000..4c813d88b765
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/mrustc/default.nix
@@ -0,0 +1,53 @@
+{ lib, stdenv
+, fetchFromGitHub
+, zlib
+}:
+
+let
+  version = "0.9";
+  tag = "v${version}";
+  rev = "15773561e40ca5c8cffe0a618c544b6cfdc5ad7e";
+in
+
+stdenv.mkDerivation rec {
+  pname = "mrustc";
+  inherit version;
+
+  # Always update minicargo.nix and bootstrap.nix in lockstep with this
+  src = fetchFromGitHub {
+    owner = "thepowersgang";
+    repo = "mrustc";
+    rev = tag;
+    sha256 = "194ny7vsks5ygiw7d8yxjmp1qwigd71ilchis6xjl6bb2sj97rd2";
+  };
+
+  postPatch = ''
+    sed -i 's/\$(shell git show --pretty=%H -s)/${rev}/' Makefile
+    sed -i 's/\$(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match)/${tag}/' Makefile
+    sed -i 's/\$(shell git diff-index --quiet HEAD; echo $$?)/0/' Makefile
+  '';
+
+  strictDeps = true;
+  buildInputs = [ zlib ];
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    runHook preInstall
+    mkdir -p $out/bin
+    cp bin/mrustc $out/bin
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    description = "Mutabah's Rust Compiler";
+    longDescription = ''
+      In-progress alternative rust compiler, written in C++.
+      Capable of building a fully-working copy of rustc,
+      but not yet suitable for everyday use.
+    '';
+    inherit (src.meta) homepage;
+    license = licenses.mit;
+    maintainers = with maintainers; [ progval r-burns ];
+    platforms = [ "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/development/compilers/mrustc/minicargo.nix b/nixpkgs/pkgs/development/compilers/mrustc/minicargo.nix
new file mode 100644
index 000000000000..8505e5b8d7cf
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/mrustc/minicargo.nix
@@ -0,0 +1,39 @@
+{ lib, stdenv
+, makeWrapper
+, mrustc
+}:
+
+stdenv.mkDerivation rec {
+  pname = "mrustc-minicargo";
+  inherit (mrustc) src version;
+
+  strictDeps = true;
+  nativeBuildInputs = [ makeWrapper ];
+
+  enableParallelBuilding = true;
+  makefile = "minicargo.mk";
+  makeFlags = [ "tools/bin/minicargo" ];
+
+  installPhase = ''
+    runHook preInstall
+    mkdir -p $out/bin
+    cp tools/bin/minicargo $out/bin
+
+    # without it, minicargo defaults to "<minicargo_path>/../../bin/mrustc"
+    wrapProgram "$out/bin/minicargo" --set MRUSTC_PATH ${mrustc}/bin/mrustc
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    description = "A minimalist builder for Rust";
+    longDescription = ''
+      A minimalist builder for Rust, similar to Cargo but written in C++.
+      Designed to work with mrustc to build Rust projects
+      (like the Rust compiler itself).
+    '';
+    inherit (src.meta) homepage;
+    license = licenses.mit;
+    maintainers = with maintainers; [ progval r-burns ];
+    platforms = [ "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/development/compilers/mrustc/patches/0001-use-shared-llvm.patch b/nixpkgs/pkgs/development/compilers/mrustc/patches/0001-use-shared-llvm.patch
new file mode 100644
index 000000000000..e8c57ae25410
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/mrustc/patches/0001-use-shared-llvm.patch
@@ -0,0 +1,12 @@
+--- a/rustc-1.29.0-src/src/librustc_llvm/lib.rs
+--- b/rustc-1.29.0-src/src/librustc_llvm/lib.rs
+@@ -23,6 +23,9 @@
+ #![feature(link_args)]
+ #![feature(static_nobundle)]
+ 
++// https://github.com/rust-lang/rust/issues/34486
++#[link(name = "ffi")] extern {}
++
+ // See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
+ #[allow(unused_extern_crates)]
+ extern crate rustc_cratesio_shim;
diff --git a/nixpkgs/pkgs/development/compilers/mrustc/patches/0002-dont-build-llvm.patch b/nixpkgs/pkgs/development/compilers/mrustc/patches/0002-dont-build-llvm.patch
new file mode 100644
index 000000000000..7ae8d191d87c
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/mrustc/patches/0002-dont-build-llvm.patch
@@ -0,0 +1,14 @@
+--- a/minicargo.mk
++++ b/minicargo.mk
+@@ -116,11 +116,6 @@
+ LLVM_CMAKE_OPTS += CMAKE_BUILD_TYPE=RelWithDebInfo
+ 
+ 
+-$(LLVM_CONFIG): $(RUSTCSRC)build/Makefile
+-	$Vcd $(RUSTCSRC)build && $(MAKE)
+-$(RUSTCSRC)build/Makefile: $(RUSTCSRC)src/llvm/CMakeLists.txt
+-	@mkdir -p $(RUSTCSRC)build
+-	$Vcd $(RUSTCSRC)build && cmake $(addprefix -D , $(LLVM_CMAKE_OPTS)) ../src/llvm
+ 
+ 
+ #
diff --git a/nixpkgs/pkgs/development/compilers/mrustc/patches/0003-echo-newlines.patch b/nixpkgs/pkgs/development/compilers/mrustc/patches/0003-echo-newlines.patch
new file mode 100644
index 000000000000..f4a4acca8578
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/mrustc/patches/0003-echo-newlines.patch
@@ -0,0 +1,13 @@
+--- a/run_rustc/Makefile
++++ b/run_rustc/Makefile
+@@ -103,7 +103,9 @@
+ else
+ 	cp $(OUTDIR)build-rustc/release/rustc_binary $(BINDIR)rustc_binary
+ endif
+-	echo '#!/bin/sh\nd=$$(dirname $$0)\nLD_LIBRARY_PATH="$(abspath $(LIBDIR))" $$d/rustc_binary $$@' >$@
++	echo '#!$(shell which bash)' > $@
++	echo 'd=$$(dirname $$0)' >> $@
++	echo 'LD_LIBRARY_PATH="$(abspath $(LIBDIR))" $$d/rustc_binary $$@' >> $@
+ 	chmod +x $@
+ 
+ $(BINDIR)hello_world: $(RUST_SRC)test/run-pass/hello.rs $(LIBDIR)libstd.rlib $(BINDIR)rustc
diff --git a/nixpkgs/pkgs/development/compilers/mrustc/patches/0004-increase-parallelism.patch b/nixpkgs/pkgs/development/compilers/mrustc/patches/0004-increase-parallelism.patch
new file mode 100644
index 000000000000..ce1fec572627
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/mrustc/patches/0004-increase-parallelism.patch
@@ -0,0 +1,28 @@
+--- a/run_rustc/Makefile
++++ b/run_rustc/Makefile
+@@ -79,14 +79,14 @@
+ 	@mkdir -p $(OUTDIR)build-std
+ 	@mkdir -p $(LIBDIR)
+ 	@echo [CARGO] $(RUST_SRC)libstd/Cargo.toml
+-	$VCARGO_TARGET_DIR=$(OUTDIR)build-std RUSTC=$(BINDIR_S)rustc $(CARGO_ENV) $(BINDIR)cargo build --manifest-path $(RUST_SRC)libstd/Cargo.toml  -j 1 --release --features panic-unwind
++	$VCARGO_TARGET_DIR=$(OUTDIR)build-std RUSTC=$(BINDIR_S)rustc $(CARGO_ENV) $(BINDIR)cargo build --manifest-path $(RUST_SRC)libstd/Cargo.toml  -j $(NIX_BUILD_CORES) --release --features panic-unwind
+ 	$Vcp --remove-destination $(OUTDIR)build-std/release/deps/*.rlib $(LIBDIR)
+ 	$Vcp --remove-destination $(OUTDIR)build-std/release/deps/*.so $(LIBDIR)
+ # libtest
+ $(LIBDIR)libtest.rlib: $(BINDIR)rustc_m $(LIBDIR)libstd.rlib $(CARGO_HOME)config
+ 	@mkdir -p $(OUTDIR)build-test
+ 	@echo [CARGO] $(RUST_SRC)libtest/Cargo.toml
+-	$VCARGO_TARGET_DIR=$(OUTDIR)build-test RUSTC=$(BINDIR)rustc_m $(CARGO_ENV) $(BINDIR)cargo build --manifest-path $(RUST_SRC)libtest/Cargo.toml  -j 1 --release
++	$VCARGO_TARGET_DIR=$(OUTDIR)build-test RUSTC=$(BINDIR)rustc_m $(CARGO_ENV) $(BINDIR)cargo build --manifest-path $(RUST_SRC)libtest/Cargo.toml  -j $(NIX_BUILD_CORES) --release
+ 	@mkdir -p $(LIBDIR)
+ 	$Vcp --remove-destination $(OUTDIR)build-test/release/deps/*.rlib $(LIBDIR)
+ 	$Vcp --remove-destination $(OUTDIR)build-test/release/deps/*.so $(LIBDIR)
+@@ -95,7 +95,7 @@
+ $(BINDIR)rustc: $(BINDIR)rustc_m $(BINDIR)cargo $(CARGO_HOME)config $(LIBDIR)libtest.rlib
+ 	@mkdir -p $(PREFIX)tmp
+ 	@echo [CARGO] $(RUST_SRC)rustc/Cargo.toml
+-	$V$(RUSTC_ENV_VARS) TMPDIR=$(abspath $(PREFIX)tmp) CARGO_TARGET_DIR=$(OUTDIR)build-rustc RUSTC=$(BINDIR)rustc_m RUSTC_ERROR_METADATA_DST=$(abspath $(PREFIX)) $(CARGO_ENV) $(BINDIR)cargo build --manifest-path $(RUST_SRC)rustc/Cargo.toml --release -j 1
++	$V$(RUSTC_ENV_VARS) TMPDIR=$(abspath $(PREFIX)tmp) CARGO_TARGET_DIR=$(OUTDIR)build-rustc RUSTC=$(BINDIR)rustc_m RUSTC_ERROR_METADATA_DST=$(abspath $(PREFIX)) $(CARGO_ENV) $(BINDIR)cargo build --manifest-path $(RUST_SRC)rustc/Cargo.toml --release -j $(NIX_BUILD_CORES)
+ 	cp $(OUTDIR)build-rustc/release/deps/*.so $(LIBDIR)
+ 	cp $(OUTDIR)build-rustc/release/deps/*.rlib $(LIBDIR)
+ ifeq ($(RUSTC_VERSION),1.19.0)