]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #36339 - brson:emscripten-new, r=alexcrichton
authorbors <bors@rust-lang.org>
Sat, 1 Oct 2016 02:00:36 +0000 (19:00 -0700)
committerGitHub <noreply@github.com>
Sat, 1 Oct 2016 02:00:36 +0000 (19:00 -0700)
Working asmjs and wasm targets

This patch set results in a working standard library for the asmjs-unknown-emscripten and wasm32-unknown-emscripten targets. It is based on the work of @badboy and @rschulman.

It does a few things:

- Updates LLVM with the emscripten [fastcomp](https://github.com/rust-lang/llvm/pull/50) patches, which include the pnacl IR legalizer and the asm.js backend. This patch is thought not to have any significant effect on existing targets.
- Teaches rustbuild to correctly link C code with emscripten
- Updates gcc-rs to work correctly with emscripten
- Teaches rustbuild to run crate tests for emscripten with node
- Modifies Thread::new to return an error on emscripten, to facilitate debugging a common failure mode
- Modifies libtest to run in single-threaded mode for emscripten
- Ignores a host of tests that don't work yet, mostly dealing with threads and I/O
- Updates libc with wasm32 definitions (presently the same as asmjs)
- Adds a wasm32-unknown-emscripten target that feeds the output of LLVM's asmjs backend through emcc to generate wasm

Notes and caveats:

- This is only known to work with `--enable-rustbuild`.
- The wasm32 target can't be tested correctly yet because of issues in compiletest and limitations in node https://github.com/kripken/emscripten/issues/4542, but hello.rs does seem to work when run on node via the binaryen interpreter
- This requires an up to date installation of the emscripten sdk from its incoming branch
- Unwinding is very broken
- When enabling the emscripten targets jemalloc is disabled for all targets, which results in test failures for the host

Next steps are to fix the jemalloc issue, start building the two emscripten targets on the auto builders, then start producing nightlies.

https://github.com/rust-lang/rust/issues/36317 tracks work on this.

Fixes https://github.com/rust-lang/rust/issues/36515
Fixes https://github.com/rust-lang/rust/issues/36515
Fixes https://github.com/rust-lang/rust/issues/36356

1  2 
src/libstd/io/mod.rs
src/libstd/process.rs
src/libstd/thread/mod.rs

diff --combined src/libstd/io/mod.rs
index e308a2d8e0375486e9669124c38a61e740bf0417,2ba2e8de71b54066a553982cef2f32fb32b7dbed..3becc0a0c9ee17ca1886823e0ad87c0cb2c02ce0
@@@ -1264,13 -1264,15 +1264,13 @@@ pub trait BufRead: Read 
      #[stable(feature = "rust1", since = "1.0.0")]
      fn consume(&mut self, amt: usize);
  
 -    /// Read all bytes into `buf` until the delimiter `byte` is reached.
 +    /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached.
      ///
      /// This function will read bytes from the underlying stream until the
      /// delimiter or EOF is found. Once found, all bytes up to, and including,
      /// the delimiter (if found) will be appended to `buf`.
      ///
 -    /// If this reader is currently at EOF then this function will not modify
 -    /// `buf` and will return `Ok(n)` where `n` is the number of bytes which
 -    /// were read.
 +    /// If successful, this function will return the total number of bytes read.
      ///
      /// # Errors
      ///
      /// up to, and including, the delimiter (if found) will be appended to
      /// `buf`.
      ///
 -    /// If this reader is currently at EOF then this function will not modify
 -    /// `buf` and will return `Ok(n)` where `n` is the number of bytes which
 -    /// were read.
 +    /// If successful, this function will return the total number of bytes read.
      ///
      /// # Errors
      ///
@@@ -1757,6 -1761,7 +1757,7 @@@ mod tests 
      use super::repeat;
  
      #[test]
+     #[cfg_attr(target_os = "emscripten", ignore)]
      fn read_until() {
          let mut buf = Cursor::new(&b"12"[..]);
          let mut v = Vec::new();
      }
  
      #[bench]
+     #[cfg_attr(target_os = "emscripten", ignore)]
      fn bench_read_to_end(b: &mut test::Bencher) {
          b.iter(|| {
              let mut lr = repeat(1).take(10000000);
diff --combined src/libstd/process.rs
index 674b00095370efc6945aaf79ee8c60a223d9f6da,94348155779814c9ae71099d3a22aafadc05b2bf..9d21a76e81b9e41f4e39ebe1af7fba669e002aa2
@@@ -8,25 -8,7 +8,25 @@@
  // option. This file may not be copied, modified, or distributed
  // except according to those terms.
  
 -//! Working with processes.
 +//! A module for working with processes.
 +//!
 +//! # Examples
 +//!
 +//! Basic usage where we try to execute the `cat` shell command:
 +//!
 +//! ```should_panic
 +//! use std::process::Command;
 +//!
 +//! let mut child = Command::new("/bin/cat")
 +//!                         .arg("file.txt")
 +//!                         .spawn()
 +//!                         .expect("failed to execute child");
 +//!
 +//! let ecode = child.wait()
 +//!                  .expect("failed to wait on child");
 +//!
 +//! assert!(ecode.success());
 +//! ```
  
  #![stable(feature = "process", since = "1.0.0")]
  
@@@ -825,7 -807,7 +825,7 @@@ pub fn exit(code: i32) -> ! 
      ::sys::os::exit(code)
  }
  
- #[cfg(test)]
+ #[cfg(all(test, not(target_os = "emscripten")))]
  mod tests {
      use io::prelude::*;
  
diff --combined src/libstd/thread/mod.rs
index a634c8f77a45ca684513a8aa7f55b3ef64534a17,775dfababc680939491bc81ddd1dad0d393517b7..901ff98fcb3c5fa51e23b52a83e42042cbb9d0ca
  //!
  //! [`Cell`]: ../cell/struct.Cell.html
  //! [`RefCell`]: ../cell/struct.RefCell.html
 -//! [`thread_local!`]: ../macro.thread_local!.html
 +//! [`thread_local!`]: ../macro.thread_local.html
  //! [`with`]: struct.LocalKey.html#method.with
  
  #![stable(feature = "rust1", since = "1.0.0")]
@@@ -741,7 -741,7 +741,7 @@@ fn _assert_sync_and_send() 
  // Tests
  ////////////////////////////////////////////////////////////////////////////////
  
- #[cfg(test)]
+ #[cfg(all(test, not(target_os = "emscripten")))]
  mod tests {
      use any::Any;
      use sync::mpsc::{channel, Sender};