-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Filesearch fixes for crosses. #13450
Conversation
Thanks for looking into this! This is something that's been a thorn in our side for quite some time now. Could you split apart the second commit into a few more commits? There's quite a lot going on in there, and it'd be much easier to review if all the changes were split apart from each other. This will also need some tests before merging. There's a number of cc #12102 |
I'll have to make some extra changes to compiletest to support compiling an aux crate twice when needed (once for the host/syntax extensions, once for link). I'll need to add a tag, something like |
I've refactored the second commit into bite-ish sized chunks. As such, the core changes are ready to review. |
@alexcrichton This PR is ready for review. |
(Needs a rebase.) |
@huonw Rebased, though the tests haven't finished running locally yet. |
Whoa, this changed a lot since I last looked at it (sorry it took awhile!). Even after separation, there are quite a lot of changes going on here, and I don't think we need to deal with them all at once. I would very much like to get cross compilation working with syntax extensions, but much of the rest of this work seems only tangentially related. Can you split out this new |
Sure, but the second request poses a bit of a problem: as a requirement of removing some Frankly, I feel that this exposes a larger issue (note I'm only referring to #[macro_registrar] crates here; macro_rules! extensions obviously don't suffer from this issue): data does not cross the phase boundary. They clearly don't belong in the same crate together, so why should it even be allowed? I actually resolved to creating a RFC wherein I propose a distinct crate type for syntax extensions, but blah! When ever is there time? |
As for libmachine: I created it specifically so compiletest would not have to depend on all of libsyntax &| librustc. However, as rustc doesn't use it's own set of crates (outside syntax extensions) to find |
I don't follow why libsyntax is needed by the tests (for the target). That should be considered a bug because if I have an x86 compiler targeting arm there's no reason that an arm libsyntax should be available. |
Its a result of the fact that rustc doesn't consider syntax phase crates separate from link phase crates except during Consider this test: https://github.com/DiamondLovesYou/rust/blob/filesearch/src/test/run-pass-fulldeps/phase-syntax-link-does-resolve.rs. This test references an aux crate: https://github.com/DiamondLovesYou/rust/blob/filesearch/src/test/auxiliary/macro_crate_test.rs. Now, speaking on a strictly theoretical basis, you're right, it doesn't depend on libsyntax during link phase. However, due to rustc's lack of crate role differentiation (the issue to which I referred to in the second paragraph in #13450 (comment)), rustc stipulates target access to libsyntax, which means libsyntax needs to also be a target crate. |
That test is requesting that |
At any rate, user crates wishing to cross compile while importing crates in both phases will run into the same problems (without additional changes): libsyntax won't be available as a target crate, stipulating an additional -L argument. But back to your comment, it would defeat the whole purpose of this PR. EDIT: Well, the desired goal. I'm curious though, what, exactly, are the objections to including libsyntax in the set of TARGET_CRATES, even if only as a temporary measure util a better general solution is proposed, discussed, and ratified by the community/Rust team? |
Correction: Actually, for cross compiled syntax extension crates, without libsyntax in both HOST_CRATES && TARGET_CRATES, importing in both phases won't work at all (libsyntax won't be available for the target, even if unused). |
Hm, let me explain myself a bit more. In today's world, a crate has a dependent set of crates. These are all declared with This does not make sense for syntax extensions using procedural macros. There is rarely a need to have a runtime dependency on libsyntax. Any tests currently doing this are getting lucky, and they should not be doing this for cross compilation. In a future world, this will not be the case, but we aren't quite there yet. This patch is fixing a real problem, however, which is that when you are targeting arm form x86, you will attempt to dlopen() arm syntax extension crates. You should instead dlopen() x86 syntax extension crates. Does that make sense? There is no need to support linking to libsyntax on targets, that's not the underlying bug which I thought this was trying to fix. |
Ah, I see where you're coming from. |
added some deriving types to both.
Added convience functions to access the OS, arch, && the full triple.
Filter crates based on the crate's target triple, if present. If cross compiling, use rustc's set of crates while resolving syntax extension imports.
…'t need to import all of librustc.
to libmachine. Added convenience checks for Android triples (I apologize, I trapped myself on my own work-flow).
As per your request, @alexcrichton, I've removed libsyntax && libmachine from TARGET_CRATES and have updated the tests accordingly. |
Could you also split out the addition of |
It would be pretty rough; I wrote the core changes in How about I first push through a PR containing the libmachine & related changes and then I revisit this PR? |
I have some concerns about the necessity and implementation of If you want to submit the PR first, that's certainly ok! |
|
…hton I spotted this while working on #13450.
This allows the use of syntax extensions when cross-compiling (fixing #12102). It does this by encoding the target triple in the crate metadata and checking it when searching for files. Currently the crate triple must match the host triple when there is a macro_registrar_fn, it must match the target triple when linking, and can match either when only macro_rules! macros are used. due to carelessness, this is pretty much a duplicate of #13450.
Currently Rustc has no way to differentiate crates based on the crate's target. That is, getting Rustc to use host platform crates for syntax phase dependencies (by using -L paths) whilst also using the same filesearch paths to resolve link phase crates results in either version mismatches or multiple matching crate errors. A truly vexing problem whilst cross compiling.
To remedy this, I added a new metadata tag, tag_crate_target, and added it to the crate metadata. I also slightly modified the build pipeline so that resolving syntax extensions for crosses will search through rustc's set of crates, instead of always searching though the target set (but only while cross compiling). Additionally, while cross compiling, rustc will always reset its cstore, lest host platform dep libraries leak in.
This isn't user visible, but I also added a Triple structure, which for the most part mimics LLVM's behavior. I realize it wasn't strictly speaking necessarily, but it made working with the triple in filesearch && loader a tad bit easier.