diff options
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/rust')
17 files changed, 881 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/compilers/rust/1_45.nix b/nixpkgs/pkgs/development/compilers/rust/1_45.nix new file mode 100644 index 000000000000..b4d887f2e964 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/1_45.nix @@ -0,0 +1,53 @@ +# New rust versions should first go to staging. +# Things to check after updating: +# 1. Rustc should produce rust binaries on x86_64-linux, aarch64-linux and x86_64-darwin: +# i.e. nix-shell -p fd or @GrahamcOfBorg build fd on github +# This testing can be also done by other volunteers as part of the pull +# request review, in case platforms cannot be covered. +# 2. The LLVM version used for building should match with rust upstream. +# 3. Firefox and Thunderbird should still build on x86_64-linux. + +{ stdenv, lib +, buildPackages +, newScope, callPackage +, CoreFoundation, Security +, pkgsBuildTarget, pkgsBuildBuild, pkgsBuildHost +, makeRustPlatform +, llvmPackages_5, llvm_10 +} @ args: + +import ./default.nix { + rustcVersion = "1.45.2"; + rustcSha256 = "0273a1g3f59plyi1n0azf21qjzwml1yqdnj5z472crz37qggr8xp"; + + llvmSharedForBuild = pkgsBuildBuild.llvm_10.override { enableSharedLibraries = true; }; + llvmSharedForHost = pkgsBuildHost.llvm_10.override { enableSharedLibraries = true; }; + llvmSharedForTarget = pkgsBuildTarget.llvm_10.override { enableSharedLibraries = true; }; + + llvmBootstrapForDarwin = llvmPackages_5; + + # For use at runtime + llvmShared = llvm_10.override { enableSharedLibraries = true; }; + + # Note: the version MUST be one version prior to the version we're + # building + bootstrapVersion = "1.44.1"; + + # fetch hashes by running `print-hashes.sh 1.45.0` + bootstrapHashes = { + i686-unknown-linux-gnu = "e69689b0a1b66599cf83e7dd54f839419007e44376195e93e301a3175da3d854"; + x86_64-unknown-linux-gnu = "a41df89a461a580536aeb42755e43037556fba2e527dd13a1e1bb0749de28202"; + arm-unknown-linux-gnueabihf = "ea18ccdfb62a153c2d43d013fdec56993cc9267f1cdc6f3834df8a2b9b468f08"; + armv7-unknown-linux-gnueabihf = "d44294732cf268ea84908f1135f574ab9489132a332eaa9d5bda547374b15d54"; + aarch64-unknown-linux-gnu = "a2d74ebeec0b6778026b6c37814cdc91d14db3b0d8b6d69d036216f4d9cf7e49"; + x86_64-apple-darwin = "a5464e7bcbce9647607904a4afa8362382f1fc55d39e7bbaf4483ac00eb5d56a"; + powerpc64le-unknown-linux-gnu = "22deeca259459db31065af7c862fcab7fbfb623200520c65002ed2ba93d87ad2"; + }; + + selectRustPackage = pkgs: pkgs.rust_1_45; + + rustcPatches = [ + ]; +} + +(builtins.removeAttrs args [ "fetchpatch" "pkgsBuildHost" "llvmPackages_5" "llvm_10" ]) diff --git a/nixpkgs/pkgs/development/compilers/rust/1_46.nix b/nixpkgs/pkgs/development/compilers/rust/1_46.nix new file mode 100644 index 000000000000..c999b346ee6f --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/1_46.nix @@ -0,0 +1,45 @@ +# New rust versions should first go to staging. +# Things to check after updating: +# 1. Rustc should produce rust binaries on x86_64-linux, aarch64-linux and x86_64-darwin: +# i.e. nix-shell -p fd or @GrahamcOfBorg build fd on github +# This testing can be also done by other volunteers as part of the pull +# request review, in case platforms cannot be covered. +# 2. The LLVM version used for building should match with rust upstream. +# Check the version number in the src/llvm-project git submodule in: +# https://github.com/rust-lang/rust/blob/<version-tag>/.gitmodules +# 3. Firefox and Thunderbird should still build on x86_64-linux. + +{ stdenv, lib +, buildPackages +, newScope, callPackage +, CoreFoundation, Security +, llvmPackages +, pkgsBuildTarget, pkgsBuildBuild +, makeRustPlatform +} @ args: + +import ./default.nix { + rustcVersion = "1.46.0"; + rustcSha256 = "0a17jby2pd050s24cy4dfc0gzvgcl585v3vvyfilniyvjrqknsid"; + + # Note: the version MUST be one version prior to the version we're + # building + bootstrapVersion = "1.45.2"; + + # fetch hashes by running `print-hashes.sh 1.45.2` + bootstrapHashes = { + i686-unknown-linux-gnu = "5b2050dde23152750de89f7e59acaab6bf088d0beb5854c69c9a545fd254b936"; + x86_64-unknown-linux-gnu = "860feed955726a4d96ffe40758a110053326b9ae11c9e1ee059e9c6222f25643"; + arm-unknown-linux-gnueabihf = "ddb5f59bbdef84e0b7c83049461e003ed031dd881a4622365c3d475102535c60"; + armv7-unknown-linux-gnueabihf = "7a556581f87602705f9c89b04cce621cfbba9050b6fbe478166e91d164567531"; + aarch64-unknown-linux-gnu = "151fad66442d28a4e4786753d1afb559c4a3d359081c64769273a31c2f0f4d30"; + x86_64-apple-darwin = "6e8067624ede10aa23081d62e0086c6f42f7228cc0d00fb5ff24d4dac65249d6"; + }; + + selectRustPackage = pkgs: pkgs.rust_1_46; + + rustcPatches = [ + ]; +} + +(builtins.removeAttrs args [ "fetchpatch" ]) diff --git a/nixpkgs/pkgs/development/compilers/rust/1_47.nix b/nixpkgs/pkgs/development/compilers/rust/1_47.nix new file mode 100644 index 000000000000..e5cbae193bf1 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/1_47.nix @@ -0,0 +1,45 @@ +# New rust versions should first go to staging. +# Things to check after updating: +# 1. Rustc should produce rust binaries on x86_64-linux, aarch64-linux and x86_64-darwin: +# i.e. nix-shell -p fd or @GrahamcOfBorg build fd on github +# This testing can be also done by other volunteers as part of the pull +# request review, in case platforms cannot be covered. +# 2. The LLVM version used for building should match with rust upstream. +# Check the version number in the src/llvm-project git submodule in: +# https://github.com/rust-lang/rust/blob/<version-tag>/.gitmodules +# 3. Firefox and Thunderbird should still build on x86_64-linux. + +{ stdenv, lib +, buildPackages +, newScope, callPackage +, CoreFoundation, Security +, llvmPackages +, pkgsBuildTarget, pkgsBuildBuild +, makeRustPlatform +} @ args: + +import ./default.nix { + rustcVersion = "1.47.0"; + rustcSha256 = "sha256-MYXfBkxHR/LIubuMRGjt1Y/0rW0HiAyHmsGxc7do2B0="; + + # Note: the version MUST be one version prior to the version we're + # building + bootstrapVersion = "1.46.0"; + + # fetch hashes by running `print-hashes.sh 1.45.2` + bootstrapHashes = { + i686-unknown-linux-gnu = "6ebd7e04dc18a36d08b9731cdb42d5caf8460e1eb41b75f3a8596c39f5e71206"; + x86_64-unknown-linux-gnu = "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5"; + arm-unknown-linux-gnueabihf = "bb8af68565321f54608e918597083eb016ed0f9f4f3cc23f7cc5f467b934ce7f"; + armv7-unknown-linux-gnueabihf = "7c0640879d7f2c38db60352e3c0f09e3fc6fa3bac6ca8f22cbccb1eb5e950121"; + aarch64-unknown-linux-gnu = "f0c6d630f3dedb3db69d69ed9f833aa6b472363096f5164f1068c7001ca42aeb"; + x86_64-apple-darwin = "82d61582a3772932432a99789c3b3bd4abe6baca339e355048ca9efb9ea5b4db"; + }; + + selectRustPackage = pkgs: pkgs.rust_1_47; + + rustcPatches = [ + ]; +} + +(builtins.removeAttrs args [ "fetchpatch" ]) diff --git a/nixpkgs/pkgs/development/compilers/rust/1_48.nix b/nixpkgs/pkgs/development/compilers/rust/1_48.nix new file mode 100644 index 000000000000..6b4b10f12d3e --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/1_48.nix @@ -0,0 +1,55 @@ +# New rust versions should first go to staging. +# Things to check after updating: +# 1. Rustc should produce rust binaries on x86_64-linux, aarch64-linux and x86_64-darwin: +# i.e. nix-shell -p fd or @GrahamcOfBorg build fd on github +# This testing can be also done by other volunteers as part of the pull +# request review, in case platforms cannot be covered. +# 2. The LLVM version used for building should match with rust upstream. +# Check the version number in the src/llvm-project git submodule in: +# https://github.com/rust-lang/rust/blob/<version-tag>/.gitmodules +# 3. Firefox and Thunderbird should still build on x86_64-linux. + +{ stdenv, lib +, buildPackages +, newScope, callPackage +, CoreFoundation, Security +, pkgsBuildTarget, pkgsBuildBuild, pkgsBuildHost +, makeRustPlatform +, llvmPackages_5, llvm_11 +} @ args: + +import ./default.nix { + rustcVersion = "1.48.0"; + rustcSha256 = "0fz4gbb5hp5qalrl9lcl8yw4kk7ai7wx511jb28nypbxninkwxhf"; + + llvmSharedForBuild = pkgsBuildBuild.llvm_11.override { enableSharedLibraries = true; }; + llvmSharedForHost = pkgsBuildHost.llvm_11.override { enableSharedLibraries = true; }; + llvmSharedForTarget = pkgsBuildTarget.llvm_11.override { enableSharedLibraries = true; }; + + llvmBootstrapForDarwin = llvmPackages_5; + + # For use at runtime + llvmShared = llvm_11.override { enableSharedLibraries = true; }; + + # Note: the version MUST be one version prior to the version we're + # building + bootstrapVersion = "1.47.0"; + + # fetch hashes by running `print-hashes.sh 1.45.2` + bootstrapHashes = { + i686-unknown-linux-gnu = "84bf092130ea5216fc701871e633563fc1c01b6528f60cb0767e96cd8eec30bf"; + x86_64-unknown-linux-gnu = "d0e11e1756a072e8e246b05d54593402813d047d12e44df281fbabda91035d96"; + arm-unknown-linux-gnueabihf = "82e12affb47596b68d0ca64045f4eb698c10ff15406afca604e12cdd07e17b26"; + armv7-unknown-linux-gnueabihf = "19d0fe3892a8e98f99c5aa84f4d6f260853147650cb71f2bae985c91de6c29af"; + aarch64-unknown-linux-gnu = "753c905e89a714ab9bce6fe1397b721f29c0760c32f09d2f328af3d39919c8e6"; + x86_64-apple-darwin = "84e5be6c5c78734deba911dcf80316be1e4c7da2c59413124d039ad96620612f"; + powerpc64le-unknown-linux-gnu = "5760c3b1897ea70791320c2565f3eef700a3d54059027b84bbe6b8d6157f81c8"; + }; + + selectRustPackage = pkgs: pkgs.rust_1_48; + + rustcPatches = [ + ]; +} + +(builtins.removeAttrs args [ "fetchpatch" "pkgsBuildHost" "llvmPackages_5" "llvm_11"]) diff --git a/nixpkgs/pkgs/development/compilers/rust/binary.nix b/nixpkgs/pkgs/development/compilers/rust/binary.nix new file mode 100644 index 000000000000..b84e390e0b0d --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/binary.nix @@ -0,0 +1,108 @@ +{ stdenv, makeWrapper, bash, curl, darwin, zlib +, version +, src +, platform +, versionType +}: + +let + inherit (stdenv.lib) optionalString; + inherit (darwin.apple_sdk.frameworks) Security; + + bootstrapping = versionType == "bootstrap"; + + installComponents + = "rustc,rust-std-${platform}" + + (optionalString bootstrapping ",cargo") + ; +in + +rec { + rustc = stdenv.mkDerivation { + name = "rustc-${versionType}-${version}"; + + inherit version; + inherit src; + + meta = with stdenv.lib; { + homepage = "http://www.rust-lang.org/"; + description = "A safe, concurrent, practical language"; + maintainers = with maintainers; [ qknight ]; + license = [ licenses.mit licenses.asl20 ]; + }; + + buildInputs = [ bash ] + ++ stdenv.lib.optional stdenv.isDarwin Security; + + postPatch = '' + patchShebangs . + ''; + + installPhase = '' + ./install.sh --prefix=$out \ + --components=${installComponents} + + ${optionalString (stdenv.isLinux && bootstrapping) ('' + patchelf \ + --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ + "$out/bin/rustc" + '' + optionalString (stdenv.lib.versionAtLeast version "1.46") + # rustc bootstrap needs libz starting from 1.46 + '' + ln -s ${zlib}/lib/libz.so.1 $out/lib/libz.so.1 + ln -s ${zlib}/lib/libz.so $out/lib/libz.so + '' + '' + patchelf \ + --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ + "$out/bin/rustdoc" + patchelf \ + --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ + "$out/bin/cargo" + '')} + + # Do NOT, I repeat, DO NOT use `wrapProgram` on $out/bin/rustc + # (or similar) here. It causes strange effects where rustc loads + # the wrong libraries in a bootstrap-build causing failures that + # are very hard to track down. For details, see + # https://github.com/rust-lang/rust/issues/34722#issuecomment-232164943 + ''; + + setupHooks = ./setup-hook.sh; + }; + + cargo = stdenv.mkDerivation { + name = "cargo-${versionType}-${version}"; + + inherit version; + inherit src; + + meta = with stdenv.lib; { + homepage = "http://www.rust-lang.org/"; + description = "A safe, concurrent, practical language"; + maintainers = with maintainers; [ qknight ]; + license = [ licenses.mit licenses.asl20 ]; + }; + + buildInputs = [ makeWrapper bash ] + ++ stdenv.lib.optional stdenv.isDarwin Security; + + postPatch = '' + patchShebangs . + ''; + + installPhase = '' + patchShebangs ./install.sh + ./install.sh --prefix=$out \ + --components=cargo + + ${optionalString (stdenv.isLinux && bootstrapping) '' + patchelf \ + --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ + "$out/bin/cargo" + ''} + + wrapProgram "$out/bin/cargo" \ + --suffix PATH : "${rustc}/bin" + ''; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/bootstrap.nix b/nixpkgs/pkgs/development/compilers/rust/bootstrap.nix new file mode 100644 index 000000000000..7c0b46d55931 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/bootstrap.nix @@ -0,0 +1,14 @@ +{ stdenv, fetchurl, rust, callPackage, version, hashes }: + +let + platform = rust.toRustTarget stdenv.hostPlatform; + + src = fetchurl { + url = "https://static.rust-lang.org/dist/rust-${version}-${platform}.tar.gz"; + sha256 = hashes.${platform} or (throw "missing bootstrap url for platform ${platform}"); + }; + +in callPackage ./binary.nix + { inherit version src platform; + versionType = "bootstrap"; + } diff --git a/nixpkgs/pkgs/development/compilers/rust/cargo.nix b/nixpkgs/pkgs/development/compilers/rust/cargo.nix new file mode 100644 index 000000000000..e820b982620a --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/cargo.nix @@ -0,0 +1,64 @@ +{ stdenv, file, curl, pkgconfig, python3, openssl, cmake, zlib +, installShellFiles, makeWrapper, libiconv, cacert, rustPlatform, rustc +, CoreFoundation, Security +}: + +rustPlatform.buildRustPackage { + name = "cargo-${rustc.version}"; + inherit (rustc) version src; + + # the rust source tarball already has all the dependencies vendored, no need to fetch them again + cargoVendorDir = "vendor"; + buildAndTestSubdir = "src/tools/cargo"; + + passthru.rustc = rustc; + + # changes hash of vendor directory otherwise + dontUpdateAutotoolsGnuConfigScripts = true; + + nativeBuildInputs = [ pkgconfig cmake installShellFiles makeWrapper ]; + buildInputs = [ cacert file curl python3 openssl zlib ] + ++ stdenv.lib.optionals stdenv.isDarwin [ CoreFoundation Security libiconv ]; + + # cargo uses git-rs which is made for a version of libgit2 from recent master that + # is not compatible with the current version in nixpkgs. + #LIBGIT2_SYS_USE_PKG_CONFIG = 1; + + # fixes: the cargo feature `edition` requires a nightly version of Cargo, but this is the `stable` channel + RUSTC_BOOTSTRAP = 1; + + postInstall = '' + # NOTE: We override the `http.cainfo` option usually specified in + # `.cargo/config`. This is an issue when users want to specify + # their own certificate chain as environment variables take + # precedence + wrapProgram "$out/bin/cargo" \ + --suffix PATH : "${rustc}/bin" \ + --set CARGO_HTTP_CAINFO "${cacert}/etc/ssl/certs/ca-bundle.crt" \ + --set SSL_CERT_FILE "${cacert}/etc/ssl/certs/ca-bundle.crt" + + installManPage src/tools/cargo/src/etc/man/* + + installShellCompletion --bash --name cargo \ + src/tools/cargo/src/etc/cargo.bashcomp.sh + + installShellCompletion --zsh src/tools/cargo/src/etc/_cargo + ''; + + checkPhase = '' + # Disable cross compilation tests + export CFG_DISABLE_CROSS_TESTS=1 + cargo test + ''; + + # Disable check phase as there are failures (4 tests fail) + doCheck = false; + + meta = with stdenv.lib; { + homepage = "https://crates.io"; + description = "Downloads your Rust project's dependencies and builds your project"; + maintainers = with maintainers; [ retrry ]; + license = [ licenses.mit licenses.asl20 ]; + platforms = platforms.unix; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/clippy.nix b/nixpkgs/pkgs/development/compilers/rust/clippy.nix new file mode 100644 index 000000000000..0546ad9bac1a --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/clippy.nix @@ -0,0 +1,34 @@ +{ stdenv, lib, rustPlatform, rustc, Security, patchelf }: +rustPlatform.buildRustPackage { + name = "clippy-${rustc.version}"; + inherit (rustc) version src; + + # the rust source tarball already has all the dependencies vendored, no need to fetch them again + cargoVendorDir = "vendor"; + buildAndTestSubdir = "src/tools/clippy"; + + # changes hash of vendor directory otherwise + dontUpdateAutotoolsGnuConfigScripts = true; + + buildInputs = [ rustc rustc.llvm ] ++ stdenv.lib.optionals stdenv.isDarwin [ Security ]; + + # fixes: error: the option `Z` is only accepted on the nightly compiler + RUSTC_BOOTSTRAP = 1; + + # Without disabling the test the build fails with: + # error: failed to run custom build command for `rustc_llvm v0.0.0 + # (/private/tmp/nix-build-clippy-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm) + doCheck = false; + + preFixup = stdenv.lib.optionalString stdenv.isDarwin '' + install_name_tool -add_rpath "${rustc}/lib" $out/bin/clippy-driver + ''; + + meta = with stdenv.lib; { + homepage = "https://rust-lang.github.io/rust-clippy/"; + description = "A bunch of lints to catch common mistakes and improve your Rust code"; + maintainers = with maintainers; [ basvandijk ]; + license = with licenses; [ mit asl20 ]; + platforms = platforms.unix; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/default.nix b/nixpkgs/pkgs/development/compilers/rust/default.nix new file mode 100644 index 000000000000..6203eaf47baf --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/default.nix @@ -0,0 +1,105 @@ +{ rustcVersion +, rustcSha256 +, enableRustcDev ? true +, bootstrapVersion +, bootstrapHashes +, selectRustPackage +, rustcPatches ? [] +, llvmBootstrapForDarwin +, llvmShared +, llvmSharedForBuild +, llvmSharedForHost +, llvmSharedForTarget +}: +{ stdenv, lib +, buildPackages +, newScope, callPackage +, CoreFoundation, Security +, pkgsBuildTarget, pkgsBuildBuild +, makeRustPlatform +}: rec { + # https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch + toTargetArch = platform: + if platform.isAarch32 then "arm" + else platform.parsed.cpu.name; + + # https://doc.rust-lang.org/reference/conditional-compilation.html#target_os + toTargetOs = platform: + if platform.isDarwin then "macos" + else platform.parsed.kernel.name; + + # Returns the name of the rust target, even if it is custom. Adjustments are + # because rust has slightly different naming conventions than we do. + toRustTarget = platform: with platform.parsed; let + cpu_ = platform.rustc.platform.arch or { + "armv7a" = "armv7"; + "armv7l" = "armv7"; + "armv6l" = "arm"; + }.${cpu.name} or cpu.name; + in platform.rustc.config + or "${cpu_}-${vendor.name}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; + + # Returns the name of the rust target if it is standard, or the json file + # containing the custom target spec. + toRustTargetSpec = platform: + if (platform.rustc or {}) ? platform + then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform) + else toRustTarget platform; + + # This just contains tools for now. But it would conceivably contain + # libraries too, say if we picked some default/recommended versions from + # `cratesIO` to build by Hydra and/or try to prefer/bias in Cargo.lock for + # all vendored Carnix-generated nix. + # + # In the end game, rustc, the rust standard library (`core`, `std`, etc.), + # and cargo would themselves be built with `buildRustCreate` like + # everything else. Tools and `build.rs` and procedural macro dependencies + # would be taken from `buildRustPackages` (and `bootstrapRustPackages` for + # anything provided prebuilt or their build-time dependencies to break + # cycles / purify builds). In this way, nixpkgs would be in control of all + # bootstrapping. + packages = { + prebuilt = callPackage ./bootstrap.nix { + version = bootstrapVersion; + hashes = bootstrapHashes; + }; + stable = lib.makeScope newScope (self: let + # Like `buildRustPackages`, but may also contain prebuilt binaries to + # break cycle. Just like `bootstrapTools` for nixpkgs as a whole, + # nothing in the final package set should refer to this. + bootstrapRustPackages = self.buildRustPackages.overrideScope' (_: _: + lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform) + (selectRustPackage buildPackages).packages.prebuilt); + bootRustPlatform = makeRustPlatform bootstrapRustPackages; + in { + # Packages suitable for build-time, e.g. `build.rs`-type stuff. + buildRustPackages = (selectRustPackage buildPackages).packages.stable; + # Analogous to stdenv + rustPlatform = makeRustPlatform self.buildRustPackages; + rustc = self.callPackage ./rustc.nix ({ + version = rustcVersion; + sha256 = rustcSha256; + inherit enableRustcDev; + inherit llvmShared llvmSharedForBuild llvmSharedForHost llvmSharedForTarget; + + patches = rustcPatches; + + # Use boot package set to break cycle + rustPlatform = bootRustPlatform; + } // lib.optionalAttrs (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) { + stdenv = llvmBootstrapForDarwin.stdenv; + pkgsBuildBuild = pkgsBuildBuild // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; }; + pkgsBuildHost = pkgsBuildBuild // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; }; + pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; }; + }); + rustfmt = self.callPackage ./rustfmt.nix { inherit Security; }; + cargo = self.callPackage ./cargo.nix { + # Use boot package set to break cycle + rustPlatform = bootRustPlatform; + inherit CoreFoundation Security; + }; + clippy = self.callPackage ./clippy.nix { inherit Security; }; + rls = self.callPackage ./rls { inherit CoreFoundation Security; }; + }); + }; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/make-rust-platform.nix b/nixpkgs/pkgs/development/compilers/rust/make-rust-platform.nix new file mode 100644 index 000000000000..4b1f572bebb8 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/make-rust-platform.nix @@ -0,0 +1,25 @@ +{ buildPackages, callPackage }: + +{ rustc, cargo, ... }: + +rec { + rust = { + inherit rustc cargo; + }; + + fetchCargoTarball = buildPackages.callPackage ../../../build-support/rust/fetchCargoTarball.nix { + inherit cargo; + }; + + buildRustPackage = callPackage ../../../build-support/rust { + inherit rustc cargo fetchCargoTarball; + }; + + rustcSrc = callPackage ./rust-src.nix { + inherit rustc; + }; + + rustLibSrc = callPackage ./rust-lib-src.nix { + inherit rustc; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/print-hashes.sh b/nixpkgs/pkgs/development/compilers/rust/print-hashes.sh new file mode 100755 index 000000000000..9180ccb67d91 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/print-hashes.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -euo pipefail + +# All rust-related downloads can be found at +# https://static.rust-lang.org/dist/index.html. To find the date on +# which a particular thing was last updated, look for the *-date.txt +# file, e.g. +# https://static.rust-lang.org/dist/channel-rust-beta-date.txt + +PLATFORMS=( + i686-unknown-linux-gnu + x86_64-unknown-linux-gnu + arm-unknown-linux-gnueabihf + armv7-unknown-linux-gnueabihf + aarch64-unknown-linux-gnu + x86_64-apple-darwin + powerpc64le-unknown-linux-gnu +) +BASEURL=https://static.rust-lang.org/dist +VERSION=${1:-} +DATE=${2:-} + +if [[ -z $VERSION ]] +then + echo "No version supplied" + exit -1 +fi + +if [[ -n $DATE ]] +then + BASEURL=$BASEURL/$DATE +fi + +for PLATFORM in "${PLATFORMS[@]}" +do + URL="$BASEURL/rust-$VERSION-$PLATFORM.tar.gz.sha256" + SHA256=$(curl -sSfL $URL | cut -d ' ' -f 1) + echo "$PLATFORM = \"$SHA256\";" +done diff --git a/nixpkgs/pkgs/development/compilers/rust/rls/default.nix b/nixpkgs/pkgs/development/compilers/rust/rls/default.nix new file mode 100644 index 000000000000..06b1b9b1e648 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/rls/default.nix @@ -0,0 +1,53 @@ +{ stdenv, makeWrapper, fetchFromGitHub, rustPlatform +, openssh, openssl, pkgconfig, cmake, zlib, curl, libiconv +, CoreFoundation, Security }: + +rustPlatform.buildRustPackage { + pname = "rls"; + inherit (rustPlatform.rust.rustc) src version; + + # changes hash of vendor directory otherwise + dontUpdateAutotoolsGnuConfigScripts = true; + + cargoVendorDir = "vendor"; + buildAndTestSubdir = "src/tools/rls"; + + preBuild = '' + # client tests are flaky + rm tests/client.rs + ''; + + # a nightly compiler is required unless we use this cheat code. + RUSTC_BOOTSTRAP=1; + + # As of rustc 1.45.0, these env vars are required to build rls + # (due to https://github.com/rust-lang/rust/pull/72001) + CFG_RELEASE = "${rustPlatform.rust.rustc.version}-nightly"; + CFG_RELEASE_CHANNEL = "nightly"; + + # rls-rustc links to rustc_private crates + CARGO_BUILD_RUSTFLAGS = if stdenv.isDarwin then "-C rpath" else null; + + nativeBuildInputs = [ pkgconfig cmake ]; + buildInputs = [ openssh openssl curl zlib libiconv makeWrapper rustPlatform.rust.rustc.llvm ] + ++ (stdenv.lib.optionals stdenv.isDarwin [ CoreFoundation Security ]); + + doCheck = true; + + doInstallCheck = true; + installCheckPhase = '' + $out/bin/rls --version + ''; + + RUST_SRC_PATH = rustPlatform.rustcSrc; + postInstall = '' + wrapProgram $out/bin/rls --set-default RUST_SRC_PATH ${rustPlatform.rustcSrc} + ''; + + meta = with stdenv.lib; { + description = "Rust Language Server - provides information about Rust programs to IDEs and other tools"; + homepage = "https://github.com/rust-lang/rls/"; + license = with licenses; [ asl20 /* or */ mit ]; + maintainers = with maintainers; [ symphorien ]; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/rust-lib-src.nix b/nixpkgs/pkgs/development/compilers/rust/rust-lib-src.nix new file mode 100644 index 000000000000..67a7fa3641ad --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/rust-lib-src.nix @@ -0,0 +1,11 @@ +{ stdenv, rustc }: + +stdenv.mkDerivation { + name = "rust-lib-src"; + src = rustc.src; + phases = [ "unpackPhase" "installPhase" ]; + + installPhase = '' + mv library $out + ''; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/rust-src.nix b/nixpkgs/pkgs/development/compilers/rust/rust-src.nix new file mode 100644 index 000000000000..489795ecec47 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/rust-src.nix @@ -0,0 +1,14 @@ +{ stdenv, rustc, minimalContent ? true }: + +stdenv.mkDerivation { + name = "rust-src"; + src = rustc.src; + phases = [ "unpackPhase" "installPhase" ]; + installPhase = '' + mv src $out + rm -rf $out/{${if minimalContent + then "ci,doc,etc,grammar,llvm-project,llvm-emscripten,rtstartup,rustllvm,test,tools,vendor,stdarch" + else "ci,doc,etc,grammar,llvm-project,llvm-emscripten,rtstartup,rustllvm,test,vendor" + }} + ''; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/rustc.nix b/nixpkgs/pkgs/development/compilers/rust/rustc.nix new file mode 100644 index 000000000000..570cd8b796fd --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/rustc.nix @@ -0,0 +1,182 @@ +{ stdenv, removeReferencesTo, pkgsBuildBuild, pkgsBuildHost, pkgsBuildTarget +, llvmShared, llvmSharedForBuild, llvmSharedForHost, llvmSharedForTarget +, fetchurl, file, python3 +, darwin, cmake, rust, rustPlatform +, pkgconfig, openssl +, which, libffi +, withBundledLLVM ? false +, enableRustcDev ? true +, version +, sha256 +, patches ? [] +}: + +let + inherit (stdenv.lib) optionals optional optionalString concatStringsSep; + inherit (darwin.apple_sdk.frameworks) Security; +in stdenv.mkDerivation rec { + pname = "rustc"; + inherit version; + + src = fetchurl { + url = "https://static.rust-lang.org/dist/rustc-${version}-src.tar.gz"; + inherit sha256; + }; + + __darwinAllowLocalNetworking = true; + + # rustc complains about modified source files otherwise + dontUpdateAutotoolsGnuConfigScripts = true; + + # Running the default `strip -S` command on Darwin corrupts the + # .rlib files in "lib/". + # + # See https://github.com/NixOS/nixpkgs/pull/34227 + # + # Running `strip -S` when cross compiling can harm the cross rlibs. + # See: https://github.com/NixOS/nixpkgs/pull/56540#issuecomment-471624656 + stripDebugList = [ "bin" ]; + + NIX_LDFLAGS = toString ( + # 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 ${llvmSharedForHost}/lib"); + + # Increase codegen units to introduce parallelism within the compiler. + RUSTFLAGS = "-Ccodegen-units=10"; + + # 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 = let + setBuild = "--set=target.${rust.toRustTarget stdenv.buildPlatform}"; + setHost = "--set=target.${rust.toRustTarget stdenv.hostPlatform}"; + setTarget = "--set=target.${rust.toRustTarget stdenv.targetPlatform}"; + ccForBuild = "${pkgsBuildBuild.targetPackages.stdenv.cc}/bin/${pkgsBuildBuild.targetPackages.stdenv.cc.targetPrefix}cc"; + cxxForBuild = "${pkgsBuildBuild.targetPackages.stdenv.cc}/bin/${pkgsBuildBuild.targetPackages.stdenv.cc.targetPrefix}c++"; + ccForHost = "${pkgsBuildHost.targetPackages.stdenv.cc}/bin/${pkgsBuildHost.targetPackages.stdenv.cc.targetPrefix}cc"; + cxxForHost = "${pkgsBuildHost.targetPackages.stdenv.cc}/bin/${pkgsBuildHost.targetPackages.stdenv.cc.targetPrefix}c++"; + ccForTarget = "${pkgsBuildTarget.targetPackages.stdenv.cc}/bin/${pkgsBuildTarget.targetPackages.stdenv.cc.targetPrefix}cc"; + cxxForTarget = "${pkgsBuildTarget.targetPackages.stdenv.cc}/bin/${pkgsBuildTarget.targetPackages.stdenv.cc.targetPrefix}c++"; + in [ + "--release-channel=stable" + "--set=build.rustc=${rustPlatform.rust.rustc}/bin/rustc" + "--set=build.cargo=${rustPlatform.rust.cargo}/bin/cargo" + "--enable-rpath" + "--enable-vendor" + "--build=${rust.toRustTargetSpec stdenv.buildPlatform}" + "--host=${rust.toRustTargetSpec stdenv.hostPlatform}" + # std is built for all platforms in --target. When building a cross-compiler + # we need to add the host platform as well so rustc can compile build.rs + # scripts. + "--target=${concatStringsSep "," ([ + (rust.toRustTargetSpec stdenv.targetPlatform) + ] ++ optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + (rust.toRustTargetSpec stdenv.hostPlatform) + ])}" + + "${setBuild}.cc=${ccForBuild}" + "${setHost}.cc=${ccForHost}" + "${setTarget}.cc=${ccForTarget}" + + "${setBuild}.linker=${ccForBuild}" + "${setHost}.linker=${ccForHost}" + "${setTarget}.linker=${ccForTarget}" + + "${setBuild}.cxx=${cxxForBuild}" + "${setHost}.cxx=${cxxForHost}" + "${setTarget}.cxx=${cxxForTarget}" + ] ++ optionals (!withBundledLLVM) [ + "--enable-llvm-link-shared" + "${setBuild}.llvm-config=${llvmSharedForBuild}/bin/llvm-config" + "${setHost}.llvm-config=${llvmSharedForHost}/bin/llvm-config" + "${setTarget}.llvm-config=${llvmSharedForTarget}/bin/llvm-config" + ] ++ optionals (stdenv.isLinux && !stdenv.targetPlatform.isRedox) [ + "--enable-profiler" # build libprofiler_builtins + ] ++ optionals stdenv.buildPlatform.isMusl [ + "${setBuild}.musl-root=${pkgsBuildBuild.targetPackages.stdenv.cc.libc}" + ] ++ optionals stdenv.hostPlatform.isMusl [ + "${setHost}.musl-root=${pkgsBuildHost.targetPackages.stdenv.cc.libc}" + ] ++ optionals stdenv.targetPlatform.isMusl [ + "${setTarget}.musl-root=${pkgsBuildTarget.targetPackages.stdenv.cc.libc}" + ]; + + # 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 + # to the bootstrap builder. + postConfigure = '' + substituteInPlace Makefile \ + --replace 'BOOTSTRAP_ARGS :=' 'BOOTSTRAP_ARGS := --jobs $(NIX_BUILD_CORES)' + ''; + + # the rust build system complains that nix alters the checksums + dontFixLibtool = true; + + inherit patches; + + postPatch = '' + patchShebangs src/etc + + ${optionalString (!withBundledLLVM) ''rm -rf src/llvm''} + + # Fix the configure script to not require curl as we won't use it + sed -i configure \ + -e '/probe_need CFG_CURL curl/d' + + # Useful debugging parameter + # export VERBOSE=1 + ''; + + # rustc unfortunately needs cmake to compile llvm-rt but doesn't + # use it for the normal build. This disables cmake in Nix. + dontUseCmakeConfigure = true; + + nativeBuildInputs = [ + file python3 rustPlatform.rust.rustc cmake + which libffi removeReferencesTo pkgconfig + ]; + + buildInputs = [ openssl ] + ++ optional stdenv.isDarwin Security + ++ optional (!withBundledLLVM) llvmShared; + + outputs = [ "out" "man" "doc" ]; + setOutputFlags = false; + + postInstall = stdenv.lib.optionalString enableRustcDev '' + # install rustc-dev components. Necessary to build rls, clippy... + python x.py dist rustc-dev + tar xf build/dist/rustc-dev*tar.gz + cp -r rustc-dev*/rustc-dev*/lib/* $out/lib/ + rm $out/lib/rustlib/install.log + for m in $out/lib/rustlib/manifest-rust* + do + sort --output=$m < $m + done + + '' + '' + # 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 + find $out/lib -name "*.so" -type f -exec remove-references-to -t ${llvmShared} '{}' '+' + ''; + + configurePlatforms = []; + + # https://github.com/NixOS/nixpkgs/pull/21742#issuecomment-272305764 + # https://github.com/rust-lang/rust/issues/30181 + # enableParallelBuilding = false; + + setupHooks = ./setup-hook.sh; + + requiredSystemFeatures = [ "big-parallel" ]; + + passthru.llvm = llvmShared; + + meta = with stdenv.lib; { + homepage = "https://www.rust-lang.org/"; + description = "A safe, concurrent, practical language"; + maintainers = with maintainers; [ madjar cstrahan globin havvy ]; + license = [ licenses.mit licenses.asl20 ]; + platforms = platforms.linux ++ platforms.darwin; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/rustfmt.nix b/nixpkgs/pkgs/development/compilers/rust/rustfmt.nix new file mode 100644 index 000000000000..6215c936c6d0 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/rustfmt.nix @@ -0,0 +1,30 @@ +{ stdenv, rustPlatform, Security }: + +rustPlatform.buildRustPackage rec { + pname = "rustfmt"; + inherit (rustPlatform.rust.rustc) version src; + + # the rust source tarball already has all the dependencies vendored, no need to fetch them again + cargoVendorDir = "vendor"; + buildAndTestSubdir = "src/tools/rustfmt"; + + # changes hash of vendor directory otherwise + dontUpdateAutotoolsGnuConfigScripts = true; + + buildInputs = stdenv.lib.optional stdenv.isDarwin Security; + + # As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler + RUSTC_BOOTSTRAP = 1; + + # As of rustc 1.45.0, these env vars are required to build rustfmt (due to + # https://github.com/rust-lang/rust/pull/72001) + CFG_RELEASE = "${rustPlatform.rust.rustc.version}-nightly"; + CFG_RELEASE_CHANNEL = "nightly"; + + meta = with stdenv.lib; { + description = "A tool for formatting Rust code according to style guidelines"; + homepage = "https://github.com/rust-lang-nursery/rustfmt"; + license = with licenses; [ mit asl20 ]; + maintainers = with maintainers; [ globin basvandijk ]; + }; +} diff --git a/nixpkgs/pkgs/development/compilers/rust/setup-hook.sh b/nixpkgs/pkgs/development/compilers/rust/setup-hook.sh new file mode 100644 index 000000000000..5d4eb642fec0 --- /dev/null +++ b/nixpkgs/pkgs/development/compilers/rust/setup-hook.sh @@ -0,0 +1,4 @@ +# Fix 'failed to open: /homeless-shelter/.cargo/.package-cache' in rust 1.36. +if [[ -z ${IN_NIX_SHELL-} && -z ${CARGO_HOME-} ]]; then + export CARGO_HOME=$TMPDIR +fi |