-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Handle target specific outputs such as .wasm or .dll.lib #4570
Conversation
Fixes rust-lang#4500, rust-lang#4535 Until now, Cargo does not have any knowledge about target-specific output files. It relies solely on rustc for this sort of information (`rustc --print=file-names ...`). As a result, Cargo does not place some build artifacts (files) to target/{debug,release} directory. These files include *.wasm for wasm32-unknown-emscripten target and *.dll.lib for *-pc-windows-msvc cdylib target. This commit will add such knowledge to Cargo so that *.wasm and *.dll.lib will be placed in target/{debug,release} directory.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Please do not merge this; we found a problem with wasm target. See this comment for details. |
Fixes rust-lang#4535 - Do not add metadata to wasm32 bin target because generated .js will refer corresponding .wasm. - Handle different usages of "-" and "_" in .js and .wasm file names. (e.g "foo-bar.js" vs. "foo_bar.wasm") - Change file mode of cargo_rustc/context.rs (100755 -> 100644)
I added one more commit to address the problem. Now this PR is ready for merge. |
Summary of ChangesFor bin target of wasm32-unknown-emscripten
Before this PR: [package]
name = "wasm-test"
# ... % tree target/wasm32-unknown-emscripten/
target/wasm32-unknown-emscripten/
└── debug
├── build
├── deps
│ ├── wasm_test-0f5ba9409d843569.js
│ ├── wasm_test-0f5ba9409d843569.wasm
│ ├── wasm_test-0f5ba9409d843569.wasm.map
│ └── wasm_test-0f5ba9409d843569.wast
├── examples
├── incremental
├── native
├── wasm-test.d
└── wasm-test.js
6 directories, 6 files After this PR: % tree target/wasm32-unknown-emscripten/
target/wasm32-unknown-emscripten/
└── debug
├── build
├── deps
│ ├── wasm-test.js <== no metadata, hyphen
│ ├── wasm_test.wasm <== no metadata
│ ├── wasm_test.wasm.map
│ └── wasm_test.wast
├── examples
├── incremental
├── native
├── wasm_test.d
├── wasm-test.d
├── wasm-test.js
└── wasm_test.wasm <== added
6 directories, 8 files For cdylib/dylib targets of *-pc-windows-msvc
Before this PR: [package]
name = "cdylib-test"
# ...
[lib]
crate-type = ["cdylib"] PS C:\Users\tatsuya\Documents\cdylib-test> dir .\target\debug\deps\
Directory: C:\Users\tatsuya\Documents\cdylib-test\target\debug\deps
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/5/2017 06:20 PM 115200 cdylib_test.dll
-a---- 10/5/2017 06:20 PM 2141 cdylib_test.dll.exp
-a---- 10/5/2017 06:20 PM 3892 cdylib_test.dll.lib
-a---- 10/5/2017 06:20 PM 1085440 cdylib_test.pdb
PS C:\Users\tatsuya\Documents\cdylib-test> dir .\target\debug\
Directory: C:\Users\tatsuya\Documents\cdylib-test\target\debug
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/5/2017 06:20 PM .fingerprint
d----- 10/5/2017 06:20 PM build
d----- 10/5/2017 06:20 PM deps
d----- 10/5/2017 06:20 PM examples
d----- 10/5/2017 06:20 PM incremental
d----- 10/5/2017 06:20 PM native
-a---- 10/5/2017 06:20 PM 0 .cargo-lock
-a---- 10/5/2017 06:20 PM 119 cdylib_test.d
-a---- 10/5/2017 06:20 PM 115200 cdylib_test.dll After this PR:
|
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.
Nice! I've got just one small nit but otherwise this looks great to me and should be good to go. If you're extra enterprising (this is optional) I think we could tackle #4056 with this infrastructure as well, but again, that's optional!
@@ -478,9 +481,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> { | |||
// doing this eventually. | |||
let __cargo_default_lib_metadata = env::var("__CARGO_DEFAULT_LIB_METADATA"); | |||
if !unit.profile.test && | |||
(unit.target.is_dylib() || unit.target.is_cdylib()) && | |||
(unit.target.is_dylib() || unit.target.is_cdylib() || | |||
(unit.target.is_bin() && self.target_triple().starts_with("wasm32-"))) && |
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.
Could this be refactored into a dedicated method? Something like:
fn fails_to_work_with_mangled_filename(...) -> bool {
// ...
}
(just to make it a bit more clear as to the intent)
Thank you for reviewing the codes.
Ah, alright, there is another. Sure. I will take that. I have macOS environment and will have some time to spare in coming weekend. |
Nice! My thinking is that we probably just need to lift up the That actually reminds me, maybe we should lift up the pdb files produced with MSVC debug info as well? Again though, both of these are optional, we can always tackle in future PRs :) |
I did not have enough time to update this PR last weekend. I was only able to reproduce the debugger problems on macOS and Windows MSVC; no time for updating the codes. I will try to work on them in tomorrow evening (It is Monday evening now in my time zone). My impression is I can address macOS debugger problem in this PR in a couple of days, but not Windows one. I found the full-path to the PDB file is embedded in Windows binary, so I can't move the PDB to anywhere else. It seems there is a way to remove the full-path via a linker flag. But I guess we will need to change |
Ok no worries! Let's go ahead and get this in and iterate in-tree @bors: r+ |
📌 Commit f9a541b has been approved by |
…ichton Handle target specific outputs such as .wasm or .dll.lib Fixes #4500, #4535 Until now, Cargo does not have any knowledge about target-specific output files. It relies solely on rustc for this sort of information (`rustc --print=file-names ...`). As a result, Cargo does not place some build artifacts (files) to target/{debug,release} directory. These files include *.wasm for wasm32-unknown-emscripten target and *.dll.lib for *-pc-windows-msvc cdylib target. This commit will add such knowledge to Cargo so that *.wasm and *.dll.lib will be placed in target/{debug,release} directory. **EDIT**: I added [a summary of changes](#4570 (comment)). Please read it for more details of changes. **IMPORTANT** Although I added test cases for both wasm32-unknown-emscripten and *-pc-windows-msvc cdylib targets, ~I did not do manual testing on wasm32-unknown-emscripten target as I do not have an environment with emscripten installed. It will be appreciated if anybody tests this change for wasm32-unknown-emscripten target.~ **EDIT**: Tested for both wasm32-unknown-emscripten and x86_64-pc-windows-msvc. Thanks @Herschel for the help.
☀️ Test successful - status-appveyor, status-travis |
Uplift *.dSYM Fixed #4490. The solution is based on #4570. Simply adding `.dSYM` into `add_target_specific_suffixes` will cause cargo trying to actually run that `.dSYM` folder, so I've upgraded the `linkable` boolean into a 3-value enum `TargetFileType`, to tell `cargo run` and `cargo test` to avoid these debug symbol files. (I haven't checked if it can solve #4056, don't wanna mess with Spotlight 😝)
Due to rust-lang/cargo#4570, a `*.dll.lib` file is uplifted when building dynamic libraries on Windows. The current bootstrap code does not understand files with multiple extensions, and will instead assume `xxxx.dll` is the file name. This caused a `no output generated` error because it tries to search for `xxxx.dll-hash.lib` inside the `deps/` folder, while it should check for `xxxx-hash.dll.lib` instead. This PR is blocking rust-lang#45285 (Bump to 1.23 and update bootstrap).
…ck, r=alexcrichton rustbuild: Fix `no output generated` error for next bootstrap cargo. Due to rust-lang/cargo#4570, a `*.dll.lib` file is uplifted when building dynamic libraries on Windows. The current bootstrap code does not understand files with multiple extensions, and will instead assume `xxxx.dll` is the file name. This caused a `no output generated` error because it tries to search for `xxxx.dll-hash.lib` inside the `deps/` folder, while it should check for `xxxx-hash.dll.lib` instead. This PR is blocking rust-lang#45285, see rust-lang#45285 (comment) and the rest of the comments for detail.
Fixes #4500, #4535
Until now, Cargo does not have any knowledge about target-specific output files. It relies solely on rustc for this sort of information (
rustc --print=file-names ...
).As a result, Cargo does not place some build artifacts (files) to target/{debug,release} directory. These files include *.wasm for wasm32-unknown-emscripten target and *.dll.lib for *-pc-windows-msvc cdylib target.
This commit will add such knowledge to Cargo so that *.wasm and *.dll.lib will be placed in target/{debug,release} directory.
EDIT: I added a summary of changes. Please read it for more details of changes.
IMPORTANT
Although I added test cases for both wasm32-unknown-emscripten and *-pc-windows-msvc cdylib targets,
I did not do manual testing on wasm32-unknown-emscripten target as I do not have an environment with emscripten installed. It will be appreciated if anybody tests this change for wasm32-unknown-emscripten target.EDIT: Tested for both wasm32-unknown-emscripten and x86_64-pc-windows-msvc. Thanks @Herschel for the help.