diff --git a/.github/workflows/documentation.yaml b/.github/workflows/documentation.yaml
index ee0e36a1d87..0316e631027 100644
--- a/.github/workflows/documentation.yaml
+++ b/.github/workflows/documentation.yaml
@@ -14,7 +14,7 @@ jobs:
- name: Set up dependencies
run: |
sudo apt-get update -y
- sudo apt-get install -y libxkbcommon-dev doxygen
+ sudo apt-get install -y libxkbcommon-dev
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
@@ -26,9 +26,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
LLVM_URL: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/11.x/linux-amd64.tar.gz'
- name: Build & package documentation
run: make package-docs
diff --git a/Cargo.lock b/Cargo.lock
index 8a1a03fd0b7..33cb9b527ed 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -238,17 +238,6 @@ version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787"
-[[package]]
-name = "cdylib-link-lines"
-version = "0.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a317db7ea5b455731e51d7f632762716fa5c0b1098dcaa6221e55e2386d170f2"
-dependencies = [
- "serde",
- "serde_derive",
- "toml",
-]
-
[[package]]
name = "cexpr"
version = "0.4.0"
@@ -2410,7 +2399,6 @@ name = "wasmer-c-api"
version = "2.0.0"
dependencies = [
"cbindgen",
- "cdylib-link-lines",
"cfg-if 1.0.0",
"enumset",
"field-offset",
diff --git a/Makefile b/Makefile
index e5c36ab9ee8..4a3d3acd20b 100644
--- a/Makefile
+++ b/Makefile
@@ -384,7 +384,7 @@ else
endif
build-docs:
- cargo doc --release $(compiler_features) --document-private-items --no-deps --workspace
+ cargo doc --release $(compiler_features) --document-private-items --no-deps --workspace --exclude wasmer-c-api
capi-setup:
ifeq ($(IS_WINDOWS), 1)
@@ -392,7 +392,12 @@ ifeq ($(IS_WINDOWS), 1)
endif
build-docs-capi: capi-setup
+ # `wasmer-c-api` lib's name is `wasmer`. To avoid a conflict
+ # when generating the documentation, we rename it to its
+ # crate's name. Then we restore the lib's name.
+ sed -i '' -e 's/name = "wasmer" # ##lib.name##/name = "wasmer_c_api" # ##lib.name##/' lib/c-api/Cargo.toml
RUSTFLAGS="${RUSTFLAGS}" cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,universal,staticlib,dylib,cranelift,wasi
+ sed -i '' -e 's/name = "wasmer_c_api" # ##lib.name##/name = "wasmer" # ##lib.name##/' lib/c-api/Cargo.toml
build-capi: capi-setup
RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \
@@ -584,33 +589,29 @@ package-capi:
cp lib/c-api/wasm.h* package/include
cp lib/c-api/README.md package/include/README.md
- # Windows
- if [ -f $(TARGET_DIR)/wasmer_c_api.dll ]; then \
- cp $(TARGET_DIR)/wasmer_c_api.dll package/lib/wasmer.dll ;\
+ if [ -f $(TARGET_DIR)/wasmer.dll ]; then \
+ cp $(TARGET_DIR)/wasmer.dll package/lib/wasmer.dll ;\
fi
- if [ -f $(TARGET_DIR)/wasmer_c_api.lib ]; then \
- cp $(TARGET_DIR)/wasmer_c_api.lib package/lib/wasmer.lib ;\
+ if [ -f $(TARGET_DIR)/wasmer.lib ]; then \
+ cp $(TARGET_DIR)/wasmer.lib package/lib/wasmer.lib ;\
fi
- # For some reason in macOS arm64 there are issues if we copy constantly in the install_name_tool util
- rm -f package/lib/libwasmer.dylib
- if [ -f $(TARGET_DIR)/libwasmer_c_api.dylib ]; then \
- cp $(TARGET_DIR)/libwasmer_c_api.dylib package/lib/libwasmer.dylib ;\
- install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib ;\
+ if [ -f $(TARGET_DIR)/libwasmer.dylib ]; then \
+ cp $(TARGET_DIR)/libwasmer.dylib package/lib/libwasmer.dylib ;\
fi
- if [ -f $(TARGET_DIR)/libwasmer_c_api.so ]; then \
- cp $(TARGET_DIR)/libwasmer_c_api.so package/lib/libwasmer.so ;\
+ if [ -f $(TARGET_DIR)/libwasmer.so ]; then \
+ cp $(TARGET_DIR)/libwasmer.so package/lib/libwasmer.so ;\
fi
- if [ -f $(TARGET_DIR)/libwasmer_c_api.a ]; then \
- cp $(TARGET_DIR)/libwasmer_c_api.a package/lib/libwasmer.a ;\
+ if [ -f $(TARGET_DIR)/libwasmer.a ]; then \
+ cp $(TARGET_DIR)/libwasmer.a package/lib/libwasmer.a ;\
fi
package-docs: build-docs build-docs-capi
- mkdir -p "package/docs/c"
- cp -R target/doc package/docs/crates
- echo '' > package/docs/index.html
- echo '' > package/docs/crates/index.html
+ mkdir -p "package/docs/crates"
+ cp -R target/doc/ package/docs/crates
+ echo '' > package/docs/index.html
+ echo '' > package/docs/crates/index.html
package: package-wapm package-wasmer package-minimal-headless-wasmer package-capi
@@ -645,13 +646,13 @@ install-capi-lib:
pkgver=$$(target/release/wasmer --version | cut -d\ -f2) && \
shortver="$${pkgver%.*}" && \
majorver="$${shortver%.*}" && \
- install -Dm755 target/release/libwasmer_c_api.so "$(DESTDIR)/lib/libwasmer.so.$$pkgver" && \
+ install -Dm755 target/release/libwasmer.so "$(DESTDIR)/lib/libwasmer.so.$$pkgver" && \
ln -sf "libwasmer.so.$$pkgver" "$(DESTDIR)/lib/libwasmer.so.$$shortver" && \
ln -sf "libwasmer.so.$$pkgver" "$(DESTDIR)/lib/libwasmer.so.$$majorver" && \
ln -sf "libwasmer.so.$$pkgver" "$(DESTDIR)/lib/libwasmer.so"
install-capi-staticlib:
- install -Dm644 target/release/libwasmer_c_api.a "$(DESTDIR)/lib/libwasmer.a"
+ install -Dm644 target/release/libwasmer.a "$(DESTDIR)/lib/libwasmer.a"
install-misc:
install -Dm644 LICENSE "$(DESTDIR)"/share/licenses/wasmer/LICENSE
diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml
index 40a0adee199..5335789a708 100644
--- a/lib/c-api/Cargo.toml
+++ b/lib/c-api/Cargo.toml
@@ -12,10 +12,17 @@ readme = "README.md"
edition = "2018"
[lib]
+# The library name is `wasmer` so that we generate dylib like
+# `libwasmer.so`, `libwasmer.dylib`, `wasmer.dll` etc. But it creates
+# a conflict with the existing `wasmer` crate, see below.
+name = "wasmer" # ##lib.name##
+ # ^ DO NOT REMOVE, it's used the `Makefile`, see `build-docs-capi`.
crate-type = ["cdylib", "rlib", "staticlib"]
[dependencies]
-wasmer = { version = "2.0.0", path = "../api", default-features = false }
+# We rename `wasmer` to `wasmer-api` to avoid the conflict with this
+# library name (see `[lib]`).
+wasmer-api = { version = "2.0.0", path = "../api", default-features = false, package = "wasmer" }
wasmer-compiler-cranelift = { version = "2.0.0", path = "../compiler-cranelift", optional = true }
wasmer-compiler-singlepass = { version = "2.0.0", path = "../compiler-singlepass", optional = true }
wasmer-compiler-llvm = { version = "2.0.0", path = "../compiler-llvm", optional = true }
@@ -48,7 +55,7 @@ default = [
"wasi",
"middlewares",
]
-wat = ["wasmer/wat"]
+wat = ["wasmer-api/wat"]
wasi = ["wasmer-wasi", "typetag", "serde"]
engine = []
middlewares = ["wasmer-middlewares"]
@@ -65,7 +72,7 @@ staticlib = [
"engine",
]
compiler = [
- "wasmer/compiler",
+ "wasmer-api/compiler",
"wasmer-engine-universal/compiler",
"wasmer-engine-dylib/compiler",
"wasmer-engine-staticlib/compiler"
@@ -91,5 +98,4 @@ native = ["dylib"]
#emscripten = ["wasmer-emscripten"]
[build-dependencies]
-cbindgen = "0.19"
-cdylib-link-lines = "0.1"
+cbindgen = "0.19"
\ No newline at end of file
diff --git a/lib/c-api/build.rs b/lib/c-api/build.rs
index 1d3494fe543..ce423ac12e1 100644
--- a/lib/c-api/build.rs
+++ b/lib/c-api/build.rs
@@ -5,7 +5,9 @@
use cbindgen::{Builder, Language};
use std::{
- env, fs,
+ env,
+ ffi::OsStr,
+ fs,
path::{Path, PathBuf},
};
@@ -76,7 +78,7 @@ fn main() {
build_wasm_c_api_headers(&crate_dir, &out_dir);
build_inline_c_env_vars();
- build_cdylib();
+ build_cdylib_link_arg();
}
/// Check whether we should build the C API headers or set `inline-c` up.
@@ -223,36 +225,7 @@ fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header:
}
fn build_inline_c_env_vars() {
- use std::ffi::OsStr;
-
- // We start from `OUT_DIR` because `cargo publish` uses a different directory
- // so traversing from `CARGO_MANIFEST_DIR` is less reliable.
- let mut shared_object_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
-
- assert_eq!(shared_object_dir.file_name(), Some(OsStr::new("out")));
- shared_object_dir.pop();
-
- assert!(shared_object_dir
- .file_name()
- .as_ref()
- .unwrap()
- .to_string_lossy()
- .to_string()
- .starts_with("wasmer-c-api"));
- shared_object_dir.pop();
-
- assert_eq!(shared_object_dir.file_name(), Some(OsStr::new("build")));
- shared_object_dir.pop();
- shared_object_dir.pop(); // "debug" or "release"
-
- // We either find `target` or the target triple if cross-compiling.
- if shared_object_dir.file_name() != Some(OsStr::new("target")) {
- let target = env::var("TARGET").unwrap();
- assert_eq!(shared_object_dir.file_name(), Some(OsStr::new(&target)));
- }
-
- shared_object_dir.push(env::var("PROFILE").unwrap());
-
+ let shared_object_dir = shared_object_dir();
let shared_object_dir = shared_object_dir.as_path().to_string_lossy();
let include_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
@@ -278,49 +251,104 @@ fn build_inline_c_env_vars() {
}
println!(
- "cargo:rustc-env=INLINE_C_RS_LDFLAGS={shared_object_dir}/{lib}",
+ "cargo:rustc-env=INLINE_C_RS_LDFLAGS=-rpath,{shared_object_dir} {shared_object_dir}/{lib}",
shared_object_dir = shared_object_dir,
lib = if cfg!(target_os = "windows") {
- "wasmer_c_api.dll".to_string()
+ "wasmer.dll".to_string()
} else if cfg!(target_os = "macos") {
- "libwasmer_c_api.dylib".to_string()
+ "libwasmer.dylib".to_string()
} else {
let path = format!(
"{shared_object_dir}/{lib}",
shared_object_dir = shared_object_dir,
- lib = "libwasmer_c_api.so"
+ lib = "libwasmer.so"
);
if Path::new(path.as_str()).exists() {
- "libwasmer_c_api.so".to_string()
+ "libwasmer.so".to_string()
} else {
- "libwasmer_c_api.a".to_string()
+ "libwasmer.a".to_string()
}
}
);
}
-fn build_cdylib() {
- // Configure the `soname`, `install_name`, `current_version`,
- // `out-implib`, `output-def` etc. for as much platforms as
- // possible.
- cdylib_link_lines::shared_object_link_args(
- "wasmer",
- &env::var("CARGO_PKG_VERSION_MAJOR").unwrap(),
- &env::var("CARGO_PKG_VERSION_MINOR").unwrap(),
- &env::var("CARGO_PKG_VERSION_PATCH").unwrap(),
- &env::var("CARGO_CFG_TARGET_ARCH").unwrap(),
- &env::var("CARGO_CFG_TARGET_OS").unwrap(),
- &env::var("CARGO_CFG_TARGET_ENV").unwrap(),
- "/usr/local/lib".into(),
- env::var_os("CARGO_TARGET_DIR").map_or(
- {
- let manifest_dir: PathBuf = env::var_os("CARGO_MANIFEST_DIR").unwrap().into();
- manifest_dir
- .join("target")
- .join(env::var("PROFILE").unwrap())
- },
- Into::into,
- ),
- );
+fn build_cdylib_link_arg() {
+ // Code inspired by the `cdylib-link-lines` crate.
+ let mut lines = Vec::new();
+ let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
+ let env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
+ let version_major = env::var("CARGO_PKG_VERSION_MAJOR").unwrap();
+ let version_minor = env::var("CARGO_PKG_VERSION_MINOR").unwrap();
+ let version_patch = env::var("CARGO_PKG_VERSION_PATCH").unwrap();
+ let shared_object_dir = shared_object_dir();
+
+ match (os.as_str(), env.as_str()) {
+ ("android", _) => {
+ lines.push(format!("-Wl,-soname,libwasmer.so"));
+ }
+
+ ("linux", _) | ("freebsd", _) | ("dragonfly", _) | ("netbsd", _) if env != "musl" => {
+ lines.push(format!("-Wl,-soname,libwasmer.so"));
+ }
+
+ ("macos", _) | ("ios", _) => {
+ lines.push(format!(
+ "-Wl,-install_name,@rpath/libwasmer.dylib,-current_version,{x}.{y}.{z},-compatibility_version,{x}",
+ x = version_major,
+ y = version_minor,
+ z = version_patch,
+ ));
+ }
+
+ ("windows", "gnu") => {
+ // This is only set up to work on GNU toolchain versions of Rust
+ lines.push(format!(
+ "-Wl,--out-implib,{}",
+ shared_object_dir.join(format!("wasmer.dll.a")).display()
+ ));
+ lines.push(format!(
+ "-Wl,--output-def,{}",
+ shared_object_dir.join(format!("wasmer.def")).display()
+ ));
+ }
+
+ _ => {}
+ }
+
+ for line in lines {
+ println!("cargo:rustc-cdylib-link-arg={}", line);
+ }
+}
+
+fn shared_object_dir() -> PathBuf {
+ // We start from `OUT_DIR` because `cargo publish` uses a different directory
+ // so traversing from `CARGO_MANIFEST_DIR` is less reliable.
+ let mut shared_object_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
+
+ assert_eq!(shared_object_dir.file_name(), Some(OsStr::new("out")));
+ shared_object_dir.pop();
+
+ assert!(shared_object_dir
+ .file_name()
+ .as_ref()
+ .unwrap()
+ .to_string_lossy()
+ .to_string()
+ .starts_with("wasmer-c-api"));
+ shared_object_dir.pop();
+
+ assert_eq!(shared_object_dir.file_name(), Some(OsStr::new("build")));
+ shared_object_dir.pop();
+ shared_object_dir.pop(); // "debug" or "release"
+
+ // We either find `target` or the target triple if cross-compiling.
+ if shared_object_dir.file_name() != Some(OsStr::new("target")) {
+ let target = env::var("TARGET").unwrap();
+ assert_eq!(shared_object_dir.file_name(), Some(OsStr::new(&target)));
+ }
+
+ shared_object_dir.push(env::var("PROFILE").unwrap());
+
+ shared_object_dir
}
diff --git a/lib/c-api/src/error.rs b/lib/c-api/src/error.rs
index 3bbbc9b5373..acf921a1023 100644
--- a/lib/c-api/src/error.rs
+++ b/lib/c-api/src/error.rs
@@ -63,7 +63,7 @@ thread_local! {
/// # Example
///
/// ```rust,no_run
-/// # use wasmer_c_api::error::{update_last_error, CApiError};
+/// # use wasmer::error::{update_last_error, CApiError};
///
/// update_last_error(CApiError {
/// msg: "Hello, World!".to_string(),
diff --git a/lib/c-api/src/ordered_resolver.rs b/lib/c-api/src/ordered_resolver.rs
index dfe4493d1a4..adffaa35c85 100644
--- a/lib/c-api/src/ordered_resolver.rs
+++ b/lib/c-api/src/ordered_resolver.rs
@@ -5,7 +5,7 @@
//! by index and not by module and name.
use std::iter::FromIterator;
-use wasmer::{Export, Exportable, Extern, Resolver};
+use wasmer_api::{Export, Exportable, Extern, Resolver};
/// An `OrderedResolver` stores all the `externs` provided to an Instance
/// in a Vec, so we can retrieve them later based on index.
diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs
index 0f9df46be82..058697393b0 100644
--- a/lib/c-api/src/wasm_c_api/engine.rs
+++ b/lib/c-api/src/wasm_c_api/engine.rs
@@ -11,7 +11,7 @@ use super::unstable::target_lexicon::wasmer_target_t;
use crate::error::{update_last_error, CApiError};
use cfg_if::cfg_if;
use std::sync::Arc;
-use wasmer::Engine;
+use wasmer_api::Engine;
#[cfg(feature = "dylib")]
use wasmer_engine_dylib::Dylib;
#[cfg(feature = "staticlib")]
@@ -286,7 +286,7 @@ pub struct wasm_engine_t {
}
#[cfg(feature = "compiler")]
-use wasmer::CompilerConfig;
+use wasmer_api::CompilerConfig;
#[cfg(feature = "compiler")]
fn get_default_compiler_config() -> Box {
diff --git a/lib/c-api/src/wasm_c_api/externals/function.rs b/lib/c-api/src/wasm_c_api/externals/function.rs
index b54598e4339..d04e3c9b95a 100644
--- a/lib/c-api/src/wasm_c_api/externals/function.rs
+++ b/lib/c-api/src/wasm_c_api/externals/function.rs
@@ -6,7 +6,7 @@ use super::CApiExternTag;
use std::convert::TryInto;
use std::ffi::c_void;
use std::sync::Arc;
-use wasmer::{Function, RuntimeError, Val};
+use wasmer_api::{Function, RuntimeError, Val};
#[derive(Debug, Clone)]
#[allow(non_camel_case_types)]
@@ -108,13 +108,15 @@ pub unsafe extern "C" fn wasm_func_new_with_env(
let func_sig = &function_type.inner().function_type;
let num_rets = func_sig.results().len();
- #[derive(wasmer::WasmerEnv, Clone)]
+ #[derive(Clone)]
#[repr(C)]
struct WrapperEnv {
env: *mut c_void,
env_finalizer: Arc