Rust -> PNaCl Cross Upstreaming

62 views
Skip to first unread message

Richard Diamond

unread,
Jun 26, 2015, 6:52:42 AM6/26/15
to native-cli...@googlegroups.com
Hey guys,

I've made a lot of progress on my GSoC 15 project, which is to port Rust to PNaCl. It was suggested by JF that I document my progress here.

At the start of this project, most of the target goals were already complete: I had a working cross compiler which could pass most of Rust's test suite. Thus, I transformed the goal from creating a working cross compiler into getting cross support for PNaCl into Rust proper. Somewhat ironically, most of the work to do for this is to remove the changes I had introduced to Rust for the port. For example, when I originally started this work 1.5ish years ago, `pnacl-llvm` was on LLVM 3.3 and was a fair bit behind the LLVM that Rust used. Rust, especially at the time, didn't support older version of LLVM than its own. So, I created and maintained a separate fork of LLVM which was a merge of `pnacl-llvm` && Rust's LLVM. Because of this separate fork, I couldn't use most of the toolchain, which resulted in me recreating the equivalent functions (ie calling `le32-nacl-ld.gold` to link bitcode) in Rust.

In no particular order:
  • Refactor the Makefiles/build system to account for the fact that not all targets/components may be available.
  • Add abstractions to `librustc_back/target` for cross compilation (ie when a special toolchain is needed).
  • Don't include compressed bitcode if the target is like PNaCl.
  • Various NaCl/Newlib idiosyncrasies in `libstd`.
  • Make `compiletest` translate PNaCl modules to NaCl modules and then use `sel_ldr` to run them.
  • Translate the crate tests before running them in `sel_ldr`.
  • Redirect many of the math related LLVM intrinsics to `libm` implementations.
  • Probably other things I'm forgetting.
Currently, my work is contained within this PR. If you'd like to try it out, get `pepper_canary` from the NaCl SDK, and configure Rust with `path/to/rust/configure --target=le32-unknown-nacl --nacl-cross-path="$NACL_SDK_ROOT" --llvm-root="$NACL_SDK_ROOT/toolchain/$($NACL_SDK_ROOT/tools/getos.py)_pnacl"` After `librustc_llvm` is built (it might fail), edit `<your machine's target triple>/rt/llvmdeps.rs` from the build directory, replacing its contents with:

#[link(name = "LLVM-3.7.0svn")]
#[link(name = "pthread")]
#[link(name = "rt")]
#[link(name = "dl")]
#[link(name = "m")]
#[cfg_attr(not(target_env = "msvc"), link(name = "c++"))]
extern {}

At time of writing, the build will fail. I'm currently tracking down a bug that Rust causes in `pnacl-llvm`, but once that's found and fixed it should succeed. After `make install`, use Cargo with `--target le32-unknown-nacl`.

I've already created a Rust wrapper for parts of the PPAPI, located here. Don't use this if you're intention is to translate straight to JS.

To translate a pexe to JS (assumes you've got the emscripten SDK already), append `.bc` to the filename, and run `emcc` on it.

I can answer any questions or issues here.
Reply all
Reply to author
Forward
0 new messages