From 6eb00a41a0850e10e6a12021332a147dd97578a5 Mon Sep 17 00:00:00 2001 From: K900 Date: Wed, 6 Apr 2022 11:03:07 +0300 Subject: [PATCH 1/4] rustfmt: actually fix the failing test It only runs on nightly, but the next commits will show why this is useful. --- .../compilers/rust/rustfmt-fix-self-tests.patch | 13 +++++++++++++ pkgs/development/compilers/rust/rustfmt.nix | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 pkgs/development/compilers/rust/rustfmt-fix-self-tests.patch diff --git a/pkgs/development/compilers/rust/rustfmt-fix-self-tests.patch b/pkgs/development/compilers/rust/rustfmt-fix-self-tests.patch new file mode 100644 index 000000000000..b60332daef44 --- /dev/null +++ b/pkgs/development/compilers/rust/rustfmt-fix-self-tests.patch @@ -0,0 +1,13 @@ +--- a/src/tools/rustfmt/src/ignore_path.rs ++++ b/src/tools/rustfmt/src/ignore_path.rs +@@ -37,9 +37,9 @@ + #[nightly_only_test] + #[test] + fn test_ignore_path_set() { +- use std::path::{Path, PathBuf}; + use crate::config::{Config, FileName}; + use crate::ignore_path::IgnorePathSet; ++ use std::path::{Path, PathBuf}; + + let config = + Config::from_toml(r#"ignore = ["foo.rs", "bar_dir/*"]"#, Path::new("")).unwrap(); diff --git a/pkgs/development/compilers/rust/rustfmt.nix b/pkgs/development/compilers/rust/rustfmt.nix index f8ac8bf39df3..9922d60ef705 100644 --- a/pkgs/development/compilers/rust/rustfmt.nix +++ b/pkgs/development/compilers/rust/rustfmt.nix @@ -21,6 +21,9 @@ rustPlatform.buildRustPackage rec { CFG_RELEASE = rustPlatform.rust.rustc.version; CFG_RELEASE_CHANNEL = "stable"; + # FIXME: seems fixed upstream, remove after the next update + patches = [ ./rustfmt-fix-self-tests.patch ]; + meta = with lib; { description = "A tool for formatting Rust code according to style guidelines"; homepage = "https://github.com/rust-lang-nursery/rustfmt"; From ddef8a68cb5e49323dbb293fd34b079cfa1f8b7a Mon Sep 17 00:00:00 2001 From: K900 Date: Wed, 6 Apr 2022 11:03:37 +0300 Subject: [PATCH 2/4] rustfmt: allow building as nightly This is used by bindgen, and may be useful for other projects as well, as rustfmt disables many features when built as stable. --- pkgs/development/compilers/rust/default.nix | 1 + pkgs/development/compilers/rust/rustfmt.nix | 6 +++--- pkgs/top-level/all-packages.nix | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix index 6dfc8a49063f..82579db0e47a 100644 --- a/pkgs/development/compilers/rust/default.nix +++ b/pkgs/development/compilers/rust/default.nix @@ -77,6 +77,7 @@ in pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; }; }); rustfmt = self.callPackage ./rustfmt.nix { inherit Security; }; + rustfmt-nightly = self.callPackage ./rustfmt.nix { inherit Security; asNightly = true; }; cargo = self.callPackage ./cargo.nix { # Use boot package set to break cycle rustPlatform = bootRustPlatform; diff --git a/pkgs/development/compilers/rust/rustfmt.nix b/pkgs/development/compilers/rust/rustfmt.nix index 9922d60ef705..5916b6c07fb5 100644 --- a/pkgs/development/compilers/rust/rustfmt.nix +++ b/pkgs/development/compilers/rust/rustfmt.nix @@ -1,7 +1,7 @@ -{ lib, stdenv, rustPlatform, Security }: +{ lib, stdenv, rustPlatform, Security, asNightly ? false }: rustPlatform.buildRustPackage rec { - pname = "rustfmt"; + pname = "rustfmt" + lib.optionalString asNightly "-nightly"; inherit (rustPlatform.rust.rustc) version src; # the rust source tarball already has all the dependencies vendored, no need to fetch them again @@ -19,7 +19,7 @@ rustPlatform.buildRustPackage rec { # 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; - CFG_RELEASE_CHANNEL = "stable"; + CFG_RELEASE_CHANNEL = if asNightly then "nightly" else "stable"; # FIXME: seems fixed upstream, remove after the next update patches = [ ./rustfmt-fix-self-tests.patch ]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 227cdccaec1f..851c26182130 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13471,7 +13471,10 @@ with pkgs; rhack = callPackage ../development/tools/rust/rhack { }; inherit (rustPackages) rls; roogle = callPackage ../development/tools/rust/roogle { }; + rustfmt = rustPackages.rustfmt; + rustfmt-nightly = rustPackages.rustfmt-nightly; + rustracer = callPackage ../development/tools/rust/racer { inherit (darwin.apple_sdk.frameworks) Security; }; From e5f5ad71acb8e67ac8f90bcced86b1760cfaa3f3 Mon Sep 17 00:00:00 2001 From: K900 Date: Wed, 6 Apr 2022 11:10:17 +0300 Subject: [PATCH 3/4] rust-bindgen: use rustfmt-nightly bindgen's tests rely on specific output from rustfmt that uses unstable features, so breaks when we build rustfmt as stable. Also, use a better way to specify the rustfmt executable. --- .../tools/rust/bindgen/unwrapped.nix | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/pkgs/development/tools/rust/bindgen/unwrapped.nix b/pkgs/development/tools/rust/bindgen/unwrapped.nix index 65ce8e20bc0e..5e52c851eab4 100644 --- a/pkgs/development/tools/rust/bindgen/unwrapped.nix +++ b/pkgs/development/tools/rust/bindgen/unwrapped.nix @@ -1,4 +1,4 @@ -{ lib, fetchFromGitHub, rustPlatform, clang, rustfmt, writeTextFile +{ lib, fetchFromGitHub, rustPlatform, clang, rustfmt-nightly , runtimeShell , bash }: @@ -25,23 +25,11 @@ rustPlatform.buildRustPackage rec { ''; doCheck = true; - checkInputs = - let fakeRustup = writeTextFile { - name = "fake-rustup"; - executable = true; - destination = "/bin/rustup"; - text = '' - #!${runtimeShell} - shift - shift - exec "$@" - ''; - }; - in [ - rustfmt - fakeRustup # the test suite insists in calling `rustup run nightly rustfmt` - clang - ]; + checkInputs = [ clang ]; + + # bindgen hardcodes rustfmt outputs that use nightly features + RUSTFMT = "${rustfmt-nightly}/bin/rustfmt"; + preCheck = '' # for the ci folder, notably patchShebangs . From af7c34be0b874493e10df040da137e2611a3e237 Mon Sep 17 00:00:00 2001 From: K900 Date: Thu, 7 Apr 2022 19:42:14 +0300 Subject: [PATCH 4/4] rustfmt: drop separate nightly alias If you really want it, override it. --- pkgs/development/compilers/rust/default.nix | 1 - pkgs/development/tools/rust/bindgen/unwrapped.nix | 9 +++++---- pkgs/top-level/all-packages.nix | 3 --- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix index 82579db0e47a..6dfc8a49063f 100644 --- a/pkgs/development/compilers/rust/default.nix +++ b/pkgs/development/compilers/rust/default.nix @@ -77,7 +77,6 @@ in pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmBootstrapForDarwin.stdenv; }; }); rustfmt = self.callPackage ./rustfmt.nix { inherit Security; }; - rustfmt-nightly = self.callPackage ./rustfmt.nix { inherit Security; asNightly = true; }; cargo = self.callPackage ./cargo.nix { # Use boot package set to break cycle rustPlatform = bootRustPlatform; diff --git a/pkgs/development/tools/rust/bindgen/unwrapped.nix b/pkgs/development/tools/rust/bindgen/unwrapped.nix index 5e52c851eab4..f77e2feb4ff3 100644 --- a/pkgs/development/tools/rust/bindgen/unwrapped.nix +++ b/pkgs/development/tools/rust/bindgen/unwrapped.nix @@ -1,9 +1,11 @@ -{ lib, fetchFromGitHub, rustPlatform, clang, rustfmt-nightly +{ lib, fetchFromGitHub, rustPlatform, clang, rustfmt , runtimeShell , bash }: - -rustPlatform.buildRustPackage rec { +let + # bindgen hardcodes rustfmt outputs that use nightly features + rustfmt-nightly = rustfmt.override { asNightly = true; }; +in rustPlatform.buildRustPackage rec { pname = "rust-bindgen-unwrapped"; version = "0.59.2"; @@ -27,7 +29,6 @@ rustPlatform.buildRustPackage rec { doCheck = true; checkInputs = [ clang ]; - # bindgen hardcodes rustfmt outputs that use nightly features RUSTFMT = "${rustfmt-nightly}/bin/rustfmt"; preCheck = '' diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 851c26182130..227cdccaec1f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13471,10 +13471,7 @@ with pkgs; rhack = callPackage ../development/tools/rust/rhack { }; inherit (rustPackages) rls; roogle = callPackage ../development/tools/rust/roogle { }; - rustfmt = rustPackages.rustfmt; - rustfmt-nightly = rustPackages.rustfmt-nightly; - rustracer = callPackage ../development/tools/rust/racer { inherit (darwin.apple_sdk.frameworks) Security; };