Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into wasix
Browse files Browse the repository at this point in the history
  • Loading branch information
theduke committed Jan 28, 2023
2 parents 5cf768d + 6e850db commit 42f58d0
Show file tree
Hide file tree
Showing 27 changed files with 462 additions and 708 deletions.
89 changes: 88 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
build-what: [
{
key: capi,
build-cmd: 'make build-capi',
build-cmd: 'make build-capi && make package-capi',
name: 'Build C-API'
},
{
Expand Down Expand Up @@ -159,6 +159,26 @@ jobs:
PKG_CONFIG_PATH: /usr/lib/aarch64-linux-gnu/pkgconfig
PKG_CONFIG_ALLOW_CROSS: true
ENABLE_LLVM: 0
- name: Dist
if: ${{ matrix.build-what.key == 'capi' }}
run: |
make distribution
env:
CARGO_BINARY: docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${GITHUB_WORKSPACE}:/project -w /project wasmer/aarch64 cross
CROSS_DOCKER_IN_DOCKER: true
CARGO_TARGET: aarch64-unknown-linux-gnu
PKG_CONFIG_PATH: /usr/lib/aarch64-linux-gnu/pkgconfig
PKG_CONFIG_ALLOW_CROSS: true
TARGET: aarch64-unknown-linux-gnu
TARGET_DIR: target/aarch64-unknown-linux-gnu/release
- name: Upload Artifacts
if: ${{ matrix.build-what.key == 'capi' }}
uses: actions/upload-artifact@v2
with:
name: capi-linux-aarch64
path: dist
if-no-files-found: error
retention-days: 2

build:
name: ${{ matrix.build-what.name }} on ${{ matrix.metadata.build }}
Expand Down Expand Up @@ -575,6 +595,73 @@ jobs:
aws-endpoint: https://storage.googleapis.com
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
- name: Prepare package directory
shell: bash
run: |
mkdir -p package
mkdir -p package/cache
- uses: actions/download-artifact@v3
with:
name: capi-linux-aarch64
path: package/cache/wasmercache1
- uses: actions/download-artifact@v3
with:
name: capi-windows-gnu
path: package/cache/wasmercache2
- uses: actions/download-artifact@v3
with:
name: capi-macos-arm
path: package/cache/wasmercache3
- uses: actions/download-artifact@v3
with:
name: capi-macos-x64
path: package/cache/wasmercache4
- uses: actions/download-artifact@v3
with:
name: capi-linux-x64
path: package/cache/wasmercache5
- name: Copy .tar.gz files to proper location
shell: bash
run: |
ls package/cache/wasmercache1
ls package/cache/wasmercache2
ls package/cache/wasmercache3
ls package/cache/wasmercache4
ls package/cache/wasmercache5
cp package/cache/wasmercache1/wasmer.tar.gz package/cache/wasmer-linux-aarch64.tar.gz
cp package/cache/wasmercache2/build-capi.tar.gz package/cache/wasmer-windows-gnu64.tar.gz
cp package/cache/wasmercache3/build-capi.tar.gz package/cache/wasmer-darwin-arm64.tar.gz
cp package/cache/wasmercache4/build-capi.tar.gz package/cache/wasmer-darwin-amd64.tar.gz
cp package/cache/wasmercache5/build-capi.tar.gz package/cache/wasmer-linux-amd64.tar.gz
- uses: actions/download-artifact@v3
if: ${{ matrix.build == 'windows-x64' }}
with:
name: capi-windows-gnu
path: download_link
- uses: actions/download-artifact@v3
if: ${{ matrix.build == 'linux-musl' }}
with:
name: capi-linux-musl
path: download_link
- uses: actions/download-artifact@v3
if: ${{ matrix.build == 'macos-arm' }}
with:
name: capi-macos-arm
path: download_link
- uses: actions/download-artifact@v3
if: ${{ matrix.build == 'macos-x64' }}
with:
name: capi-macos-x64
path: download_link
- uses: actions/download-artifact@v3
if: ${{ matrix.build == 'linux-x64' }}
with:
name: capi-linux-x64
path: download_link
- name: Copy build-capi.tar.gz to link.tar.gz
shell: bash
run: |
cp download_link/build-capi.tar.gz link.tar.gz
- name: Unzip Artifacts
shell: bash
run: |
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ out.txt
wapm.toml
build-capi.tar.gz
build-wasmer.tar.gz
lcov.info
lcov.info
link/
link.tar.gz
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,12 @@ test-wasi-unit:
test-wasi:
$(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --release --tests $(compiler_features) -- wasi::wasitests

test-integration-cli:
test-integration-cli: build-wasmer build-capi package dist
cp ./dist/wasmer.tar.gz ./link.tar.gz
rustup target add wasm32-wasi
$(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --features webc_runner --no-fail-fast -p wasmer-integration-tests-cli -- --nocapture --test-threads=1

# Before running this in the CI, we need to set up link.tar.gz and /cache/wasmer-[target].tar.gz
test-integration-cli-ci:
rustup target add wasm32-wasi
$(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --features webc_runner -p wasmer-integration-tests-cli -- --nocapture --test-threads=1 || $(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --features webc_runner --no-fail-fast -p wasmer-integration-tests-cli -- --nocapture --test-threads=1
Expand Down Expand Up @@ -619,6 +621,7 @@ endif
package-capi:
mkdir -p "package/include"
mkdir -p "package/lib"
mkdir -p "package/winsdk"
cp lib/c-api/wasmer.h* package/include
cp lib/c-api/wasmer_wasm.h* package/include
cp lib/c-api/tests/wasm-c-api/include/wasm.h* package/include
Expand Down Expand Up @@ -729,7 +732,7 @@ package: package-wasmer package-minimal-headless-wasmer package-capi

tar-capi:
ls -R package
tar -C package -zcvf build-capi.tar.gz lib include
tar -C package -zcvf build-capi.tar.gz lib include winsdk

untar-capi:
mkdir -p package
Expand Down
2 changes: 1 addition & 1 deletion docs/ja/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ qjs >

## 他の言語とのインテグレーション

📦 Wasmer ランタイムは**他の言語に組み込んで**使用できるため、WebAssembly は_どんな場所でも_利用できます
📦 Wasmer ランタイムは**他の言語に組み込んで**使用できるため、WebAssembly *どんな場所でも*利用できます

|   | Language | Package | Docs |
|-|-|-|-|
Expand Down
54 changes: 21 additions & 33 deletions lib/api/src/js/externals/function.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pub use self::inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv};
use crate::js::exports::{ExportError, Exportable};
use crate::js::externals::{Extern, VMExtern};
use crate::js::externals::Extern;
use crate::js::function_env::FunctionEnvMut;
use crate::js::store::{AsStoreMut, AsStoreRef, InternalStoreHandle, StoreHandle, StoreMut};
use crate::js::store::{AsStoreMut, AsStoreRef, StoreMut};
use crate::js::types::{param_from_js, AsJs}; /* ValFuncRef */
use crate::js::vm::VMExtern;
use crate::js::RuntimeError;
use crate::js::TypedFunction;
use crate::js::Value;
Expand All @@ -13,7 +14,7 @@ use std::iter::FromIterator;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;

use crate::js::export::VMFunction;
use crate::js::vm::VMFunction;
use std::fmt;

#[repr(C)]
Expand Down Expand Up @@ -58,11 +59,11 @@ fn results_to_js_array(values: &[Value]) -> Array {
/// [Closures as host functions tracking issue](https://github.com/wasmerio/wasmer/issues/1840)
#[derive(Clone, PartialEq)]
pub struct Function {
pub(crate) handle: StoreHandle<VMFunction>,
pub(crate) handle: VMFunction,
}

impl From<StoreHandle<VMFunction>> for Function {
fn from(handle: StoreHandle<VMFunction>) -> Self {
impl From<VMFunction> for Function {
fn from(handle: VMFunction) -> Self {
Self { handle }
}
}
Expand All @@ -86,7 +87,7 @@ impl Function {

/// To `VMExtern`.
pub fn to_vm_extern(&self) -> VMExtern {
VMExtern::Function(self.handle.internal_handle())
VMExtern::Function(self.handle.clone())
}

/// Creates a new host `Function` (dynamic) with the provided signature.
Expand Down Expand Up @@ -190,7 +191,7 @@ impl Function {
JSFunction::new_with_args("f", "return f(Array.prototype.slice.call(arguments, 1))");
let binded_func = dyn_func.bind1(&JsValue::UNDEFINED, &wrapped_func);
let vm_function = VMFunction::new(binded_func, func_ty);
Self::from_vm_export(&mut store, vm_function)
Self::from_vm_extern(&mut store, vm_function)
}

#[deprecated(
Expand All @@ -214,7 +215,7 @@ impl Function {
Args: WasmTypeList,
Rets: WasmTypeList,
{
let mut store = store.as_store_mut();
let store = store.as_store_mut();
if std::mem::size_of::<F>() != 0 {
Self::closures_unsupported_panic();
}
Expand All @@ -232,7 +233,7 @@ impl Function {
let ty = function.ty();
let vm_function = VMFunction::new(binded_func, ty);
Self {
handle: StoreHandle::new(store.objects_mut(), vm_function),
handle: vm_function,
}
}

Expand Down Expand Up @@ -281,7 +282,7 @@ impl Function {
Args: WasmTypeList,
Rets: WasmTypeList,
{
let mut store = store.as_store_mut();
let store = store.as_store_mut();
if std::mem::size_of::<F>() != 0 {
Self::closures_unsupported_panic();
}
Expand All @@ -300,7 +301,7 @@ impl Function {
let ty = function.ty();
let vm_function = VMFunction::new(binded_func, ty);
Self {
handle: StoreHandle::new(store.objects_mut(), vm_function),
handle: vm_function,
}
}

Expand All @@ -321,8 +322,8 @@ impl Function {
/// assert_eq!(f.ty().params(), vec![Type::I32, Type::I32]);
/// assert_eq!(f.ty().results(), vec![Type::I32]);
/// ```
pub fn ty(&self, store: &impl AsStoreRef) -> FunctionType {
self.handle.get(store.as_store_ref().objects()).ty.clone()
pub fn ty(&self, _store: &impl AsStoreRef) -> FunctionType {
self.handle.ty.clone()
}

/// Returns the number of parameters that this function takes.
Expand Down Expand Up @@ -422,7 +423,7 @@ impl Function {
// TODO: This loop is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451
loop {
r = js_sys::Reflect::apply(
&self.handle.get(store.as_store_ref().objects()).function,
&self.handle.function,
&wasm_bindgen::JsValue::NULL,
&arr,
);
Expand All @@ -446,7 +447,7 @@ impl Function {
r?
};

let result_types = self.handle.get(store.as_store_ref().objects()).ty.results();
let result_types = self.handle.ty.results();
match result_types.len() {
0 => Ok(Box::new([])),
1 => {
Expand All @@ -465,21 +466,8 @@ impl Function {
}
}

pub(crate) fn from_vm_export(store: &mut impl AsStoreMut, vm_function: VMFunction) -> Self {
Self {
handle: StoreHandle::new(store.objects_mut(), vm_function),
}
}

pub(crate) fn from_vm_extern(
store: &mut impl AsStoreMut,
internal: InternalStoreHandle<VMFunction>,
) -> Self {
Self {
handle: unsafe {
StoreHandle::from_internal(store.as_store_ref().objects().id(), internal)
},
}
pub(crate) fn from_vm_extern(_store: &mut impl AsStoreMut, internal: VMFunction) -> Self {
Self { handle: internal }
}

#[deprecated(since = "3.0.0", note = "native() has been renamed to typed().")]
Expand Down Expand Up @@ -616,8 +604,8 @@ impl Function {
}

/// Checks whether this `Function` can be used with the given context.
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
self.handle.store_id() == store.as_store_ref().objects().id()
pub fn is_from_store(&self, _store: &impl AsStoreRef) -> bool {
true
}
}

Expand Down
Loading

0 comments on commit 42f58d0

Please sign in to comment.