~andir/nixpkgs-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[RESEND] [PATCH] default-crate-overrides: proc-macro-crate assumes env::var("CARGO")

Details
Message ID
<20240822202814.23086-2-adam@westernsemico.com>
DKIM signature
pass
Download raw message
Patch: +13 -0
Since version 2.0.0, proc-macro-crate has assumed it can exec()
`env::var("CARGO")` in order to run `cargo locate-project`.

This commit adds a crate override to proc-macro-crate which simply writes the
path to buildPlatform.cargo into the proc-macro-crate sources.

This way we don't need to set `env.CARGO` for every build that depends on
proc-macro-crate -- if we do that, the $CARGO environment variable would be
visible to the entire build.  This could potentially lead to incredibly
hard-to-troubleshoot heisenbugs if there is some other crate that expects
`env::var("CARGO")` to exist -- that other crate would mysteriously work only
in projects that use proc-macro-crate but not anywhere else!
---
 pkgs/build-support/rust/default-crate-overrides.nix | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/pkgs/build-support/rust/default-crate-overrides.nix b/pkgs/build-support/rust/default-crate-overrides.nix
index d8f1bfaf4447..368753d73c84 100644
--- a/pkgs/build-support/rust/default-crate-overrides.nix
+++ b/pkgs/build-support/rust/default-crate-overrides.nix
@@ -41,6 +41,7 @@
, automake
, libtool
, seatd # =libseat
, buildPackages
, ...
}:

@@ -320,4 +321,16 @@ in
    buildInputs = [ atk ];
  };

  # Assumes it can run Command::new(env::var("CARGO")).arg("locate-project")
  # https://github.com/bkchr/proc-macro-crate/blame/master/src/lib.rs#L244
  proc-macro-crate = attrs: lib.optionalAttrs (lib.versionAtLeast attrs.version "2.0") {
    prePatch = (attrs.prePatch or "") + ''
      substituteInPlace \
        src/lib.rs \
        --replace-fail \
        'env::var("CARGO").map_err(|_| Error::CargoEnvVariableNotSet)?' \
        '"${lib.getBin buildPackages.cargo}/bin/cargo"'
    '';
  };

}
-- 
2.44.1
Details
Message ID
<vrwg4ffz5um5zu4fduto3b7t74opx4u3gjonmwn6n5ajbv5vhr@yltd4z46gma4>
In-Reply-To
<20240822202814.23086-2-adam@westernsemico.com> (view parent)
DKIM signature
pass
Download raw message
Don't know what your rebased against, certainly not after
0c00ad14acbef5f64476b473e9ba035ad504d3a1, but it still didn't apply.

I now manually applied the patch and sent out
https://github.com/NixOS/nixpkgs/pull/336704.

On Thu, Aug 22, 2024 at 01:28:15PM GMT, Adam Joseph wrote:
>Since version 2.0.0, proc-macro-crate has assumed it can exec()
>`env::var("CARGO")` in order to run `cargo locate-project`.
>
>This commit adds a crate override to proc-macro-crate which simply writes the
>path to buildPlatform.cargo into the proc-macro-crate sources.
>
>This way we don't need to set `env.CARGO` for every build that depends on
>proc-macro-crate -- if we do that, the $CARGO environment variable would be
>visible to the entire build.  This could potentially lead to incredibly
>hard-to-troubleshoot heisenbugs if there is some other crate that expects
>`env::var("CARGO")` to exist -- that other crate would mysteriously work only
>in projects that use proc-macro-crate but not anywhere else!
>---
> pkgs/build-support/rust/default-crate-overrides.nix | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
>diff --git a/pkgs/build-support/rust/default-crate-overrides.nix b/pkgs/build-support/rust/default-crate-overrides.nix
>index d8f1bfaf4447..368753d73c84 100644
>--- a/pkgs/build-support/rust/default-crate-overrides.nix
>+++ b/pkgs/build-support/rust/default-crate-overrides.nix
>@@ -41,6 +41,7 @@
> , automake
> , libtool
> , seatd # =libseat
>+, buildPackages
> , ...
> }:
>
>@@ -320,4 +321,16 @@ in
>     buildInputs = [ atk ];
>   };
>
>+  # Assumes it can run Command::new(env::var("CARGO")).arg("locate-project")
>+  # https://github.com/bkchr/proc-macro-crate/blame/master/src/lib.rs#L244
>+  proc-macro-crate = attrs: lib.optionalAttrs (lib.versionAtLeast attrs.version "2.0") {
>+    prePatch = (attrs.prePatch or "") + ''
>+      substituteInPlace \
>+        src/lib.rs \
>+        --replace-fail \
>+        'env::var("CARGO").map_err(|_| Error::CargoEnvVariableNotSet)?' \
>+        '"${lib.getBin buildPackages.cargo}/bin/cargo"'
>+    '';
>+  };
>+
> }
>-- 
>2.44.1
Reply to thread Export thread (mbox)