From acdc7e24986649432a8c89abc3a8b74a5615df64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 23 Dec 2022 14:44:28 +0100 Subject: [PATCH] Fix error when WASMER_DIR is not defined + prepare libwasmer-headless --- Makefile | 34 ++++++++++++++++++++++++++---- lib/cli/src/commands/create_exe.rs | 18 +++++++--------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index c0f3a6d0d..3f37267ef 100644 --- a/Makefile +++ b/Makefile @@ -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" diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 64c903719..93cf78ce7 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -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 { - 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 {