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

Initial emscripten work #30453

Closed
wants to merge 3 commits into from
Closed

Conversation

brson
Copy link
Contributor

@brson brson commented Dec 18, 2015

Add the asmjs-unknown-emscripten triple. Add cfgs to libs. target_arch = "asmjs". target_os = "emscripten".

Backtraces, and the compilation of libbacktrace for asmjs, are disabled.

This port doesn't use jemalloc so, like pnacl, it disables jemalloc for all targets in the configure file.

It updates libc to not link to -m and -rt since all emscripten runtime components are part of libc. Emscripten libc is musl.

It disables stack protection.

This adds a weird new target option: obj_is_bitcode. This tells trans::back::write not to LLVM codegen to create .o files but to put LLMV bitcode in .o files. Emscripten's emcc supports .o in this format, and this is, I think, slightly easier than making rlibs work without .o files.

Note this badness where the makefiles depend on the EMSCRIPTEN environment variable.

Depends on rust-lang/libc#107.

This isn't enough to compile code with emscripten. It still needs 4 patches to add emscripten's LLVM fork to the tree. But note that there are bugs in that fork that cause even hello.rs not to build at the moment.

cc @kripken

@rust-highfive
Copy link
Collaborator

r? @jroesch

(rust_highfive has picked a reviewer for you, use r? to override)

@brson
Copy link
Contributor Author

brson commented Dec 18, 2015

cc @rust-lang/compiler because of the new target option.

@brson
Copy link
Contributor Author

brson commented Dec 18, 2015

r? @alexcrichton

@tomaka
Copy link
Contributor

tomaka commented Dec 18, 2015

The libstd/rand/os.rs file also needs some changes.

Since emscripten is considered as unix the code will try to open /dev/urandom, which is unavailable. The problem is only detectable at runtime, and I'm wondering if there are other similar cases.

Unfortunately this is pretty important because creating a hashmap uses this code.

@tomaka
Copy link
Contributor

tomaka commented Dec 18, 2015

I just found out this issue: emscripten-core/emscripten#2439 which claims that /dev/urandom is now emulated.
That's weird because I updated my version of the emscripten SDK right before trying the branch.

@nikomatsakis
Copy link
Contributor

@brson did you add a feature flag or something for the new target? do we want one? I didn't see it in the patch, but I didn't really look that closely.

@alexcrichton
Copy link
Member

The libc changes look good to me (just a doc fix needed to get them pushed), and the LLVM changes also look pretty innocuous. When paired with #30448 it may "just work" as that updates to LLVM 3.8.

Definitely looking forward to getting a builder up and running executing the test suite here, in theory it shouldn't be too hard as we've at least got Android to work off! (e.g. android is running target-only tests in a weird fashion today already).

CFG_JEMALLOC_CFLAGS_asmjs-unknown-emscripten := -m32 $(CFLAGS)
# NB: The EMSCRIPTEN environment variable is set by the emscripten SDK.
# This is only needed here to so the compiler-rt build can find unwind.h,
# but the asmjs target *doesn't even link to compiler-rt*.
Copy link
Member

Choose a reason for hiding this comment

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

There's a custom target option to disable compiler-rt, so perhaps we could avoid building compiler-rt and avoid linking it entirely?

Copy link
Member

Choose a reason for hiding this comment

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

Oh wait it looks like no_compiler_rt is already set, I wonder if we could avoid building compiler-rt like libbacktrace is avoided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll look into it. I punted on it last time I looked at rt.mk just because that file was so difficult.

@alexcrichton
Copy link
Member

Looks good to me!

r=me when the stars are aligned (e.g. libc is landed and this is rebased)

@bors
Copy link
Contributor

bors commented Dec 19, 2015

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

@brson
Copy link
Contributor Author

brson commented Dec 21, 2015

@nikomatsakis No, I did not add a feature flag. It's not something we've done before for targets.

@brson brson force-pushed the emscripten-upstream branch from 8d00b67 to e0d8802 Compare December 21, 2015 23:39
Backtraces, and the compilation of libbacktrace for asmjs, are disabled.

This port doesn't use jemalloc so, like pnacl, it disables jemalloc *for all targets*
in the configure file.

It updates libc to not link to -m and -rt since all emscripten runtime components
are part of libc. Emscripten libc is musl.

It disables stack protection.
This tells trans::back::write not to LLVM codegen to create .o
files but to put LLMV bitcode in .o files.

Emscripten's emcc supports .o in this format, and this is,
I think, slightly easier than making rlibs work without .o
files.
@brson brson force-pushed the emscripten-upstream branch from e0d8802 to b723bad Compare December 22, 2015 18:01
@brson
Copy link
Contributor Author

brson commented Dec 22, 2015

@alexcrichton r? I've added another commit that uses alloc_system in stage0 to make --disable-jemalloc work

@@ -1 +1 @@
Subproject commit f84e30927284b0c500ed3eaf09e8e159da20ddaf
Subproject commit e24a1a025a1f214e40eedafe3b9c7b1d69937922
Copy link
Member

Choose a reason for hiding this comment

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

Accidental update?

@alexcrichton
Copy link
Member

Looks like two perhaps spurious updates to submodules, but otherwise r=me

@brson
Copy link
Contributor Author

brson commented Dec 22, 2015

std doesn't build after the rebase either

@brson
Copy link
Contributor Author

brson commented Dec 28, 2015

I'm going to close this until I get the 32-bit musl libc bindings correct.

@brson brson closed this Dec 28, 2015
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.

7 participants