Skip to content
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

Merged
merged 10 commits into from
Apr 17, 2020
Merged

Conversation

Freax13
Copy link
Contributor

@Freax13 Freax13 commented Apr 11, 2020

  • for target paths Compilation::target only contains the shortened file name, but we need to pass the full path to rustdoc

@rust-highfive
Copy link

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 11, 2020
@ehuss
Copy link
Contributor

ehuss commented Apr 11, 2020

Thanks!

It seems like Compilation.host and Compilation.target only exist for doc tests. Perhaps those should just be removed? Then run_doc_tests can just look at the build_config to decide what to do.

Also, can you add a test for this? There are some examples in custom_target.rs. There is documentation for writing tests in CONTRIBUTING and cargo-test-support.

@Freax13
Copy link
Contributor Author

Freax13 commented Apr 12, 2020

It seems like Compilation.host and Compilation.target only exist for doc tests. Perhaps those should just be removed? Then run_doc_tests can just look at the build_config to decide what to do.

Compilation is part of the public api though so removing host and target is technically a breaking change

@Freax13
Copy link
Contributor Author

Freax13 commented Apr 12, 2020

Also, can you add a test for this? There are some examples in custom_target.rs. There is documentation for writing tests in CONTRIBUTING and cargo-test-support.

there is a similar bug #71002 in rustdoc that needs to get patched first. when that pr is merged I can add tests

@ehuss
Copy link
Contributor

ehuss commented Apr 12, 2020

Compilation is part of the public api though so removing host and target is technically a breaking change

Cargo's public API isn't stable, so each release is a breaking change.

@ehuss ehuss added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 14, 2020
@Freax13
Copy link
Contributor Author

Freax13 commented Apr 15, 2020

It seems like Compilation.host and Compilation.target only exist for doc tests. Perhaps those should just be removed? Then run_doc_tests can just look at the build_config to decide what to do.

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.

@ehuss
Copy link
Contributor

ehuss commented Apr 15, 2020

Hm, ok, I see that doctests have the unusual behavior that --target HOST still needs to work.

Perhaps add a comment explaining that, perhaps along the lines of "Use rustc_target() to properly handle JSON spec paths.".

Let me know if you have any issues adding the test.

@Freax13
Copy link
Contributor Author

Freax13 commented Apr 15, 2020

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 rustc_target)

Comment on lines 458 to 462
let target = cross_compile::alternate();

// This tests the library and runs the doc tests.
p.cargo("test -v -Z doctest-xcompile --target")
.arg(&target)
Copy link
Contributor

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.

Copy link
Contributor Author

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

@Freax13
Copy link
Contributor Author

Freax13 commented Apr 16, 2020

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

@ehuss
Copy link
Contributor

ehuss commented Apr 16, 2020

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.)

@Freax13
Copy link
Contributor Author

Freax13 commented Apr 16, 2020

I'm using it for my os kernel using the bootimage/bootloader crates which procss the compiled binaries into a disk image

@ehuss
Copy link
Contributor

ehuss commented Apr 16, 2020

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).

@Freax13
Copy link
Contributor Author

Freax13 commented Apr 16, 2020

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.
i checked some cross compiled binaries earlier and it seems like they were normal elf files (im not sure if thats the default or if it is influenced by some config key i set). those elf files also had an entrypoint, so i was able to open them in a debugger (they pretty much instantly segfault, but thats probably caused by my kernel trying to setup memory and not because they're inherintly broken)

@ehuss
Copy link
Contributor

ehuss commented Apr 17, 2020

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 --target flag to rustdoc. So maybe in custom_target_minimal, add something like the following:

    // 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 --target. How does that sound?

@Freax13
Copy link
Contributor Author

Freax13 commented Apr 17, 2020

sounds good to me

@ehuss
Copy link
Contributor

ehuss commented Apr 17, 2020

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Apr 17, 2020

📌 Commit e5d9b03 has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Apr 17, 2020
@bors
Copy link
Collaborator

bors commented Apr 17, 2020

⌛ Testing commit e5d9b03 with merge 6d76d7c...

@bors
Copy link
Collaborator

bors commented Apr 17, 2020

☀️ Test successful - checks-azure
Approved by: ehuss
Pushing 6d76d7c to master...

@bors bors merged commit 6d76d7c into rust-lang:master Apr 17, 2020
@Freax13 Freax13 deleted the fix-target branch April 17, 2020 16:45
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 22, 2020
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)
@ehuss ehuss added this to the 1.45.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants