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

-Clink-args=resources.res fails in 1.82 #131995

Closed
printfn opened this issue Oct 21, 2024 · 5 comments
Closed

-Clink-args=resources.res fails in 1.82 #131995

printfn opened this issue Oct 21, 2024 · 5 comments
Labels
C-bug Category: This is a bug.

Comments

@printfn
Copy link
Contributor

printfn commented Oct 21, 2024

Code

In my .cargo/config.toml file I have:

[target.x86_64-pc-windows-msvc]
rustflags = [
    "-Clink-args=../../../icon/resources.res",
]

This used to work in Rust 1.81 but broke on 1.82.

Instead, this happened: See error message below

Minimal reproduction: https://github.com/printfn/repro/tree/rust-link-args

Version it worked on

It most recently worked on: 1.81

Version with regression

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-pc-windows-msvc
release: 1.82.0
LLVM version: 19.1.1

Detailed error

Error

cargo run
   Compiling repro v0.1.0 (C:\Users\print\repro\cli)
error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.41.34120\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\print\\AppData\\Local\\Temp\\rustcXlOPFN\\symbols.o" "C:\\Users\\print\\repro\\target\\debug\\deps\\repro.26qtrl3wfp1ut4mm4u3lrj0wm.rcgu.o" "C:\\Users\\print\\repro\\target\\debug\\deps\\repro.2kzymqvj3183xbugivmrarp69.rcgu.o" "C:\\Users\\print\\repro\\target\\debug\\deps\\repro.2o95soo3fx3kew44tvfx0kn94.rcgu.o" "C:\\Users\\print\\repro\\target\\debug\\deps\\repro.37h2v349ylr35l522jwmg7jwe.rcgu.o" "C:\\Users\\print\\repro\\target\\debug\\deps\\repro.8ru88bk8gp4zihobsrx5sncqc.rcgu.o" "C:\\Users\\print\\repro\\target\\debug\\deps\\repro.bbgwzs8uveanm9xqmy3pk3bhj.rcgu.o" "C:\\Users\\print\\repro\\target\\debug\\deps\\repro.77iorrjxaxmlihy8uzl1njjbm.rcgu.o" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-2df1f22abef96888.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-7fa781213a0698f8.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libwindows_targets-2440cb72ce7deb9b.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-f04b9120076f20fa.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-b521ee511095af2f.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-124aa6c4c6ef4b4c.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-c86a42f7194744c8.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-a416069596473508.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-e246a9218bd1ed0e.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-8f9b5fcbcd27c22e.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-65178e86c6c71ba8.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-fbeb171b69c59b37.rlib" "C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-e3a3e7896142045d.rlib" "kernel32.lib" "kernel32.lib" "advapi32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "dbghelp.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/OUT:C:\\Users\\print\\repro\\target\\debug\\deps\\repro.exe" "/OPT:REF,NOICF" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NATVIS:C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\print\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis" "../../../icon/resources.res"
  = note: LINK : fatal error LNK1181: cannot open input file '..\..\..\icon\resources.res'␍


error: could not compile `repro` (bin "repro") due to 1 previous error

If I instead run cargo +1.81 build it succeeds.

Bisection

searched nightlies: from nightly-2024-07-20 to nightly-2024-08-30
regressed nightly: nightly-2024-08-04
searched commit range: fd8d6fb...64ebd39
regressed commit: edc4dc3

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-pc-windows-msvc
Reproduce with:

cargo bisect-rustc --start=1.81.0 --end=2024-08-30

Bisects to #128370

@printfn printfn added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Oct 21, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-untriaged Untriaged performance or correctness regression. labels Oct 21, 2024
@bjorn3
Copy link
Member

bjorn3 commented Oct 21, 2024

Does it work if you pass the full path to the resources.res file?

@ChrisDenton
Copy link
Member

ChrisDenton commented Oct 21, 2024

I think it worked by accident previously. This should probably be done by adding a parent directory to the search path. E.g.:

[target.x86_64-pc-windows-msvc]
rustflags = [
    "-Clink-args=resources.res",
    "-L./icon",
]

Or maybe use a build script to get the path so the argument isn't being passed to everything in the build.

@printfn
Copy link
Contributor Author

printfn commented Oct 21, 2024

I've now made a minimum reproduction here: https://github.com/printfn/repro/tree/rust-link-args

Does it work if you pass the full path to the resources.res file?

Changing it to an absolute file path like -Clink-args=C:/Users/user/repro/icon/resources.res works, although I'd prefer being able to continue using a relative path so it's not specific to where the repository is located.

Changing it to

[target.x86_64-pc-windows-msvc]
rustflags = [
    "-Clink-args=resources.res",
    "-L./icon",
]

causes it to work in my minimal repro, but if I add a dependency with a build script (e.g. cargo add serde --features derive) it no longer works. Example code here: https://github.com/printfn/repro/tree/rust-link-args-serde.

@ChrisDenton
Copy link
Member

I guess the current working directory changes for every crate. You could try a build script:

// build.rs
fn main() {
    println!("cargo::rustc-link-arg-bins=icon/resources.res");
}

@printfn
Copy link
Contributor Author

printfn commented Oct 23, 2024

Thanks, a build script works and is probably cleaner anyway.

I guess this resolves my issue, though it's still a bit unfortunate that this broke with a minor Rust update.

@printfn printfn closed this as completed Oct 23, 2024
@apiraino apiraino removed regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 23, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

6 participants