at master 2.1 kB view raw
1{ 2 lib, 3 stdenv, 4 cargo, 5 makeWrapper, 6 rustPlatform, 7 rustc, 8 asNightly ? false, 9}: 10 11rustPlatform.buildRustPackage { 12 pname = "rustfmt" + lib.optionalString asNightly "-nightly"; 13 inherit (rustc) version src; 14 15 # the rust source tarball already has all the dependencies vendored, no need to fetch them again 16 cargoVendorDir = "vendor"; 17 buildAndTestSubdir = "src/tools/rustfmt"; 18 19 # changes hash of vendor directory otherwise 20 dontUpdateAutotoolsGnuConfigScripts = true; 21 22 nativeBuildInputs = [ 23 makeWrapper 24 ]; 25 26 buildInputs = [ 27 rustc.llvm 28 ]; 29 30 # rustfmt uses the rustc_driver and std private libraries, and Rust's build process forces them to have 31 # an install name of `@rpath/...` [0] [1] instead of the standard on macOS, which is an absolute path 32 # to itself. 33 # 34 # [0]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/src/bootstrap/builder.rs#L1543 35 # [1]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/compiler/rustc_codegen_ssa/src/back/linker.rs#L323-L331 36 preFixup = lib.optionalString stdenv.hostPlatform.isDarwin '' 37 install_name_tool -add_rpath "${rustc.unwrapped}/lib" "$out/bin/rustfmt" 38 install_name_tool -add_rpath "${rustc.unwrapped}/lib" "$out/bin/git-rustfmt" 39 ''; 40 41 # As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler 42 RUSTC_BOOTSTRAP = 1; 43 44 # As of rustc 1.45.0, these env vars are required to build rustfmt (due to 45 # https://github.com/rust-lang/rust/pull/72001) 46 CFG_RELEASE = rustc.version; 47 CFG_RELEASE_CHANNEL = if asNightly then "nightly" else "stable"; 48 49 postInstall = '' 50 wrapProgram $out/bin/cargo-fmt \ 51 --suffix PATH : ${lib.makeBinPath [ cargo ]} 52 ''; 53 54 meta = with lib; { 55 description = "Tool for formatting Rust code according to style guidelines"; 56 homepage = "https://github.com/rust-lang-nursery/rustfmt"; 57 license = with licenses; [ 58 mit 59 asl20 60 ]; 61 mainProgram = "rustfmt"; 62 maintainers = with maintainers; [ 63 globin 64 basvandijk 65 ]; 66 }; 67}