Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty RUSTFLAGS are still set #1496

Closed
delehef opened this issue Oct 4, 2024 · 6 comments
Closed

Empty RUSTFLAGS are still set #1496

delehef opened this issue Oct 4, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@delehef
Copy link

delehef commented Oct 4, 2024

Describe the bug

Even if the computed value is empty, the RUSTFLAGS env. var. is still set when activating rust with languages.rust.enable = true;.

However, an empty RUSTFLAGS env. var. inhibits any rust flags that may have been set in .cargo/config.toml.

To reproduce
Set some rust flags in the [build] section of .cargo/config.toml, do not alter languages.rust.rustflags, and enable the rust environment with languages.rust.enable = true;.

Version

devenv 1.1.0

@delehef delehef added the bug Something isn't working label Oct 4, 2024
@domenkozar
Copy link
Member

Could you test #1498

@clotodex
Copy link
Contributor

clotodex commented Oct 7, 2024

could this be related in any way? #1419
I am thinking if this is afffecting more than just rustflags or if there are any cross-effects?

@delehef
Copy link
Author

delehef commented Oct 7, 2024

@domenkozar this unfortunately does not work, as it appears that lib.mkIf is not compatible with the environment variables creation method. However, I slightly modified your PR with the joined patch, and I made it work (at least on my machine).

diff --git a/src/modules/languages/rust.nix b/src/modules/languages/rust.nix
index dcbd03c..339088c 100644
--- a/src/modules/languages/rust.nix
+++ b/src/modules/languages/rust.nix
@@ -128,15 +128,15 @@ in
         env =
           let
             moldFlags = lib.optionalString cfg.mold.enable "-C link-arg=-fuse-ld=mold";
-          in
-          {
+          in
+          lib.attrsets.filterAttrs (_: value: (lib.stringLength value) > 0) {
             # RUST_SRC_PATH is necessary when rust-src is not at the same location as
             # as rustc. This is the case with the rust toolchain from nixpkgs.
             RUST_SRC_PATH =
               if cfg.toolchain ? rust-src
               then "${cfg.toolchain.rust-src}/lib/rustlib/src/rust/library"
               else pkgs.rustPlatform.rustLibSrc;
-            RUSTFLAGS = lib.mkIf (moldFlags != "" || cfg.rustflags != "") (lib.concatStringsSep " " (lib.filter (x: x != "") [moldFlags cfg.rustflags]));
+            RUSTFLAGS = (lib.concatStringsSep " " (lib.filter (x: x != "") [moldFlags cfg.rustflags]));
             RUSTDOCFLAGS = moldFlags;
             CFLAGS = lib.optionalString pkgs.stdenv.isDarwin "-iframework ${config.devenv.profile}/Library/Frameworks";
           };

@domenkozar
Copy link
Member

@delehef we can't dynamically filter env because that creates recursion errors.

I've pushed a fix that sets it to null, which should make sure it's not set. Can you try again?

@delehef
Copy link
Author

delehef commented Oct 7, 2024

because that creates recursion errors.

Just FYI, I tested it on my side and it didn't fail; I suppose you would need to alter env from multiple sides to see these errors come into play?

Can you try again?

This one seems to work fine :)

@domenkozar
Copy link
Member

Alright merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants