-
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
Fix target for doc test cross compilation #8094
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (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. |
Thanks! It seems like Also, can you add a test for this? There are some examples in |
|
there is a similar bug #71002 in |
Cargo's public API isn't stable, so each release is a breaking change. |
I played around with this and it seems to me that removing those two attribute results in messy/more complex code, so imho it's not worth removing them. |
Hm, ok, I see that doctests have the unusual behavior that Perhaps add a comment explaining that, perhaps along the lines of "Use Let me know if you have any issues adding the test. |
okay so the fix in rustdoc got merged this morning, so I'm guessing it should be in the next nightly version. I'll try adding the tests tomorrow (and the comment regarding |
tests/testsuite/cross_compile.rs
Outdated
let target = cross_compile::alternate(); | ||
|
||
// This tests the library and runs the doc tests. | ||
p.cargo("test -v -Z doctest-xcompile --target") | ||
.arg(&target) |
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.
I think this should be using a json spec target, since that's what this PR is fixing. I think it would be best for it to go in the custom_target.rs
module with the other json spec tests.
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.
yeah that makes sense not sure why I missed that
the custom targets obviously can't use std, so exiting cleanly is a bit of a challenge. the only way I can think of right now is by using inline assembly and manually calling the system calls to exit. the downside of this approach is that it wouldn't be cross platform |
Hm, I'm wondering, are you somehow using json specs to build std? I'm having a hard time imagining an environment where these kinds of tests would even work. (I'm only familiar with using specs with no_std.) |
I'm using it for my os kernel using the bootimage/bootloader crates which procss the compiled binaries into a disk image |
Can you say more of how that would work? Without std, I don't think the tests will work (maybe with a custom test runner, but those don't work with rustdoc afaik). |
correct. i'm using custom test frameworks for normal tests. doctests are actually just small programs that all get compiled and executed individually. usually rustdoc wraps the code in a main method, but if it detects that you wrote your own, it will use that instead. that way you can also use outer attributes like #![no_std] or use extern crate. so in my case I have some hidden code in the doctests that runs the os initialization and the os uses qemu's exit decice feature to stop itself and signal whether the tests ran successfully. if i remember correctly i think i managed to get it to work at one point by manually fixing all the target path bugs. |
That is an impressive level of dedication to get doctests working! 😄 Considering that getting an actual doctest working will likely be very difficult, perhaps it should just have a test that cargo passes the correct // Ensure that the correct style of flag is passed to --target with doc tests.
p.cargo("test --doc --target src/../custom-target.json -v -Zdoctest-xcompile")
.masquerade_as_nightly_cargo()
.with_stderr_contains("[RUNNING] `rustdoc [..]--target [..]foo/custom-target.json[..]")
.run(); with the goal just to check that it passes the correct form of |
sounds good to me |
Thanks! |
📌 Commit e5d9b03 has been approved by |
☀️ Test successful - checks-azure |
Update cargo, rls ## cargo 17 commits in ebda5065ee8a1e46801380abcbac21a25bc7e755..8751eb3010d4cdb5329b5a6bd2b6d765c95b0dca 2020-04-16 14:28:43 +0000 to 2020-04-21 18:04:35 +0000 - Uplift windows gnu DLL import libraries. (rust-lang/cargo#8141) - Add windows-gnu CI and fix tests (rust-lang/cargo#8139) - Several updates to token/index handling. (rust-lang/cargo#7973) - Add `resolver` opt-in for new feature resolver. (rust-lang/cargo#8129) - Improve error message when running `cargo install .` (rust-lang/cargo#8137) - fix mem replace unused (rust-lang/cargo#8138) - Change `-Cembed-bitcode=no` use to `-Cbitcode-in-rlib=no`. (rust-lang/cargo#8134) - Refactor BuildContext (rust-lang/cargo#8068) - Rename allows_underscores to allows_dashes. (rust-lang/cargo#8135) - Fixed a needless borrow. (rust-lang/cargo#8130) - Add link to changelog in the Cargo book. (rust-lang/cargo#8126) - Fix target for doc test cross compilation (rust-lang/cargo#8094) - Add note about .cargo/config support. (rust-lang/cargo#8125) - Fix pdb uplift when executable has dashes. (rust-lang/cargo#8123) - Hint upgrading for future edition keys (rust-lang/cargo#8122) - Use some fs shorthand functions. (rust-lang/cargo#8124) - Update documentation to mention "config.toml" instead of "config" (rust-lang/cargo#8121) ## rls 1 commits in 2659cbf14bfb0929a16d7ce9b6858d0bb286ede7..7de2a1f299f8744ffe109139f9f1fdf28bfec909 2020-04-14 22:07:24 +0200 to 2020-04-19 22:41:55 +0000 - Update cargo (rust-lang/rls#1663)
Compilation::target
only contains the shortened file name, but we need to pass the full path to rustdoc