Skip to content

Commit

Permalink
Merge branch 'master' into feat-c-api-wasi-unordered-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Feb 2, 2021
2 parents 995a2d4 + 63acc46 commit e5d5303
Show file tree
Hide file tree
Showing 18 changed files with 499 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Run Benchmarks and upload results
on:
push:
branches:
- master
- benchmark # TODO: change it back to master once we really track the results. We commented this as speed.wasmer.io is failing

jobs:
run_benchmark:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ jobs:
- build: linux-x64
os: ubuntu-18.04
rust: 1.48
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-amd64.tar.gz'
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/11.x/linux-amd64.tar.gz'
artifact_name: 'wasmer-linux-amd64'
cross_compilation_artifact_name: 'cross_compiled_from_linux'
run_integration_tests: true
- build: macos-x64
os: macos-latest
rust: 1.48
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/darwin-amd64.tar.gz'
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/11.x/darwin-amd64.tar.gz'
artifact_name: 'wasmer-darwin-amd64'
cross_compilation_artifact_name: 'cross_compiled_from_mac'
run_integration_tests: true
Expand All @@ -62,15 +62,15 @@ jobs:
- build: windows-x64
os: windows-latest
rust: 1.48
# llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/windows-amd64.tar.gz'
# llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/11.x/windows-amd64.tar.gz'
artifact_name: 'wasmer-windows-amd64'
cross_compilation_artifact_name: 'cross_compiled_from_win'
run_integration_tests: true
- build: linux-aarch64
os: [self-hosted, linux, ARM64]
random_sccache_port: true
rust: 1.48
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/10.x/linux-aarch64.tar.gz'
llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/11.x/linux-aarch64.tar.gz'
artifact_name: 'wasmer-linux-aarch64'
run_integration_tests: false
env:
Expand Down Expand Up @@ -108,9 +108,9 @@ jobs:
mkdir ${{ env.LLVM_DIR }}
tar xf llvm.tar.gz --strip-components=1 -C ${{ env.LLVM_DIR }}
echo "${{ env.LLVM_DIR }}/bin" >> $GITHUB_PATH
echo "LLVM_SYS_100_PREFIX=${{ env.LLVM_DIR }}" >> $GITHUB_ENV
echo "LLVM_SYS_110_PREFIX=${{ env.LLVM_DIR }}" >> $GITHUB_ENV
env:
LLVM_DIR: ${{ github.workspace }}/llvm-10
LLVM_DIR: ${{ github.workspace }}/llvm-11
- name: Set up dependencies for Mac OS
run: |
brew install automake
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Added
- [#2053](https://github.com/wasmerio/wasmer/pull/2053) Implement the non-standard `wasi_get_unordered_imports` function in the C API.
- [#2072](https://github.com/wasmerio/wasmer/pull/2072) Add `wasm_config_set_target`, along with `wasm_target_t`, `wasm_triple_t` and `wasm_cpu_features_t` in the unstable C API.
- [#2059](https://github.com/wasmerio/wasmer/pull/2059) Ability to capture `stdout` and `stderr` with WASI in the C API.
- [#2040](https://github.com/wasmerio/wasmer/pull/2040) Add `InstanceHandle::vmoffsets` to expose the offsets of the `vmctx` region.
- [#2026](https://github.com/wasmerio/wasmer/pull/2010) Expose trap code of a `RuntimeError`, if it's a `Trap`.
Expand All @@ -19,6 +20,7 @@
- [#2056](https://github.com/wasmerio/wasmer/pull/2056) Change back to depend on the `enumset` crate instead of `wasmer_enumset`

### Fixed
- [#2084](https://github.com/wasmerio/wasmer/pull/2084) Avoid calling the function environment finalizer more than once when the environment has been cloned in the C API.
- [#2069](https://github.com/wasmerio/wasmer/pull/2069) Use the new documentation for `include/README.md` in the Wasmer package.
- [#2042](https://github.com/wasmerio/wasmer/pull/2042) Parse more exotic environment variables in `wasmer run`.
- [#2041](https://github.com/wasmerio/wasmer/pull/2041) Documentation diagrams now have a solid white background rather than a transparent background.
Expand Down
15 changes: 8 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ build-docs:

build-docs-capi:
cd lib/c-api/doc/deprecated/ && doxygen doxyfile
cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,jit,object-file,native,cranelift,wasi
cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,jit,object-file,native,cranelift,wasi $(capi_default_features)

# We use cranelift as the default backend for the capi for now
build-capi: build-capi-cranelift
Expand Down
1 change: 1 addition & 0 deletions lib/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ wasmer-engine-native = { version = "1.0.1", path = "../engine-native", optional
wasmer-engine-object-file = { version = "1.0.1", path = "../engine-object-file", optional = true }
wasmer-wasi = { version = "1.0.1", path = "../wasi", optional = true }
wasmer-types = { version = "1.0.1", path = "../wasmer-types" }
enumset = "1.0"
cfg-if = "1.0"
lazy_static = "1.4"
libc = { version = "^0.2", default-features = false }
Expand Down
12 changes: 12 additions & 0 deletions lib/c-api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ fn exclude_items_from_wasm_c_api(builder: Builder) -> Builder {
.exclude_item("wasi_version_t")
.exclude_item("wasm_config_set_compiler")
.exclude_item("wasm_config_set_engine")
.exclude_item("wasm_config_set_target")
.exclude_item("wasm_cpu_features_add")
.exclude_item("wasm_cpu_features_delete")
.exclude_item("wasm_cpu_features_new")
.exclude_item("wasm_cpu_features_t")
.exclude_item("wasm_module_name")
.exclude_item("wasm_module_set_name")
.exclude_item("wasm_named_extern_module")
Expand All @@ -478,6 +483,13 @@ fn exclude_items_from_wasm_c_api(builder: Builder) -> Builder {
.exclude_item("wasm_named_extern_vec_new")
.exclude_item("wasm_named_extern_vec_new_empty")
.exclude_item("wasm_named_extern_vec_new_uninitialized")
.exclude_item("wasm_target_delete")
.exclude_item("wasm_target_new")
.exclude_item("wasm_target_t")
.exclude_item("wasm_triple_delete")
.exclude_item("wasm_triple_new")
.exclude_item("wasm_triple_new_from_host")
.exclude_item("wasm_triple_t")
.exclude_item("wasmer_compiler_t")
.exclude_item("wasmer_engine_t")
.exclude_item("wat2wasm")
Expand Down
57 changes: 49 additions & 8 deletions lib/c-api/src/wasm_c_api/engine.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub use super::unstable::engine::wasm_config_set_target;
use super::unstable::target_lexicon::wasm_target_t;
use crate::error::{update_last_error, CApiError};
use cfg_if::cfg_if;
use std::sync::Arc;
Expand Down Expand Up @@ -93,6 +95,7 @@ pub struct wasm_config_t {
engine: wasmer_engine_t,
#[cfg(feature = "compiler")]
compiler: wasmer_compiler_t,
pub(super) target: Option<Box<wasm_target_t>>,
}

/// Create a new default Wasmer configuration.
Expand Down Expand Up @@ -396,7 +399,7 @@ pub unsafe extern "C" fn wasm_engine_delete(_engine: Option<Box<wasm_engine_t>>)
/// cbindgen:ignore
#[no_mangle]
pub extern "C" fn wasm_engine_new_with_config(
config: Box<wasm_config_t>,
config: Option<Box<wasm_config_t>>,
) -> Option<Box<wasm_engine_t>> {
#[allow(dead_code)]
fn return_with_error<M>(msg: M) -> Option<Box<wasm_engine_t>>
Expand All @@ -408,7 +411,9 @@ pub extern "C" fn wasm_engine_new_with_config(
});

return None;
};
}

let config = config?;

cfg_if! {
if #[cfg(feature = "compiler")] {
Expand Down Expand Up @@ -447,7 +452,13 @@ pub extern "C" fn wasm_engine_new_with_config(
wasmer_engine_t::JIT => {
cfg_if! {
if #[cfg(feature = "jit")] {
Arc::new(JIT::new(compiler_config).engine())
let mut builder = JIT::new(compiler_config);

if let Some(target) = config.target {
builder = builder.target(target.inner);
}

Arc::new(builder.engine())
} else {
return return_with_error("Wasmer has not been compiled with the `jit` feature.");
}
Expand All @@ -456,7 +467,13 @@ pub extern "C" fn wasm_engine_new_with_config(
wasmer_engine_t::NATIVE => {
cfg_if! {
if #[cfg(feature = "native")] {
Arc::new(Native::new(compiler_config).engine())
let mut builder = Native::new(compiler_config);

if let Some(target) = config.target {
builder = builder.target(target.inner);
}

Arc::new(builder.engine())
} else {
return return_with_error("Wasmer has not been compiled with the `native` feature.");
}
Expand All @@ -467,7 +484,13 @@ pub extern "C" fn wasm_engine_new_with_config(
// There are currently no uses of the object-file engine + compiler from the C API.
// So we run in headless mode.
if #[cfg(feature = "object-file")] {
Arc::new(ObjectFile::headless().engine())
let mut builder = ObjectFile::headless();

if let Some(target) = config.target {
builder = builder.target(target.inner);
}

Arc::new(builder.engine())
} else {
return return_with_error("Wasmer has not been compiled with the `object-file` feature.");
}
Expand All @@ -480,7 +503,13 @@ pub extern "C" fn wasm_engine_new_with_config(
wasmer_engine_t::JIT => {
cfg_if! {
if #[cfg(feature = "jit")] {
Arc::new(JIT::headless().engine())
let mut builder = JIT::headless();

if let Some(target) = config.target {
builder = builder.target(target.inner);
}

Arc::new(builder.engine())
} else {
return return_with_error("Wasmer has not been compiled with the `jit` feature.");
}
Expand All @@ -489,7 +518,13 @@ pub extern "C" fn wasm_engine_new_with_config(
wasmer_engine_t::NATIVE => {
cfg_if! {
if #[cfg(feature = "native")] {
Arc::new(Native::headless().engine())
let mut builder = Native::headless();

if let Some(target) = config.target {
builder = builder.target(target.inner);
}

Arc::new(builder.engine())
} else {
return return_with_error("Wasmer has not been compiled with the `native` feature.");
}
Expand All @@ -498,7 +533,13 @@ pub extern "C" fn wasm_engine_new_with_config(
wasmer_engine_t::OBJECT_FILE => {
cfg_if! {
if #[cfg(feature = "object-file")] {
Arc::new(ObjectFile::headless().engine())
let mut builder = ObjectFile::headless();

if let Some(target) = config.target {
builder = builder.target(target.inner);
}

Arc::new(builder.engine())
} else {
return return_with_error("Wasmer has not been compiled with the `object-file` feature.");
}
Expand Down
18 changes: 13 additions & 5 deletions lib/c-api/src/wasm_c_api/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ pub unsafe extern "C" fn wasm_func_new_with_env(
#[repr(C)]
struct WrapperEnv {
env: *mut c_void,
finalizer: Option<wasm_env_finalizer_t>,
};
finalizer: Arc<Option<wasm_env_finalizer_t>>,
}

// Only relevant when using multiple threads in the C API;
// Synchronization will be done via the C API / on the C side.
Expand All @@ -115,8 +115,13 @@ pub unsafe extern "C" fn wasm_func_new_with_env(

impl Drop for WrapperEnv {
fn drop(&mut self) {
if let Some(finalizer) = self.finalizer {
unsafe { (finalizer)(self.env as _) }
if let Some(finalizer) = Arc::get_mut(&mut self.finalizer)
.map(Option::take)
.flatten()
{
if !self.env.is_null() {
unsafe { (finalizer)(self.env as _) }
}
}
}
}
Expand Down Expand Up @@ -160,7 +165,10 @@ pub unsafe extern "C" fn wasm_func_new_with_env(
let function = Function::new_with_env(
&store.inner,
func_sig,
WrapperEnv { env, finalizer },
WrapperEnv {
env,
finalizer: Arc::new(finalizer),
},
inner_callback,
);

Expand Down
7 changes: 5 additions & 2 deletions lib/c-api/src/wasm_c_api/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,19 @@ macro_rules! wasm_declare_own {

#[macro_export]
macro_rules! c_try {
($expr:expr) => {{
($expr:expr; otherwise $return:expr) => {{
let res: Result<_, _> = $expr;
match res {
Ok(val) => val,
Err(err) => {
crate::error::update_last_error(err);
return None;
return $return;
}
}
}};
($expr:expr) => {{
c_try!($expr; otherwise None)
}};
($expr:expr, $e:expr) => {{
let opt: Option<_> = $expr;
c_try!(opt.ok_or_else(|| $e))
Expand Down
Loading

0 comments on commit e5d5303

Please sign in to comment.