-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Try to better handle restricted crate names. #7959
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Warn on Windows about reserved target names.
- Loading branch information
commit 15ac82b677a7055c3e67fa06fd32e8446b2b377f
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| //! Tests specifically related to target handling (lib, bins, examples, tests, benches). | ||
|
|
||
| use cargo_test_support::project; | ||
|
|
||
| #[cargo_test] | ||
| fn reserved_windows_target_name() { | ||
| let p = project() | ||
| .file( | ||
| "Cargo.toml", | ||
| r#" | ||
| [package] | ||
| name = "foo" | ||
| version = "0.1.0" | ||
|
|
||
| [[bin]] | ||
| name = "con" | ||
| path = "src/main.rs" | ||
| "#, | ||
| ) | ||
| .file("src/main.rs", "fn main() {}") | ||
| .build(); | ||
|
|
||
| if cfg!(windows) { | ||
| p.cargo("check") | ||
| .with_stderr( | ||
| "\ | ||
| [WARNING] binary target `con` is a reserved Windows filename, \ | ||
| this target will not work on Windows platforms | ||
| [CHECKING] foo[..] | ||
| [FINISHED][..] | ||
| ", | ||
| ) | ||
| .run(); | ||
| } else { | ||
| p.cargo("check") | ||
| .with_stderr("[CHECKING] foo[..]\n[FINISHED][..]") | ||
| .run(); | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm can you clarify this a bit for me? How come we'd only issue this warning on windows, and how comit it applies to all targets? It should be ok to have a library called
con, right? I don't think that creates any of the bad file names?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking for only showing on Windows is: if someone wants to create an executable called
con, and they never intend for it to be used on Windows, then that would create a warning that they cannot silence. Maybe if we had the "compatibility" table we discussed at the last meeting, we could warn on all platforms and then allow the warning to be silenced by specifying that it is incompatible with windows?FWIW, I scanned all of crates.io, and didn't find any targets with a reserved name. Part of this came up with a user on Discord who had a package named
prunewith a binary namedprn, and was confused when their Windows CI failed. I don't think they've published to crates.io, though.As for libraries, in some situations rustc creates filenames like
con.tr1cof326ip8vwg.rcgu.owhich fail on windows. It also seems like it would just be a risky thing to do, and I didn't want to put in effort and complexity to handle that edge case, which is pretty far on the edge.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh for sure binaries make sense here, I was just confused about the library part. The point about crate names showing up in object files makes sense though!