Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib, stdenv, rustPlatform, rustc, Security, asNightly ? false }: 2 3rustPlatform.buildRustPackage rec { 4 pname = "rustfmt" + lib.optionalString asNightly "-nightly"; 5 inherit (rustc) version src; 6 7 # the rust source tarball already has all the dependencies vendored, no need to fetch them again 8 cargoVendorDir = "vendor"; 9 buildAndTestSubdir = "src/tools/rustfmt"; 10 11 # changes hash of vendor directory otherwise 12 dontUpdateAutotoolsGnuConfigScripts = true; 13 14 buildInputs = [ 15 rustc.llvm 16 ] ++ lib.optional stdenv.isDarwin Security; 17 18 # rustfmt uses the rustc_driver and std private libraries, and Rust's build process forces them to have 19 # an install name of `@rpath/...` [0] [1] instead of the standard on macOS, which is an absolute path 20 # to itself. 21 # 22 # [0]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/src/bootstrap/builder.rs#L1543 23 # [1]: https://github.com/rust-lang/rust/blob/f77f4d55bdf9d8955d3292f709bd9830c2fdeca5/compiler/rustc_codegen_ssa/src/back/linker.rs#L323-L331 24 preFixup = lib.optionalString stdenv.isDarwin '' 25 install_name_tool -add_rpath "${rustc}/lib" "$out/bin/rustfmt" 26 install_name_tool -add_rpath "${rustc}/lib" "$out/bin/git-rustfmt" 27 ''; 28 29 # As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler 30 RUSTC_BOOTSTRAP = 1; 31 32 # As of rustc 1.45.0, these env vars are required to build rustfmt (due to 33 # https://github.com/rust-lang/rust/pull/72001) 34 CFG_RELEASE = rustc.version; 35 CFG_RELEASE_CHANNEL = if asNightly then "nightly" else "stable"; 36 37 meta = with lib; { 38 description = "A tool for formatting Rust code according to style guidelines"; 39 homepage = "https://github.com/rust-lang-nursery/rustfmt"; 40 license = with licenses; [ mit asl20 ]; 41 maintainers = with maintainers; [ globin basvandijk ]; 42 }; 43}