brson / miri

An experimental compiler from Rust to WebAssembly (inactive - do not use)
Apache License 2.0
209 stars 15 forks source link

Does rustc need a wasm target? #35

Open eholk opened 8 years ago

eholk commented 8 years ago

The issue with isize failing on 64-bit systems that was recently fixed (#34) got me thinking, does rustc itself need to know it's compiling for Wasm? I feel like WebAssembly is really its own platform, so for example we should always use i32 for isize regardless of the host architecture. Can this be done just by having mir2wasm pass certain flags to the code it imports from rustc, or does rustc actually need to be modified to have a WebAssembly platform target?

brson commented 8 years ago

It does need a wasm platform target. I'm not sure the triple but @kripken will know (I'd expect wasm-unknown-emscripten for wasm + the emscripten runtime).

The compiler already has a target for asm.js, asmjs-unknown-emscripten. This target sets target_pointer_width = "32", target_os = "emscripten", target_arch = "asmjs". For wasm the target spec can probably be exactly the same except that target_arch = "wasm".

The best way for mir2wasm to proceed for now is probably to create its own target spec and pass that to the session config (or wherever it goes).

kripken commented 8 years ago

Should we need an LLVM target triple in this case? We are not using LLVM in this path. Or is the triple used in some other way?

brson commented 8 years ago

@kripken target triples are also how rustc thinks about targets. It may be true that mir2wasm can get by without actually defining a string that is a target triple, but mir2wasm's ultimate destiny is as a rustc backend.

brson commented 8 years ago

In rustc a target triple is shorthand for a 'target spec', and that's the thing that we really do need to define since it impacts a variety of things, like the pointer width and various definitions used for conditional compilation.

kripken commented 8 years ago

Oh ok, got it.