diff --git a/packages/cli/src/build/request.rs b/packages/cli/src/build/request.rs index 1fd53edd56..4a116173bc 100644 --- a/packages/cli/src/build/request.rs +++ b/packages/cli/src/build/request.rs @@ -861,6 +861,20 @@ impl BuildRequest { let mut custom_linker = cargo_config.linker(triple.to_string()).ok().flatten(); let mut rustflags = cargo_config2::Flags::default(); + // Remove "rust-lld" as a custom linker on Windows, since that is already the linker we + // default to. + if let Some(linker) = custom_linker.as_ref() { + if (linker == "rust-lld" || linker == "rust-lld.exe") && cfg!(windows) { + // When using "rust-lld.exe" as linker on windows, it still needs to have a flavor + // given to it. rustc appears to be passing `-flavor "link"` when none is set by the + // user. If no flavor is given, it fails with 'lld is a generic driver'. + // We already use the existing lld-link by default on windows, so we can simply set the + // `custom_linker` to `None` in these cases, since we end up using "lld-link" anyway + // which is the same as "rust-lld.exe -flavor link". + custom_linker = None; + } + } + // Make sure to take into account the RUSTFLAGS env var and the CARGO_TARGET__RUSTFLAGS for env in [ "RUSTFLAGS".to_string(),