Skip to content

file!() returns incorrect Paths on WASM target built on Windows. #140883

Open
@andriyDev

Description

@andriyDev

Here is a minimal reproducible example: https://github.com/andriyDev/wasm-path-error

The file!() macro produces nonsensical paths for WASM built on Windows.

On Windows, file!() in src/lib.rs produces src\\lib.rs with the components ["src", "lib.rs"].

I would expect file!() to produce the same set of components on WASM. However, on WASM built on Windows, file!() in src/lib.rs produces src\\lib.rs with the components ["src\\lib.rs"].

It seems that the path is not translated appropriately from Windows to WASM.

Meta

rustc --version --verbose:

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-pc-windows-msvc
release: 1.85.0
LLVM version: 19.1.7

Additional Context

This is relevant for bevyengine/bevy#14246. We are using the file path to refer to an asset in the src directory, but due to the incorrect components, we can't remove the src prefix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.T-compilerRelevant to the compiler 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