From 57d918e3f590cc9b0b804992c8e0208e3a394569 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 21 Aug 2022 16:12:52 +0300 Subject: [PATCH] Bring libwasmer-headless.a from 22MiB to 7.2MiB (on my machine) By using lto optimization flags. A qjs.wasm executable using the headless engine now weights 4.6MiB: % du -sh qjs-he*.out 20M qjs-headfull.out 4.6M qjs-headless.out --- Makefile | 4 ++-- lib/c-api/Cargo.toml | 2 +- lib/wasi/Cargo.toml | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a6be323b4d9..aa38bd87cf8 100644 --- a/Makefile +++ b/Makefile @@ -389,7 +389,7 @@ build-wasmer-headless-minimal: RUSTFLAGS += -C panic=abort build-wasmer-headless-minimal: RUSTFLAGS="${RUSTFLAGS}" xargo build --target $(HOST_TARGET) --release --manifest-path=lib/cli/Cargo.toml --no-default-features --features headless-minimal --bin wasmer-headless ifeq ($(IS_DARWIN), 1) - strip -u target/$(HOST_TARGET)/release/wasmer-headless + strip target/$(HOST_TARGET)/release/wasmer-headless else ifeq ($(IS_WINDOWS), 1) strip --strip-unneeded target/$(HOST_TARGET)/release/wasmer-headless.exe else @@ -455,7 +455,7 @@ build-capi-llvm-universal: capi-setup # Headless (we include the minimal to be able to run) build-capi-headless: capi-setup - RUSTFLAGS="${RUSTFLAGS} -C panic=abort" $(CARGO_BINARY) build $(CARGO_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ + 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 build-capi-headless-ios: capi-setup diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index d275c0fff82..072da4e3d9f 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -17,7 +17,7 @@ edition = "2018" # 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"] +crate-type = ["staticlib", "cdylib"] #"cdylib", "rlib", "staticlib"] [dependencies] # We rename `wasmer` to `wasmer-api` to avoid the conflict with this diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index bfa746e2921..798d1304668 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -10,9 +10,6 @@ license = "MIT" readme = "README.md" edition = "2018" -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] cfg-if = "1.0" thiserror = "1"