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

Add Emscripten-specific linker #39490

Merged
merged 3 commits into from
Feb 11, 2017
Merged

Add Emscripten-specific linker #39490

merged 3 commits into from
Feb 11, 2017

Conversation

RReverser
Copy link
Contributor

Emscripten claims to accept most GNU linker options, but in fact most of -Wl,... are useless for it and instead it requires some additional special options which are easier to handle in a separate trait.

Currently added:

TODO (in future PR): dynamic linking via SIDE_MODULE / MAIN_MODULE mechanism.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nrc (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.

@RReverser
Copy link
Contributor Author

r? @brson @alexcrichton

@rust-highfive rust-highfive assigned brson and unassigned nrc Feb 3, 2017
@RReverser
Copy link
Contributor Author

Ah, so this command assigns only one reviewer at a time. This is my first PR, so I might have missed something. I'll be away for the weekend, but please do leave comments if something needs to be changed and I'll fix it as soon as I'm back.

@alexcrichton
Copy link
Member

This looks great to me, thanks for the PR! I'll leave the final review to @brson though who's our "Emscripten czar"

It looks like there may also be a tidy error on Travis which needs to be fixed?

@RReverser
Copy link
Contributor Author

Indeed, also just noticed a minor whitespace glitch.

@RReverser
Copy link
Contributor Author

Both should be fixed now.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 4, 2017

📌 Commit db2df7d has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Feb 5, 2017

☔ The latest upstream changes (presumably #39563) made this pull request unmergeable. Please resolve the merge conflicts.

@RReverser
Copy link
Contributor Author

Should I rebase on top of @pepyakin's changes now or wait for @brson's review?

@alexcrichton
Copy link
Member

Ah if you want to go ahead and rebase I can r+

@RReverser
Copy link
Contributor Author

Done. (TIL Github has conflict resolving UI, is that something new? I don't think I saw it before)

@RReverser
Copy link
Contributor Author

No, wait, it didn't merge cleanly, I'll better repeat later from my laptop.

@@ -435,6 +435,7 @@ impl Default for TargetOptions {
is_like_android: false,
is_like_emscripten: false,
is_like_msvc: false,
is_like_emscripten: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is set in two places, maybe a merge conflict gone wrong?

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, as said above. Previous PR had exactly same changes as mine too :(

@RReverser
Copy link
Contributor Author

Should be merging cleanly now.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 6, 2017

📌 Commit 82b5a09 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Feb 6, 2017

⌛ Testing commit 82b5a09 with merge 1c193bb...

@bors
Copy link
Contributor

bors commented Feb 6, 2017

💔 Test failed - status-travis

@RReverser
Copy link
Contributor Author

That's something new...

@RReverser
Copy link
Contributor Author

Well emscripten task worked after rebase, so 🤷‍♂️

@alexcrichton @brson Could you please take a look while it's not broken again? :)

@alexcrichton
Copy link
Member

@bors: r+

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 10, 2017

📌 Commit 908ed36 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Feb 10, 2017

⌛ Testing commit 908ed36 with merge 912ff3a...

@bors
Copy link
Contributor

bors commented Feb 10, 2017

💔 Test failed - status-travis

@RReverser
Copy link
Contributor Author

RReverser commented Feb 10, 2017

@alexcrichton Just to reconfirm - when you did r+ and @bors says "Commit 908ed36 has been approved by alexcrichton" and "Testing commit 908ed36 with merge 912ff3a..." - does it mean that all commits where approved and merged for testing or the previous one (aa83c3e) wasn't? Looks like both, so this is cwd missing in some another place. I'm starting to think that it could be easier to disable that optimization with separate memory file rather than try to deal with it. I'll try one more time though.

@alexcrichton
Copy link
Member

@RReverser ah yeah looks like you figure out the what-was-tested question I think?

IIRC this is an existing bug (#38454), so it may not be the easiest to work around (although I'm not too privvy to the intricacies of the bug here)

@RReverser
Copy link
Contributor Author

@alexcrichton Oach, I see... Will be harder to workaround if it's on Cargo side indeed. I'll see if I can, if not, I'll just disable that specific optimization for now.

@RReverser
Copy link
Contributor Author

@alexcrichton So there is memoryInitializerPrefixURL which I can set to whatever value needed. It's strange though that Emscripten doesn't default it to __dirname in Node.js environment, in which case issue wouldn't exist in the first place (perhaps worth making PR to them later too).

@RReverser
Copy link
Contributor Author

RReverser commented Feb 10, 2017

Ok, I think I'm just going to disable memory file until that issue is resolved. Fixing it in both Rust test runners and Cargo is too cumbersome at the moment.

It claims to accept most GNU linker options, but in fact most of them
have no effect and instead it requires some special options which are
easier to handle in a separate trait.

Currently added:
 - `export_symbols`: works on executables as special Emscripten case
since staticlibs/dylibs aren't compiled to JS, while exports are
required to be accessible from JS.
Fixes rust-lang#39171.
 - `optimize` - translates Rust's optimization level to Emscripten
optimization level (whether passed via `-C opt-level=...` or `-O...`).
Fixes rust-lang#36899.
 - `debuginfo` - translates debug info; Emscripten has 5 debug levels
while Rust has 3, so chose to translate `-C debuginfo=1` to `-g3`
(preserves whitespace, variable and function names for easy debugging).
Fixes rust-lang#36901.
 - `no_default_libraries` - tells Emscripten to exlude `memcpy` and co.
It's support is currently too buggy in both Rust tests and Cargo.
@RReverser
Copy link
Contributor Author

Let's hope this was the last issue.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 10, 2017

📌 Commit f35b598 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Feb 10, 2017

⌛ Testing commit f35b598 with merge 064a0ee...

bors added a commit that referenced this pull request Feb 10, 2017
Add Emscripten-specific linker

Emscripten claims to accept most GNU linker options, but in fact most of `-Wl,...` are useless for it and instead it requires some additional special options which are easier to handle in a separate trait.

Currently added:
 - `export_symbols`: works on executables as special Emscripten case since staticlibs/dylibs aren't compiled to JS, while exports are required to be accessible from JS.
Fixes #39171.
 - `optimize` - translates Rust's optimization level to Emscripten optimization level (whether passed via `-C opt-level=...` or `-O...`).
Fixes #36899.
 - `debuginfo` - translates debug info; Emscripten has 5 debug levels while Rust has 3, so chose to translate `-C debuginfo=1` to `-g3` (preserves whitespace, variable and function names for easy debugging).
Fixes #36901.
 - `no_default_libraries` - tells Emscripten to exclude `memcpy` and co.

TODO (in future PR): dynamic linking via `SIDE_MODULE` / `MAIN_MODULE` mechanism.
@RReverser
Copy link
Contributor Author

@alexcrichton Offtop question as I watch Travis logs: is it not configured to cache compiled LLVM between builds? It seems to rebuild it every time, even though LLVM is not updated between most of them.

@alexcrichton
Copy link
Member

Oh we use sccache to cache LLVM. That means we go through the rigamarole of configure-and-make, but the actual compiles take very little time. Overall an entire LLVM build (cached) should take ~4min

@RReverser
Copy link
Contributor Author

@alexcrichton Ah, I just saw that Travis uploads some artifacts in the end of the build to its own cache (?), so thought LLVM objects could be part of it too?

@alexcrichton
Copy link
Member

Nah those are just the docker images we use across builds, all of the LLVM files are stored in S3 via sccache

@RReverser
Copy link
Contributor Author

Yessss 🍾 https://travis-ci.org/rust-lang/rust/jobs/200535437

I don't fully like that we had to disable memory init file for now, but that's hopefully just a temporary measure and still better to have 95% of optimizations out of the box than none :)

@bors
Copy link
Contributor

bors commented Feb 11, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 064a0ee to master...

@bors bors merged commit f35b598 into rust-lang:master Feb 11, 2017
@alexcrichton
Copy link
Member

🌮

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants