Skip to content

Commit

Permalink
feat(api) Merge js-api into api.
Browse files Browse the repository at this point in the history
This patch takes the entire `wasmer-js` crate and merges it into the
`wasmer` crate.

Inside the `lib/api/src/` directory, there are 2 new directories:

1. a new `sys` directory, which contains the usual `wasmer` crate
   implementation,
2. a new directory `js`, which contains the implementation of
   `wasmer-js`.

The `Cargo.toml` file is still compatible. The `default` feature
fallbacks to `sys-default`, which enables the `sys` feature. All
features related to compilers or engines or anything else prior this
patch, activates the `sys` feature.

Parallel to that, there is a `js-default` and `js` features.

The `Cargo.toml` file is extensively documented to explain what are
dependencies, dev-dependencies, features and other sections related to
`sys` or to `js`.

There is a bug with `wasm_bindgen_test` where it doesn't compile or
look for tests in `tests/*/<test>.rs`. The hack is to name files
`tests/js_<test>.rs`. Ugly, but it works.
  • Loading branch information
Hywan committed Jul 23, 2021
1 parent 6b2ec72 commit b302848
Show file tree
Hide file tree
Showing 65 changed files with 3,808 additions and 3,783 deletions.
24 changes: 5 additions & 19 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ members = [
"lib/engine-universal",
"lib/engine-dylib",
"lib/engine-staticlib",
"lib/js-api",
"lib/object",
"lib/vm",
"lib/wasi",
Expand Down
241 changes: 177 additions & 64 deletions lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,96 +10,209 @@ license = "MIT"
readme = "README.md"
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

#####
#
# This crate comes in 2 major flavors:
#
# * `sys`, where `wasmer` will be compiled to a native executable
# which provides compilers, engines, a full VM etc.
# * `js`, where `wasmer` will be compiled to WebAssembly to run in a
# JavaScript host.
#
#####

#####
#
# Shared dependencies.
[dependencies]
#
# ## Mandatory shared dependencies.
#
indexmap = { version = "1.6", features = ["serde-1"] }
cfg-if = "1.0"
thiserror = "1.0"
more-asserts = "0.2"
#
# ## Optional shared dependencies.
#
wat = { version = "1.0", optional = true }
#
#####

#####
#
# # Dependencies and Development Dependencies for `sys`.
#
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
#
# ## Mandatory dependencies for `sys`.
#
wasmer-vm = { path = "../vm", version = "2.0.0" }
wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "2.0.0", optional = true }
wasmer-compiler-cranelift = { path = "../compiler-cranelift", version = "2.0.0", optional = true }
wasmer-compiler-llvm = { path = "../compiler-llvm", version = "2.0.0", optional = true }
wasmer-compiler = { path = "../compiler", version = "2.0.0" }
wasmer-derive = { path = "../derive", version = "2.0.0" }
wasmer-engine = { path = "../engine", version = "2.0.0" }
wasmer-engine-universal = { path = "../engine-universal", version = "2.0.0", optional = true }
wasmer-engine-dylib = { path = "../engine-dylib", version = "2.0.0", optional = true }
wasmer-types = { path = "../types", version = "2.0.0" }
indexmap = { version = "1.6", features = ["serde-1"] }
cfg-if = "1.0"
wat = { version = "1.0", optional = true }
thiserror = "1.0"
more-asserts = "0.2"
target-lexicon = { version = "0.12", default-features = false }
loupe = "0.1"

[target.'cfg(target_os = "windows")'.dependencies]
#
# ## Optional dependencies for `sys`.
#
wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "2.0.0", optional = true }
wasmer-compiler-cranelift = { path = "../compiler-cranelift", version = "2.0.0", optional = true }
wasmer-compiler-llvm = { path = "../compiler-llvm", version = "2.0.0", optional = true }
wasmer-engine-universal = { path = "../engine-universal", version = "2.0.0", optional = true }
wasmer-engine-dylib = { path = "../engine-dylib", version = "2.0.0", optional = true }
#
# ## Mandatory dependencies for `sys` on Windows.
#
[target.'cfg(all(not(target_arch = "wasm32"), target_os = "windows"))'.dependencies]
#
winapi = "0.3"

[dev-dependencies]
# for the binary wasmer.rs
libc = { version = "^0.2", default-features = false }
#
# ## Development Dependencies for `sys`.
#
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
#
libc = { version = "^0.2", default-features = false } # for the binary wasmer.rs
wat = "1.0"
tempfile = "3.1"
anyhow = "1.0"
#
#####

#####
#
# # Dependencies and Develoment Dependencies for `js`.
#
[target.'cfg(target_arch = "wasm32")'.dependencies]
#
# ## Mandatory dependencies for `js`.
#
wasmer-types = { path = "../types", version = "2.0.0", default-features = false, features = ["std"] }
wasm-bindgen = "0.2.74"
js-sys = "0.3.51"
wasmer-derive = { path = "../derive", version = "2.0.0" }
#
# ## Optional dependencies for `js`.
#
wasmparser = { version = "0.78", default-features = false, optional = true }
hashbrown = { version = "0.11", optional = true }
#
# ## Development Dependencies for `js`.
#
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
#
wat = "1.0"
anyhow = "1.0"
wasm-bindgen-test = "0.3.0"
#
#####

#####
#
# # Specific to `js`.
#
# `wasm-opt` is on by default in for the release profile, but it can be
# disabled by setting it to `false`
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
#
####

[badges]
maintenance = { status = "actively-developed" }

[features]
default = ["wat", "default-cranelift", "default-universal"]
default = ["sys-default"]

#####
#
# # Features for `sys`.
#
sys = []
sys-default = ["sys", "wat", "default-cranelift", "default-universal"]
#
# ## Compilers.
#
compiler = [
"sys",
"wasmer-compiler/translator",
"wasmer-engine-universal/compiler",
"wasmer-engine-dylib/compiler",
]
engine = []
universal = [
"wasmer-engine-universal",
"engine"
]
dylib = [
"wasmer-engine-dylib",
"engine"
]
singlepass = [
"wasmer-compiler-singlepass",
"compiler",
]
cranelift = [
"wasmer-compiler-cranelift",
"compiler",
]
llvm = [
"wasmer-compiler-llvm",
"compiler",
]

default-singlepass = [
"singlepass",
"default-compiler"
]
default-cranelift = [
"cranelift",
"default-compiler"
]
default-llvm = [
"llvm",
"default-compiler"
]
default-universal = [
"universal",
"default-engine"
]
default-dylib = [
"dylib",
"default-engine"
]

singlepass = [
"compiler",
"wasmer-compiler-singlepass",
]
cranelift = [
"compiler",
"wasmer-compiler-cranelift",
]
llvm = [
"compiler",
"wasmer-compiler-llvm",
]
default-compiler = []
default-singlepass = [
"default-compiler",
"singlepass",
]
default-cranelift = [
"default-compiler",
"cranelift",
]
default-llvm = [
"default-compiler",
"llvm",
]
#
# ## Engines.
#
engine = ["sys"]
universal = [
"engine",
"wasmer-engine-universal",
]
dylib = [
"engine",
"wasmer-engine-dylib",
]
default-engine = []

# experimental / in-development features
default-universal = [
"default-engine",
"universal",
]
default-dylib = [
"default-engine",
"dylib",
]
#
# ## Experimental / in-development features
#
experimental-reference-types-extern-ref = [
"sys",
"wasmer-types/experimental-reference-types-extern-ref",
]

# Deprecated features.
#
# ## Deprecated features.
#
jit = ["universal"]
native = ["dylib"]
#
#####

#####
#
# # Features for `js`.
#
js = []
js-default = ["js", "std", "wasm-types-polyfill", "wat"]
#
wasm-types-polyfill = ["js", "wasmparser"]
std = ["js"]
core = ["js", "hashbrown"]
#
#####
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/js-api/src/env.rs → lib/api/src/js/env.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ExportError, Instance};
use crate::js::{ExportError, Instance};
use thiserror::Error;

/// An error while initializing the user supplied host env with the `WasmerEnv` trait.
Expand Down
2 changes: 1 addition & 1 deletion lib/js-api/src/error.rs → lib/api/src/js/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::lib::std::string::String;
use crate::js::lib::std::string::String;
#[cfg(feature = "std")]
use thiserror::Error;

Expand Down
8 changes: 4 additions & 4 deletions lib/js-api/src/export.rs → lib/api/src/js/export.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::instance::Instance;
use crate::wasm_bindgen_polyfill::Global;
use crate::HostEnvInitError;
use crate::WasmerEnv;
use crate::js::instance::Instance;
use crate::js::wasm_bindgen_polyfill::Global;
use crate::js::HostEnvInitError;
use crate::js::WasmerEnv;
use js_sys::Function;
use js_sys::WebAssembly::{Memory, Table};
use std::cell::RefCell;
Expand Down
Loading

0 comments on commit b302848

Please sign in to comment.