Skip to content

Commit

Permalink
Merge pull request #1498 from cachix/rust-flags
Browse files Browse the repository at this point in the history
rust: set empty flags if empty
  • Loading branch information
domenkozar authored Oct 7, 2024
2 parents 9eccaee + 9a48700 commit e339e11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/modules/languages/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ in
defaultText = lib.literalExpression ''[ ]'';
description = ''
List of extra [targets](https://github.com/nix-community/fenix#supported-platforms-and-targets)
to install. Defaults to only the native target.
to install. Defaults to only the native target.
'';
};

Expand Down Expand Up @@ -128,6 +128,7 @@ in
env =
let
moldFlags = lib.optionalString cfg.mold.enable "-C link-arg=-fuse-ld=mold";
optionalEnv = cond: str: if cond then str else null;
in
{
# RUST_SRC_PATH is necessary when rust-src is not at the same location as
Expand All @@ -136,8 +137,8 @@ in
if cfg.toolchain ? rust-src
then "${cfg.toolchain.rust-src}/lib/rustlib/src/rust/library"
else pkgs.rustPlatform.rustLibSrc;
RUSTFLAGS = "${moldFlags} ${cfg.rustflags}";
RUSTDOCFLAGS = "${moldFlags}";
RUSTFLAGS = optionalEnv (moldFlags != "" || cfg.rustflags != "") (lib.concatStringsSep " " (lib.filter (x: x != "") [moldFlags cfg.rustflags]));
RUSTDOCFLAGS = optionalEnv (moldFlags != "") moldFlags;
CFLAGS = lib.optionalString pkgs.stdenv.isDarwin "-iframework ${config.devenv.profile}/Library/Frameworks";
};

Expand Down
10 changes: 10 additions & 0 deletions tests/rust/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
languages.rust.enable = true;
languages.rust.mold.enable = false;
enterTest = ''
if [ -n "$RUSTFLAGS" ]; then
echo "RUSTFLAGS is set, but it should not be"
exit 1
fi
'';
}

0 comments on commit e339e11

Please sign in to comment.