forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ff64cf
commit 40e5863
Showing
34 changed files
with
2,233 additions
and
81 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
curl http://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz | \ | ||
tar xJf - | ||
export PATH=`pwd`/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-14.04/bin:$PATH | ||
|
||
# FIXME: uncomment this line and remove the next | ||
#git clone https://github.com/cranestation/reference-sysroot-wasi | ||
git clone /tmp/wut reference-sysroot-wasi | ||
|
||
cd reference-sysroot-wasi | ||
git reset --hard d5a609fe63926533e1054e539ba5f2693d51bdf5 | ||
make -j$(nproc) INSTALL_DIR=/wasm32-unknown-wasi | ||
make install INSTALL_DIR=/wasm32-unknown-wasi | ||
|
||
cd .. | ||
rm -rf reference-sysroot-wasi | ||
rm -rf clang+llvm* |
Submodule reference-sysroot-wasi
added at
d5a609
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
//! The `wasm32-unknown-wasi` target is a new and still (as of March 2019) | ||
//! experimental target. The definition in this file is likely to be tweaked | ||
//! over time and shouldn't be relied on too much. | ||
//! | ||
//! The `wasi` target is a proposal to define a standardized set of syscalls | ||
//! that WebAssembly files can interoperate with. This set of syscalls is | ||
//! intended to empower WebAssembly binaries with native capabilities such as | ||
//! filesystem access, network access, etc. | ||
//! | ||
//! FIXME: insert link to proposal here | ||
//! | ||
//! The Rust target definition here is interesting in a few ways. We want to | ||
//! serve two use cases here with this target: | ||
//! | ||
//! * First, we want Rust usage of the target to be as hassle-free as possible, | ||
//! ideally avoiding the need to configure and install a local | ||
//! wasm32-unknown-wasi toolchain. | ||
//! | ||
//! * Second, one of the primary use cases of LLVM's new wasm backend and the | ||
//! wasm support in LLD is that any compiled language can interoperate with | ||
//! any other. To that the `wasm32-unknown-wasi` target is the first with a | ||
//! viable C standard library and sysroot common definition, so we want Rust | ||
//! and C/C++ code to interoperate when compiled to `wasm32-unknown-unknown`. | ||
//! | ||
//! You'll note, however, that the two goals above are somewhat at odds with one | ||
//! another. To attempt to solve both use cases in one go we define a target | ||
//! that (ab)uses the `crt-static` target feature to indicate which one you're | ||
//! in. | ||
//! | ||
//! ## No interop with C required | ||
//! | ||
//! By default the `crt-static` target feature is enabled, and when enabled | ||
//! this means that the the bundled version of `libc.a` found in `liblibc.rlib` | ||
//! is used. This isn't intended really for interoperation with a C because it | ||
//! may be the case that Rust's bundled C library is incompatible with a | ||
//! foreign-compiled C library. In this use case, though, we use `rust-lld` and | ||
//! some copied crt startup object files to ensure that you can download the | ||
//! wasi target for Rust and you're off to the races, no further configuration | ||
//! necessary. | ||
//! | ||
//! All in all, by default, no external dependencies are required. You can | ||
//! compile `wasm32-unknown-wasi` binaries straight out of the box. You can't, | ||
//! however, reliably interoperate with C code in this mode (yet). | ||
//! | ||
//! ## Interop with C required | ||
//! | ||
//! For the second goal we repurpose the `target-feature` flag, meaning that | ||
//! you'll need to do a few things to have C/Rust code interoperate. | ||
//! | ||
//! 1. All Rust code needs to be compiled with `-C target-feature=-crt-static`, | ||
//! indicating that the bundled C standard library in the Rust sysroot will | ||
//! not be used. | ||
//! | ||
//! 2. If you're using rustc to build a linked artifact then you'll need to | ||
//! specify `-C linker` to a `clang` binary that supports | ||
//! `wasm32-unknown-wasi` and is configured with the `wasm32-unknown-wasi` | ||
//! sysroot. This will cause Rust code to be linked against the libc.a that | ||
//! the specified `clang` provides. | ||
//! | ||
//! 3. If you're building a staticlib and integrating Rust code elsewhere, then | ||
//! compiling with `-C target-feature=-crt-static` is all you need to do. | ||
//! | ||
//! You can configure the linker via Cargo using the | ||
//! `CARGO_TARGET_WASM32_UNKNOWN_WASI_LINKER` env var. Be sure to also set | ||
//! `CC_wasm32-unknown-wasi` if any crates in the dependency graph are using | ||
//! the `cc` crate. | ||
//! | ||
//! ## Remember, this is all in flux | ||
//! | ||
//! The wasi target is **very** new in its specification. It's likely going to | ||
//! be a long effort to get it standardized and stable. We'll be following it as | ||
//! best we can with this target. Don't start relying on too much here unless | ||
//! you know what you're getting in to! | ||
use super::wasm32_base; | ||
use super::{LinkerFlavor, LldFlavor, Target}; | ||
|
||
pub fn target() -> Result<Target, String> { | ||
let mut options = wasm32_base::options(); | ||
|
||
options | ||
.pre_link_args | ||
.entry(LinkerFlavor::Gcc) | ||
.or_insert(Vec::new()) | ||
.push("--target=wasm32-unknown-wasi".to_string()); | ||
|
||
// When generating an executable be sure to put the startup object at the | ||
// front so the main function is correctly hooked up. | ||
options.pre_link_objects_exe_crt.push("crt1.o".to_string()); | ||
|
||
// Right now this is a bit of a workaround but we're currently saying that | ||
// the target by default has a static crt which we're taking as a signal | ||
// for "use the bundled crt". If that's turned off then the system's crt | ||
// will be used, but this means that default usage of this target doesn't | ||
// need an external compiler but it's still interoperable with an external | ||
// compiler if configured correctly. | ||
options.crt_static_default = true; | ||
options.crt_static_respected = true; | ||
|
||
Ok(Target { | ||
llvm_target: "wasm32-unknown-wasi".to_string(), | ||
target_endian: "little".to_string(), | ||
target_pointer_width: "32".to_string(), | ||
target_c_int_width: "32".to_string(), | ||
target_os: "unknown".to_string(), | ||
target_env: "wasi".to_string(), | ||
target_vendor: "unknown".to_string(), | ||
data_layout: "e-m:e-p:32:32-i64:64-n32:64-S128".to_string(), | ||
arch: "wasm32".to_string(), | ||
linker_flavor: LinkerFlavor::Lld(LldFlavor::Wasm), | ||
options, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//! WASI-specific definitions | ||
#![stable(feature = "raw_ext", since = "1.1.0")] | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub use crate::sys::ext::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::alloc::{GlobalAlloc, Layout, System}; | ||
use crate::ptr; | ||
use crate::sys_common::alloc::{MIN_ALIGN, realloc_fallback}; | ||
use libc; | ||
|
||
#[stable(feature = "alloc_system_type", since = "1.28.0")] | ||
unsafe impl GlobalAlloc for System { | ||
#[inline] | ||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { | ||
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { | ||
libc::malloc(layout.size()) as *mut u8 | ||
} else { | ||
libc::aligned_alloc(layout.size(), layout.align()) as *mut u8 | ||
} | ||
} | ||
|
||
#[inline] | ||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { | ||
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { | ||
libc::calloc(layout.size(), 1) as *mut u8 | ||
} else { | ||
let ptr = self.alloc(layout.clone()); | ||
if !ptr.is_null() { | ||
ptr::write_bytes(ptr, 0, layout.size()); | ||
} | ||
ptr | ||
} | ||
} | ||
|
||
#[inline] | ||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { | ||
libc::free(ptr as *mut libc::c_void) | ||
} | ||
|
||
#[inline] | ||
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { | ||
if layout.align() <= MIN_ALIGN && layout.align() <= new_size { | ||
libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8 | ||
} else { | ||
realloc_fallback(self, ptr, layout, new_size) | ||
} | ||
} | ||
} |
Oops, something went wrong.