From 16cb2611d9235868c4596c40080fdd24157186d3 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Fri, 16 Aug 2019 12:26:51 +0200 Subject: [PATCH 1/3] rustfmt: use the src as defined by the git submodule in rust This commit makes sure rustc and rustfmt are compatible by setting rustfmt's src to the rustfmt git submodule as defined in: https://github.com/rust-lang/rust/tree/1.36.0/src/tools --- pkgs/development/compilers/rust/default.nix | 1 + pkgs/development/compilers/rust/rustfmt.nix | 89 +++++++++++++++++++ .../tools/rust/rustfmt/default.nix | 34 ------- pkgs/top-level/all-packages.nix | 2 +- 4 files changed, 91 insertions(+), 35 deletions(-) create mode 100644 pkgs/development/compilers/rust/rustfmt.nix delete mode 100644 pkgs/development/tools/rust/rustfmt/default.nix diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix index 0e3de0c4ab9..d4f2f50ceee 100644 --- a/pkgs/development/compilers/rust/default.nix +++ b/pkgs/development/compilers/rust/default.nix @@ -59,6 +59,7 @@ pkgsBuildHost = pkgsBuildBuild // { targetPackages.stdenv = llvmPackages_5.stdenv; }; pkgsBuildTarget = pkgsBuildTarget // { targetPackages.stdenv = llvmPackages_5.stdenv; }; }); + rustfmt = self.callPackage ./rustfmt.nix { inherit Security; }; 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 new file mode 100644 index 00000000000..62a6ccbbef1 --- /dev/null +++ b/pkgs/development/compilers/rust/rustfmt.nix @@ -0,0 +1,89 @@ +{ stdenv, rustPlatform, rustc, Security }: + +rustPlatform.buildRustPackage rec { + name = "rustfmt-${version}"; + inherit (rustc) version src; + + # the rust source tarball already has all the dependencies vendored, no need to fetch them again + cargoVendorDir = "vendor"; + preBuild = "pushd src/tools/rustfmt"; + postBuild = "popd"; + + buildInputs = stdenv.lib.optional stdenv.isDarwin Security; + + # As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler + RUSTC_BOOTSTRAP = 1; + + # Without disabling the test the build fails with: + # + # Compiling rustc_llvm v0.0.0 (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm) + # ... + # error: failed to run custom build command for `rustc_llvm v0.0.0 + # (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm)` + # + # Caused by: + # process didn't exit successfully: + # `/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/target/debug/build/rustc_llvm-4d3eb1eff32fd46b/build-script-build` (exit code: 101) + # --- stdout + # cargo:rerun-if-env-changed=REAL_LIBRARY_PATH_VAR + # cargo:rerun-if-env-changed=REAL_LIBRARY_PATH + # + # --- stderr + # thread 'main' panicked at 'REAL_LIBRARY_PATH_VAR', src/libcore/option.rs:1036:5 + # note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. + # + # Setting the following: + # + # # This mimics https://github.com/rust-lang/rust/blob/1.36.0/src/bootstrap/util.rs#L58:L70 + # REAL_LIBRARY_PATH_VAR = + # if stdenv.isDarwin then "DYLD_LIBRARY_PATH" + # else "LD_LIBRARY_PATH"; + # + # Results in: + # + # Compiling rustc_llvm v0.0.0 (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm) + # ... + # error: failed to run custom build command for `rustc_llvm v0.0.0 (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm)` + # + # Caused by: + # process didn't exit successfully: `/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/target/debug/build/rustc_llvm-4d3eb1eff32fd46b/build-script-build` (exit code: 1) + # --- stdout + # cargo:rerun-if-env-changed=REAL_LIBRARY_PATH_VAR + # cargo:rerun-if-env-changed=REAL_LIBRARY_PATH + # cargo:rerun-if-changed=llvm-config + # cargo:rerun-if-env-changed=LLVM_CONFIG + # + # + # failed to execute command: "llvm-config" "--version" + # error: No such file or directory (os error 2) + # + # Adding `llvmSharedForBuild` to rustc's `passthru` and adding + # `rustc.llvmSharedForBuild` to the `buildInputs` fixes this but then the + # build fails lateron with: + # + # Compiling rustc_llvm v0.0.0 (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm) + # ... + # error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? + # --> src/librustc_llvm/lib.rs:9:1 + # | + # 9 | extern crate rustc_cratesio_shim; + # | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + # | + # = note: for more information, see https://github.com/rust-lang/rust/issues/27812 + # = help: add #![feature(rustc_private)] to the crate attributes to enable + # + # error: aborting due to previous error + # + # For more information about this error, try `rustc --explain E0658`. + # + # error: Could not compile `rustc_llvm`. + doCheck = false; + + 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 ]; + platforms = platforms.all; + }; +} diff --git a/pkgs/development/tools/rust/rustfmt/default.nix b/pkgs/development/tools/rust/rustfmt/default.nix deleted file mode 100644 index b98ab0dc74d..00000000000 --- a/pkgs/development/tools/rust/rustfmt/default.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ stdenv, fetchFromGitHub, rustPlatform, darwin }: - -rustPlatform.buildRustPackage rec { - name = "rustfmt-${version}"; - version = "1.2.2"; - - src = fetchFromGitHub { - owner = "rust-lang"; - repo = "rustfmt"; - rev = "v${version}"; - sha256 = "1k9p6sp8q87flx9vzg46880ir7likvbydai3g6q76278h86rn0v8"; - }; - - cargoSha256 = "08x6vy5v2vgrk3gsw3qcvv52a7hifsgcsnsg1phlk1ikaff21y4z"; - - buildInputs = stdenv.lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Security; - - # As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler - RUSTC_BOOTSTRAP = 1; - - # we run tests in debug mode so tests look for a debug build of - # rustfmt. Anyway this adds nearly no compilation time. - preCheck = '' - cargo build - ''; - - 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 = [ maintainers.globin ]; - platforms = platforms.all; - }; -} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5e9eb55dbab..e5f86984b17 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8243,7 +8243,7 @@ in rls = callPackage ../development/tools/rust/rls { inherit (darwin.apple_sdk.frameworks) CoreFoundation Security; }; - rustfmt = callPackage ../development/tools/rust/rustfmt { }; + rustfmt = rustPackages.rustfmt; rustracer = callPackage ../development/tools/rust/racer { inherit (darwin.apple_sdk.frameworks) Security; }; From dc374218c9038eb98fe1ba048d89f0df319f53c5 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Mon, 19 Aug 2019 12:54:40 +0200 Subject: [PATCH 2/3] rustfmt: make sure to test rustfmt instead of rustc Co-Authored-By: symphorien --- pkgs/development/compilers/rust/rustfmt.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/compilers/rust/rustfmt.nix b/pkgs/development/compilers/rust/rustfmt.nix index 62a6ccbbef1..e564cabd85e 100644 --- a/pkgs/development/compilers/rust/rustfmt.nix +++ b/pkgs/development/compilers/rust/rustfmt.nix @@ -7,7 +7,7 @@ rustPlatform.buildRustPackage rec { # the rust source tarball already has all the dependencies vendored, no need to fetch them again cargoVendorDir = "vendor"; preBuild = "pushd src/tools/rustfmt"; - postBuild = "popd"; + preInstall = "popd"; buildInputs = stdenv.lib.optional stdenv.isDarwin Security; From 4e5d4d5509f1fa2e36fea791975665873445d296 Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Mon, 19 Aug 2019 15:09:15 +0200 Subject: [PATCH 3/3] rustfmt: enable tests --- pkgs/development/compilers/rust/rustfmt.nix | 73 ++------------------- 1 file changed, 7 insertions(+), 66 deletions(-) diff --git a/pkgs/development/compilers/rust/rustfmt.nix b/pkgs/development/compilers/rust/rustfmt.nix index e564cabd85e..d7bcb994313 100644 --- a/pkgs/development/compilers/rust/rustfmt.nix +++ b/pkgs/development/compilers/rust/rustfmt.nix @@ -1,8 +1,8 @@ -{ stdenv, rustPlatform, rustc, Security }: +{ stdenv, rustPlatform, Security }: rustPlatform.buildRustPackage rec { name = "rustfmt-${version}"; - inherit (rustc) version src; + inherit (rustPlatform.rust.rustc) version src; # the rust source tarball already has all the dependencies vendored, no need to fetch them again cargoVendorDir = "vendor"; @@ -14,70 +14,11 @@ rustPlatform.buildRustPackage rec { # As of 1.0.0 and rustc 1.30 rustfmt requires a nightly compiler RUSTC_BOOTSTRAP = 1; - # Without disabling the test the build fails with: - # - # Compiling rustc_llvm v0.0.0 (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm) - # ... - # error: failed to run custom build command for `rustc_llvm v0.0.0 - # (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm)` - # - # Caused by: - # process didn't exit successfully: - # `/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/target/debug/build/rustc_llvm-4d3eb1eff32fd46b/build-script-build` (exit code: 101) - # --- stdout - # cargo:rerun-if-env-changed=REAL_LIBRARY_PATH_VAR - # cargo:rerun-if-env-changed=REAL_LIBRARY_PATH - # - # --- stderr - # thread 'main' panicked at 'REAL_LIBRARY_PATH_VAR', src/libcore/option.rs:1036:5 - # note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. - # - # Setting the following: - # - # # This mimics https://github.com/rust-lang/rust/blob/1.36.0/src/bootstrap/util.rs#L58:L70 - # REAL_LIBRARY_PATH_VAR = - # if stdenv.isDarwin then "DYLD_LIBRARY_PATH" - # else "LD_LIBRARY_PATH"; - # - # Results in: - # - # Compiling rustc_llvm v0.0.0 (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm) - # ... - # error: failed to run custom build command for `rustc_llvm v0.0.0 (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm)` - # - # Caused by: - # process didn't exit successfully: `/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/target/debug/build/rustc_llvm-4d3eb1eff32fd46b/build-script-build` (exit code: 1) - # --- stdout - # cargo:rerun-if-env-changed=REAL_LIBRARY_PATH_VAR - # cargo:rerun-if-env-changed=REAL_LIBRARY_PATH - # cargo:rerun-if-changed=llvm-config - # cargo:rerun-if-env-changed=LLVM_CONFIG - # - # - # failed to execute command: "llvm-config" "--version" - # error: No such file or directory (os error 2) - # - # Adding `llvmSharedForBuild` to rustc's `passthru` and adding - # `rustc.llvmSharedForBuild` to the `buildInputs` fixes this but then the - # build fails lateron with: - # - # Compiling rustc_llvm v0.0.0 (/private/tmp/nix-build-rustfmt-1.36.0.drv-0/rustc-1.36.0-src/src/librustc_llvm) - # ... - # error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? - # --> src/librustc_llvm/lib.rs:9:1 - # | - # 9 | extern crate rustc_cratesio_shim; - # | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - # | - # = note: for more information, see https://github.com/rust-lang/rust/issues/27812 - # = help: add #![feature(rustc_private)] to the crate attributes to enable - # - # error: aborting due to previous error - # - # For more information about this error, try `rustc --explain E0658`. - # - # error: Could not compile `rustc_llvm`. - doCheck = false; + # we run tests in debug mode so tests look for a debug build of + # rustfmt. Anyway this adds nearly no compilation time. + preCheck = '' + cargo build + ''; meta = with stdenv.lib; { description = "A tool for formatting Rust code according to style guidelines";