Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: build with system llvm and jemalloc #49557

Merged
merged 2 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/development/compilers/rust/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ in rec {
./patches/disable-test-inherit-env.patch
];

forceBundledLLVM = true;
withBundledLLVM = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LnL7 @dtzWill anyone who does remember why we switched away from this option? I thing this option was true at some point.

Copy link
Member

@Mic92 Mic92 Nov 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It broke the tests back then 7bd191d
It could be still ok though:

Since you deal with rust backports sometimes for firefox what would you prefer @andir ?
I guess in the worst case it should be still possible to just re-enable the bundled version in backported version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really have no strong opinion here. I would certainly like to avoid a situation where we have to port LLVM whenever we have to back port rustc for Thunderbird/Firefox.

How much is the speedup of compilation time? If it is significant I could see this being a good thing in general.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiling rustc with the bundled llvm takes about 1h05 for llvm and 55 min for rustc. So this halves compilation time.
Note that fedora disables codegen tests when using the bundled llvm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment we do not run tests anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is everything from their llvm fork upstream now? That was the main reason for this IIRC.

Copy link
Member

@Mic92 Mic92 Nov 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They only seem to merge pull requests from changes that have been before in llvm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I tried to split this out into 2 separate derivations at some point but not rebuilding llvm is even better.


configureFlags = [ "--release-channel=stable" ];

Expand Down
57 changes: 26 additions & 31 deletions pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ stdenv, targetPackages
{ stdenv, targetPackages, removeReferencesTo
, fetchurl, fetchgit, fetchzip, file, python2, tzdata, ps
, llvm, jemalloc, ncurses, darwin, rustPlatform, git, cmake, curl
, which, libffi, gdb
, version
, forceBundledLLVM ? false
, withBundledLLVM ? false
, src
, configureFlags ? []
, patches
Expand All @@ -20,6 +20,8 @@ let

llvmShared = llvm.override { enableSharedLibraries = true; };

prefixedJemalloc = jemalloc.override { stripPrefix = false; };

target = builtins.replaceStrings [" "] [","] (builtins.toString targets);
in

Expand All @@ -40,7 +42,11 @@ stdenv.mkDerivation {
# See https://github.com/NixOS/nixpkgs/pull/34227
stripDebugList = if stdenv.isDarwin then [ "bin" ] else null;

NIX_LDFLAGS = optionalString stdenv.isDarwin "-rpath ${llvmShared}/lib";
NIX_LDFLAGS =
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch'
optional (stdenv.isLinux && !withBundledLLVM) "--push-state --as-needed -lstdc++ --pop-state"
++ optional (stdenv.isDarwin && !withBundledLLVM) "-lc++"
++ optional stdenv.isDarwin "-rpath ${llvmShared}/lib";

# Enable nightly features in stable compiles (used for
# bootstrapping, see https://github.com/rust-lang/rust/pull/37265).
Expand All @@ -54,13 +60,12 @@ stdenv.mkDerivation {
# We need rust to build rust. If we don't provide it, configure will try to download it.
# Reference: https://github.com/rust-lang/rust/blob/master/src/bootstrap/configure.py
configureFlags = configureFlags
++ [ "--enable-local-rust" "--local-rust-root=${rustPlatform.rust.rustc}" "--enable-rpath" ]
++ [ "--enable-vendor" ]
# ++ [ "--jemalloc-root=${jemalloc}/lib"
++ [ "--default-linker=${targetPackages.stdenv.cc}/bin/cc" ]
++ optional (!forceBundledLLVM) [ "--enable-llvm-link-shared" ]
++ optional (targets != []) "--target=${target}"
++ optional (!forceBundledLLVM) "--llvm-root=${llvmShared}";
++ [ "--enable-local-rust" "--local-rust-root=${rustPlatform.rust.rustc}" "--enable-rpath"
"--enable-vendor"
"--jemalloc-root=${prefixedJemalloc}/lib"
"--default-linker=${targetPackages.stdenv.cc}/bin/cc" ]
++ optional (!withBundledLLVM) [ "--enable-llvm-link-shared" "--llvm-root=${llvmShared}" ]
++ optional (targets != []) "--target=${target}";

# The bootstrap.py will generated a Makefile that then executes the build.
# The BOOTSTRAP_ARGS used by this Makefile must include all flags to pass
Expand All @@ -79,29 +84,13 @@ stdenv.mkDerivation {
postPatch = ''
patchShebangs src/etc

# Fix dynamic linking against llvm
#${optionalString (!forceBundledLLVM) ''sed -i 's/, kind = \\"static\\"//g' src/etc/mklldeps.py''}
${optionalString (!withBundledLLVM) ''rm -rf src/llvm''}
rm -rf src/jemalloc

# Fix the configure script to not require curl as we won't use it
sed -i configure \
-e '/probe_need CFG_CURL curl/d'

# Fix the use of jemalloc prefixes which our jemalloc doesn't have
# TODO: reenable if we can figure out how to get our jemalloc to work
#[ -f src/liballoc_jemalloc/lib.rs ] && sed -i 's,je_,,g' src/liballoc_jemalloc/lib.rs
#[ -f src/liballoc/heap.rs ] && sed -i 's,je_,,g' src/liballoc/heap.rs # Remove for 1.4.0+

# Disable fragile tests.
rm -vr src/test/run-make-fulldeps/linker-output-non-utf8 || true
rm -vr src/test/run-make-fulldeps/issue-26092 || true

# Remove test targeted at LLVM 3.9 - https://github.com/rust-lang/rust/issues/36835
rm -vr src/test/ui/run-pass/issue-36023.rs || true

# Disable test getting stuck on hydra - possible fix:
# https://reviews.llvm.org/rL281650
rm -vr src/test/ui/run-pass/issue-36474.rs || true

# On Hydra: `TcpListener::bind(&addr)`: Address already in use (os error 98)'
sed '/^ *fn fast_rebind()/i#[ignore]' -i src/libstd/net/tcp.rs

Expand Down Expand Up @@ -137,14 +126,14 @@ stdenv.mkDerivation {
# ps is needed for one of the test cases
nativeBuildInputs =
[ file python2 ps rustPlatform.rust.rustc git cmake
which libffi
which libffi removeReferencesTo
]
# Only needed for the debuginfo tests
++ optional (!stdenv.isDarwin) gdb;

buildInputs = [ ncurses ] ++ targetToolchains
buildInputs = targetToolchains
++ optional stdenv.isDarwin Security
++ optional (!forceBundledLLVM) llvmShared;
++ optional (!withBundledLLVM) llvmShared;

outputs = [ "out" "man" "doc" ];
setOutputFlags = false;
Expand All @@ -165,6 +154,12 @@ stdenv.mkDerivation {

inherit doCheck;

# remove references to llvm-config in lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_codegen_llvm-llvm.so
# and thus a transitive dependency on ncurses
postInstall = ''
find $out/lib -name "*.so" -type f -exec remove-references-to -t ${llvmShared} '{}' '+'
'';

configurePlatforms = [];

# https://github.com/NixOS/nixpkgs/pull/21742#issuecomment-272305764
Expand Down
19 changes: 12 additions & 7 deletions pkgs/development/libraries/jemalloc/common.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{ stdenv, fetchurl, version, sha256, ... }@args:
{ version, sha256 }:
{ stdenv, fetchurl,
# By default, jemalloc puts a je_ prefix onto all its symbols on OSX, which
# then stops downstream builds (mariadb in particular) from detecting it. This
# option should remove the prefix and give us a working jemalloc.
# Causes segfaults with some software (ex. rustc), but defaults to true for backward
# compatibility. Ignored on non OSX.
stripPrefix ? true }:

stdenv.mkDerivation (rec {
stdenv.mkDerivation rec {
name = "jemalloc-${version}";
inherit version;

Expand All @@ -9,10 +16,8 @@ stdenv.mkDerivation (rec {
inherit sha256;
};

# By default, jemalloc puts a je_ prefix onto all its symbols on OSX, which
# then stops downstream builds (mariadb in particular) from detecting it. This
# option should remove the prefix and give us a working jemalloc.
configureFlags = stdenv.lib.optional stdenv.isDarwin "--with-jemalloc-prefix=";
# see the comment on stripPrefix
configureFlags = stdenv.lib.optional (stdenv.isDarwin && stripPrefix) "--with-jemalloc-prefix=";
doCheck = true;

enableParallelBuilding = true;
Expand All @@ -28,4 +33,4 @@ stdenv.mkDerivation (rec {
platforms = platforms.all;
maintainers = with maintainers; [ wkennington ];
};
} // (builtins.removeAttrs args [ "stdenv" "fetchurl" "version" "sha256" ]))
}
2 changes: 0 additions & 2 deletions pkgs/development/libraries/jemalloc/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{ stdenv, fetchurl, fetchpatch }:
import ./common.nix {
inherit stdenv fetchurl;
version = "5.1.0";
sha256 = "0s3jpcyhzia8d4k0xyc67is78kg416p9yc3c2f9w6fhhqqffd5jk";
}
4 changes: 1 addition & 3 deletions pkgs/development/libraries/jemalloc/jemalloc450.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{ stdenv, fetchurl }:
import ./common.nix {
inherit stdenv fetchurl;
version = "4.5.0";
sha256 = "10373xhpc10pgmai9fkc1z0rs029qlcb3c0qfnvkbwdlcibdh2cl";
}
}
1 change: 1 addition & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7324,6 +7324,7 @@ with pkgs;
# For beta and nightly releases use the nixpkgs-mozilla overlay
rust = callPackage ../development/compilers/rust ({
inherit (darwin.apple_sdk.frameworks) CoreFoundation Security;
llvm = llvm_7;
} // stdenv.lib.optionalAttrs (stdenv.cc.isGNU && stdenv.hostPlatform.isi686) {
stdenv = overrideCC stdenv gcc6; # with gcc-7: undefined reference to `__divmoddi4'
});
Expand Down