Make #[files(...)] work on Windows#322
Merged
la10736 merged 2 commits intola10736:masterfrom Jul 26, 2025
Merged
Conversation
The resolver produces canonicalized paths, which have the verbatim path prefix "\\?\" on Windows. This caused the calculation of relative paths to break, resulting in strange test names being generated. As a workaround, canonicalize the base path as well, so that it gets the prefix, too. This makes relative path resolution work again. As a consequence, though, we need to ignore not found errors during canonicalization. Some tests use fake resolvers which produce non-existing paths. Ignoring not found errors makes them pass. Also, fix the tests so that they work on Windows. There have been many hard-coded slashes, and often, paths have been injected into contexts where backslashes need to be escaped, such as in TOML strings, regular expressions, or Rust code. Signed-off-by: Tom Wieczorek <tom@bibbu.net>
Signed-off-by: Tom Wieczorek <tom@bibbu.net>
la10736
approved these changes
Jul 26, 2025
Comment on lines
+41
to
+51
| env: | ||
| RSTEST_TEST_CHANNEL: stable | ||
| run: cargo test --all --verbose | ||
| - name: Run tests beta | ||
| run: RSTEST_TEST_CHANNEL=beta cargo test --all --verbose | ||
| env: | ||
| RSTEST_TEST_CHANNEL: beta | ||
| run: cargo test --all --verbose | ||
| - name: Run tests nightly | ||
| run: RSTEST_TEST_CHANNEL=nightly cargo test --all --verbose | ||
| env: | ||
| RSTEST_TEST_CHANNEL: nightly | ||
| run: cargo test --all --verbose |
Comment on lines
+19
to
+23
| strategy: | ||
| matrix: | ||
| runs-on: | ||
| - ubuntu-latest | ||
| - windows-latest |
Owner
There was a problem hiding this comment.
I'm trying to avoid windows at all... but you're right, I really need it.
Comment on lines
+8
to
+15
| const SRC_LIB_RS: &str = { | ||
| const SEP: u8 = std::path::MAIN_SEPARATOR as u8; | ||
| const SRC_LIB_RS: [u8; 11] = [ | ||
| SEP, b's', b'r', b'c', SEP, b'l', b'i', b'b', b'.', b'r', b's', | ||
| ]; | ||
| unsafe { std::str::from_utf8_unchecked(&SRC_LIB_RS) } | ||
| }; | ||
|
|
Owner
There was a problem hiding this comment.
Sure there isn't any simpler way to make a portable static path? Maybe use OnceLock or a function to get it is better, it's test code: performance is a detail against readability.
Comment on lines
589
to
+591
| let base_dir = match refs.base_dir()? { | ||
| Some(mut p) => { | ||
| if p.is_relative() { | ||
| p = default_base_dir.join(p); | ||
| } | ||
| p.canonicalize().map_err(|e| { | ||
| refs.glob[0].error(&format!("Cannot canonicalize base dir due {e}")) | ||
| })? | ||
| } | ||
| Some(p) if p.is_relative() => default_base_dir.join(p), | ||
| Some(p) => p, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The resolver produces canonicalized paths, which have the verbatim path prefix
\\?\on Windows. This caused the calculation of relative paths to break, resulting in strange test names being generated.As a workaround, canonicalize the base path as well, so that it gets the prefix, too. This makes relative path resolution work again. As a consequence, though, we need to ignore not found errors during canonicalization. Some tests use fake resolvers which produce non-existing paths. Ignoring not found errors makes them pass.
Also, fix the tests so that they work on Windows. There have been many hard-coded slashes, and often, paths have been injected into contexts where backslashes need to be escaped, such as in TOML strings, regular expressions, or Rust code.
Fixes #287.