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

UWP target (e.g. x86_64-uwp-windows-msvc) is broken #138257

Closed
anter1 opened this issue Mar 9, 2025 · 3 comments · Fixed by #138276
Closed

UWP target (e.g. x86_64-uwp-windows-msvc) is broken #138257

anter1 opened this issue Mar 9, 2025 · 3 comments · Fixed by #138276
Labels
C-bug Category: This is a bug. O-uwp-windows-msvc Windows targets for Universal Windows Platform (UWP) applications, using MSVC toolchain. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@anter1
Copy link

anter1 commented Mar 9, 2025

I tried to compile x86_64-uwp-windows-msvc on nightly rust using -Z build-std . I used staticlib as target type. Then I tried to link the successfully created .lib file into my exe - outside of rust ecosystem. The linker failed with this error:

error LNK2019: unresolved external symbol __imp_NtOpenFile referenced in function _ZN3std3sys3pal7windows2fs14remove_dir_all12nt_open_file17h43bb929b19188a87E

My successful cargo command which created my staticlib which is unusable in UWP is:

cargo.exe rustc --lib --target=x86_64-uwp-windows-msvc --package pkg_name --manifest-path C:/path/to/Cargo.toml -Z build-std=std,panic_abort -- -Cdefault-linker-libraries=no

The issue is due to rust's std lib using NtOpenFile function which is not available for UWP applications. This regression was introduced in bb9d5c4

The usage of the function is not guarded by the #[cfg(target_vendor = "uwp")] feature here:

c::NtOpenFile(&mut handle, access, object_attribute, &mut io_status, share, options);

The way I understand it, all uwp targets are unusable since the above mentioned commit around September 2024 because the rust's std library uses function not allowed for uwp applications.

@anter1 anter1 added the C-bug Category: This is a bug. label Mar 9, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 9, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Mar 9, 2025

cc @bdbai for FYI

@jieyouxu jieyouxu added O-uwp-windows-msvc Windows targets for Universal Windows Platform (UWP) applications, using MSVC toolchain. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 9, 2025
@bdbai
Copy link
Contributor

bdbai commented Mar 9, 2025

It looks like NtOpenFile needs a dummy implementation for UWP, same as NtCreateFile here

pub fn NtCreateFile(

Before a patch is available to fix this, a workaround will be to turn on lto and use release build only so that the staticlib will not require this symbol, given std::fs::remove_dir_all is not used anywhere in your library.

@bdbai
Copy link
Contributor

bdbai commented Mar 9, 2025

I just filed #138276 and verified locally in Visual Studio that a new UWP app was able to link against a staticlib calling std::fs::remove_dir_all.

@bors bors closed this as completed in 33530e4 Mar 9, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 9, 2025
Rollup merge of rust-lang#138276 - bdbai:fix-uwp-ntopenfile, r=ChrisDenton

Lazy load NtOpenFile for UWP

Lazily load `NtOpenFile` to allow libraries targeting UWP to build and link.

Fixes rust-lang#138257 .

r? `@ChrisDenton`
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. O-uwp-windows-msvc Windows targets for Universal Windows Platform (UWP) applications, using MSVC toolchain. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants