Skip to content

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

Closed

Description

@anter1

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.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 9, 2025
  2. jieyouxu commented on Mar 9, 2025

    @jieyouxu
    Member

    cc @bdbai for FYI

  3. added
    O-uwp-windows-msvcWindows targets for Universal Windows Platform (UWP) applications, using MSVC toolchain.
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 9, 2025
  4. bdbai commented on Mar 9, 2025

    @bdbai
    Contributor

    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.

  5. bdbai commented on Mar 9, 2025

    @bdbai
    Contributor

    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.

  6. added a commit that references this issue on Mar 9, 2025
    33530e4
  7. added a commit that references this issue on Mar 9, 2025
    f424ec1
  8. added a commit that references this issue on Mar 14, 2025
    2077b05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-uwp-windows-msvcWindows targets for Universal Windows Platform (UWP) applications, using MSVC toolchain.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions