Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at gcc-offload 150 lines 4.3 kB view raw
1{ 2 stdenv, 3 lib, 4 runCommand, 5 patchelf, 6 fetchFromGitHub, 7 rustPlatform, 8 makeBinaryWrapper, 9 pkg-config, 10 openssl, 11 curl, 12 zlib, 13 Security, 14 CoreServices, 15 libiconv, 16 xz, 17}: 18 19let 20 libPath = lib.makeLibraryPath [ 21 zlib # libz.so.1 22 ]; 23in 24 25rustPlatform.buildRustPackage rec { 26 pname = "rustup"; 27 version = "1.27.1"; 28 29 src = fetchFromGitHub { 30 owner = "rust-lang"; 31 repo = "rustup"; 32 rev = version; 33 sha256 = "sha256-BehkJTEIbZHaM+ABaWN/grl9pX75lPqyBj1q1Kt273M="; 34 }; 35 36 cargoHash = "sha256-iQoMPV97V9WJqT+qVtNpQtW5g+Jyl+U2uA+JEoRYTQA="; 37 38 nativeBuildInputs = [ 39 makeBinaryWrapper 40 pkg-config 41 ]; 42 43 buildInputs = 44 [ 45 (curl.override { inherit openssl; }) 46 zlib 47 ] 48 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 49 CoreServices 50 Security 51 libiconv 52 xz 53 ]; 54 55 buildFeatures = [ "no-self-update" ]; 56 57 checkFeatures = [ "test" ]; 58 59 patches = lib.optionals stdenv.hostPlatform.isLinux [ 60 (runCommand "0001-dynamically-patchelf-binaries.patch" 61 { 62 CC = stdenv.cc; 63 patchelf = patchelf; 64 libPath = "${libPath}"; 65 } 66 '' 67 export dynamicLinker=$(cat $CC/nix-support/dynamic-linker) 68 substitute ${./0001-dynamically-patchelf-binaries.patch} $out \ 69 --subst-var patchelf \ 70 --subst-var dynamicLinker \ 71 --subst-var libPath 72 '' 73 ) 74 ]; 75 76 # Random tests fail nondeterministically on macOS. 77 # TODO: Investigate this. 78 doCheck = !stdenv.hostPlatform.isDarwin; 79 80 # skip failing tests 81 checkFlags = [ 82 # auto-self-update mode is set to 'disable' for nix rustup 83 "--skip=suite::cli_exact::check_updates_none" 84 "--skip=suite::cli_exact::check_updates_some" 85 "--skip=suite::cli_exact::check_updates_with_update" 86 # rustup-init is not used in nix rustup 87 "--skip=suite::cli_ui::rustup_init_ui_doc_text_tests" 88 ]; 89 90 postInstall = '' 91 pushd $out/bin 92 mv rustup-init rustup 93 binlinks=( 94 cargo rustc rustdoc rust-gdb rust-lldb rls rustfmt cargo-fmt 95 cargo-clippy clippy-driver cargo-miri rust-gdbgui rust-analyzer 96 ) 97 for link in ''${binlinks[@]}; do 98 ln -s rustup $link 99 done 100 popd 101 102 wrapProgram $out/bin/rustup --prefix "LD_LIBRARY_PATH" : "${libPath}" 103 104 # tries to create .rustup 105 export HOME=$(mktemp -d) 106 mkdir -p "$out/share/"{bash-completion/completions,fish/vendor_completions.d,zsh/site-functions} 107 108 # generate completion scripts for rustup 109 $out/bin/rustup completions bash rustup > "$out/share/bash-completion/completions/rustup" 110 $out/bin/rustup completions fish rustup > "$out/share/fish/vendor_completions.d/rustup.fish" 111 $out/bin/rustup completions zsh rustup > "$out/share/zsh/site-functions/_rustup" 112 113 # generate completion scripts for cargo 114 # Note: fish completion script is not supported. 115 $out/bin/rustup completions bash cargo > "$out/share/bash-completion/completions/cargo" 116 $out/bin/rustup completions zsh cargo > "$out/share/zsh/site-functions/_cargo" 117 118 # add a wrapper script for ld.lld 119 mkdir -p $out/nix-support 120 substituteAll ${../../../../../pkgs/build-support/wrapper-common/utils.bash} $out/nix-support/utils.bash 121 substituteAll ${../../../../../pkgs/build-support/wrapper-common/darwin-sdk-setup.bash} $out/nix-support/darwin-sdk-setup.bash 122 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/add-flags.sh} $out/nix-support/add-flags.sh 123 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/add-hardening.sh} $out/nix-support/add-hardening.sh 124 export prog='$PROG' 125 export use_response_file_by_default=0 126 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/ld-wrapper.sh} $out/nix-support/ld-wrapper.sh 127 chmod +x $out/nix-support/ld-wrapper.sh 128 ''; 129 130 env = lib.optionalAttrs (pname == "rustup") { 131 inherit (stdenv.cc.bintools) 132 expandResponseParams 133 shell 134 suffixSalt 135 wrapperName 136 coreutils_bin 137 ; 138 hardening_unsupported_flags = ""; 139 }; 140 141 meta = with lib; { 142 description = "Rust toolchain installer"; 143 homepage = "https://www.rustup.rs/"; 144 license = with licenses; [ 145 asl20 # or 146 mit 147 ]; 148 maintainers = [ maintainers.mic92 ]; 149 }; 150}