Fix error when WASMER_DIR is not defined + prepare libwasmer-headless

This commit is contained in:
Felix Schütt
2022-12-23 14:44:28 +01:00
parent 88f6933876
commit acdc7e2498
2 changed files with 38 additions and 14 deletions

View File

@@ -93,7 +93,7 @@ endif
#####
CARGO_BINARY ?= cargo
CARGO_TARGET ?=
CARGO_TARGET ?=
# Variables that can be overridden by the users to force to enable or
# to disable a specific compiler.
@@ -450,15 +450,15 @@ build-capi-llvm-universal: capi-setup
build-capi-headless: capi-setup
ifeq ($(CARGO_TARGET),)
RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) build --target $(HOST_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features compiler-headless,wasi
--no-default-features --features compiler-headless,wasi --target-dir target/$(CARGO_TARGET)/headless
else
RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features compiler-headless,wasi
--no-default-features --features compiler-headless,wasi --target-dir target/$(CARGO_TARGET)/headless
endif
build-capi-headless-ios: capi-setup
RUSTFLAGS="${RUSTFLAGS} -C panic=abort" cargo lipo --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features compiler-headless,wasi
--no-default-features --features compiler-headless,wasi --target-dir target/$(CARGO_TARGET)/headless
#####
#
@@ -587,24 +587,50 @@ package-capi:
cp $(TARGET_DIR)/wasmer.dll package/lib/wasmer.dll ;\
fi
if [ -f target/headless/$(CARGO_TARGET)/release/wasmer.dll ]; then \
cp target/headless/$(CARGO_TARGET)/release/wasmer.dll package/lib/wasmer-headless.dll ;\
fi
if [ -f $(TARGET_DIR)/wasmer.dll.lib ]; then \
cp $(TARGET_DIR)/wasmer.dll.lib package/lib/wasmer.dll.lib ;\
fi
if [ -f target/headless/$(CARGO_TARGET)/release/wasmer.dll.lib ]; then \
cp target/headless/$(CARGO_TARGET)/release/wasmer.dll.lib package/lib/wasmer-headless.dll.lib ;\
fi
if [ -f $(TARGET_DIR)/wasmer.lib ]; then \
cp $(TARGET_DIR)/wasmer.lib package/lib/wasmer.lib ;\
fi
if [ -f target/headless/$(CARGO_TARGET)/release/wasmer.lib ]; then \
cp target/headless/$(CARGO_TARGET)/release/wasmer.lib package/lib/wasmer-headless.lib ;\
fi
if [ -f $(TARGET_DIR)/libwasmer.dylib ]; then \
cp $(TARGET_DIR)/libwasmer.dylib package/lib/libwasmer.dylib ;\
fi
if [ -f target/headless/$(CARGO_TARGET)/release/libwasmer.dylib ]; then \
cp target/headless/$(CARGO_TARGET)/release/libwasmer.dylib package/lib/libwasmer-headless.dylib ;\
fi
if [ -f $(TARGET_DIR)/libwasmer.so ]; then \
cp $(TARGET_DIR)/libwasmer.so package/lib/libwasmer.so ;\
fi
if [ -f target/headless/$(CARGO_TARGET)/release/libwasmer.so ]; then \
cp target/headless/$(CARGO_TARGET)/release/libwasmer.so package/lib/libwasmer-headless.so ;\
fi
if [ -f $(TARGET_DIR)/libwasmer.a ]; then \
cp $(TARGET_DIR)/libwasmer.a package/lib/libwasmer.a ;\
fi
if [ -f target/headless/$(CARGO_TARGET)/release/libwasmer.a ]; then \
cp target/headless/$(CARGO_TARGET)/release/libwasmer.a package/lib/libwasmer-headless.a ;\
fi
package-capi-headless: build-capi-headless
mkdir -p "package/include"
mkdir -p "package/lib"

View File

@@ -1014,7 +1014,13 @@ pub(super) mod utils {
let file = files
.iter()
.find(|f| f.ends_with("libwasmer.a")).cloned()
.find(|f| f.ends_with("libwasmer-headless.a"))
.or_else(|| {
files
.iter()
.find(|f| f.ends_with("libwasmer.a"))
})
.cloned()
.ok_or_else(|| {
anyhow!("Could not find libwasmer.a for {} target in the provided tarball path (files = {files:#?})", target)
})?;
@@ -1096,15 +1102,7 @@ pub(super) mod utils {
}
pub(super) fn get_wasmer_dir() -> anyhow::Result<PathBuf> {
Ok(PathBuf::from(
env::var("WASMER_DIR")
.or_else(|e| {
option_env!("WASMER_INSTALL_PREFIX")
.map(str::to_string)
.ok_or(e)
})
.context("Trying to read env var `WASMER_DIR`")?,
))
wasmer_registry::WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))
}
pub(super) fn get_wasmer_include_directory() -> anyhow::Result<PathBuf> {