From bc902b222ff03eaedd67f84f9aeef80bc1be6205 Mon Sep 17 00:00:00 2001 From: Simon Warta <2603011+webmaster128@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:34:16 +0100 Subject: [PATCH 1/3] Merge pull request #387 from NibiruChain/main Add static build for macos (cherry picked from commit 78f9a4105f72f2bb0b471203ccd8a664cf6129b3) --- .circleci/config.yml | 0 Makefile | 11 +++++++++++ builders/guest/build_macos_static.sh | 24 ++++++++++++++++++++++++ internal/api/link_mac.go | 3 +-- internal/api/link_mac_static.go | 6 ++++++ libwasmvm/Cargo.toml | 9 +++++---- libwasmvm/src/examples/wasmvmstatic.rs | 1 + 7 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 .circleci/config.yml create mode 100755 builders/guest/build_macos_static.sh create mode 100644 internal/api/link_mac_static.go create mode 100644 libwasmvm/src/examples/wasmvmstatic.rs diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..e69de29b diff --git a/Makefile b/Makefile index 196ed8e4..f770abbe 100644 --- a/Makefile +++ b/Makefile @@ -92,6 +92,17 @@ release-build-macos: cp libwasmvm/artifacts/libwasmvm.dylib internal/api make update-bindings +# Creates a release build in a containerized build environment of the static library for macOS (.a) +release-build-macos-static: + rm -rf libwasmvm/target/x86_64-apple-darwin/release + rm -rf libwasmvm/target/aarch64-apple-darwin/release + docker run --rm -u $(USER_ID):$(USER_GROUP) \ + -v $(shell pwd)/libwasmvm:/code \ + -v $(shell pwd)/builders/guest/build_macos_static.sh:/usr/local/bin/build_macos_static.sh \ + $(BUILDERS_PREFIX)-cross build_macos_static.sh + cp libwasmvm/artifacts/libwasmvmstatic_darwin.a internal/api/libwasmvmstatic_darwin.a + make update-bindings + # Creates a release build in a containerized build environment of the shared library for Windows (.dll) release-build-windows: rm -rf libwasmvm/target/release diff --git a/builders/guest/build_macos_static.sh b/builders/guest/build_macos_static.sh new file mode 100755 index 00000000..45086a5d --- /dev/null +++ b/builders/guest/build_macos_static.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -o errexit -o nounset -o pipefail + +# ref: https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html +export PATH="/opt/osxcross/target/bin:$PATH" +export LIBZ_SYS_STATIC=1 + +# See https://github.com/CosmWasm/wasmvm/issues/222#issuecomment-880616953 for two approaches to +# enable stripping through cargo (if that is desired). + +echo "Starting aarch64-apple-darwin build" +export CC=aarch64-apple-darwin20.4-clang +export CXX=aarch64-apple-darwin20.4-clang++ +cargo build --release --target aarch64-apple-darwin --example wasmvmstatic + +echo "Starting x86_64-apple-darwin build" +export CC=o64-clang +export CXX=o64-clang++ +cargo build --release --target x86_64-apple-darwin --example wasmvmstatic + +# Create a universal library with both archs +lipo -output artifacts/libwasmvmstatic_darwin.a -create \ + target/x86_64-apple-darwin/release/examples/libwasmvmstatic.a \ + target/aarch64-apple-darwin/release/examples/libwasmvmstatic.a diff --git a/internal/api/link_mac.go b/internal/api/link_mac.go index ddd139e0..e6d841ea 100644 --- a/internal/api/link_mac.go +++ b/internal/api/link_mac.go @@ -1,5 +1,4 @@ -//go:build darwin && !sys_wasmvm -// +build darwin,!sys_wasmvm +//go:build darwin && !static_wasm && !sys_wasmvm package api diff --git a/internal/api/link_mac_static.go b/internal/api/link_mac_static.go new file mode 100644 index 00000000..d9132e51 --- /dev/null +++ b/internal/api/link_mac_static.go @@ -0,0 +1,6 @@ +//go:build darwin && static_wasm && !sys_wasmvm + +package api + +// #cgo LDFLAGS: -L${SRCDIR} -lwasmvmstatic_darwin +import "C" diff --git a/libwasmvm/Cargo.toml b/libwasmvm/Cargo.toml index f8720497..de22d514 100644 --- a/libwasmvm/Cargo.toml +++ b/libwasmvm/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" exclude = [".circleci/*", ".gitignore"] [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "rlib"] # the example is to allow us to compile a muslc static lib with the same codebase as we compile the # normal dynamic libs (best workaround I could find to override crate-type on the command line) @@ -20,9 +20,10 @@ name = "muslc" path = "src/lib.rs" crate-type = ["staticlib"] -# # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -# [badges] -# maintenance = { status = "actively-developed" } +[[example]] +name = "wasmvmstatic" +path = "src/examples/wasmvmstatic.rs" +crate-type = ["staticlib"] [features] default = [] diff --git a/libwasmvm/src/examples/wasmvmstatic.rs b/libwasmvm/src/examples/wasmvmstatic.rs new file mode 100644 index 00000000..42db554f --- /dev/null +++ b/libwasmvm/src/examples/wasmvmstatic.rs @@ -0,0 +1 @@ +pub use wasmvm::*; From c62513a3ec502571ce585a22ca27cb3dd56a5302 Mon Sep 17 00:00:00 2001 From: zemyblue Date: Wed, 19 Jul 2023 13:59:09 +0900 Subject: [PATCH 2/3] ci: apply `make release-build-macos-static` in release github action. Signed-off-by: zemyblue --- .circleci/config.yml | 0 .github/workflows/release.yml | 5 ++++- Makefile | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e248cd22..ed2bcc95 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -66,14 +66,17 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Build docker image - run: cd builders && make docker-image-alpine + run: cd builders && make docker-image-alpine && make docker-image-cross - name: Build & Test static library run: make release-build-alpine + - name: Build static library for MacOS + run: make release-build-macos-static - name: Collect artifacts run: | mkdir artifacts cp ./internal/api/libwasmvm_muslc.a ./artifacts/libwasmvm_muslc.x86_64.a cp ./internal/api/libwasmvm_muslc.aarch64.a ./artifacts/libwasmvm_muslc.aarch64.a + cp ./internal/api/libwasmvmstatic_darwin.a ./artifacts/libwasmvmstatic_darwin.a - name: Create checksums working-directory: ./artifacts run: sha256sum * > checksums.txt && cat checksums.txt diff --git a/Makefile b/Makefile index f770abbe..dc2537e4 100644 --- a/Makefile +++ b/Makefile @@ -121,6 +121,7 @@ release-build: make release-build-linux make release-build-macos make release-build-windows + make release-build-macos-static test-alpine: release-build-alpine # try running go tests using this lib with muslc From b89009f394c3ab40f223d6c7fcbcbeda5be28ffe Mon Sep 17 00:00:00 2001 From: zemyblue Date: Wed, 19 Jul 2023 19:54:16 +0900 Subject: [PATCH 3/3] chore: update changelog Signed-off-by: zemyblue --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abc52826..21ed01a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased](https://github.com/Finschia/wasmvm/compare/v1.1.1-0.11.2...HEAD) ### Features +* feat: Add static build for macos ([#115](https://github.com/Finschia/wasmvm/pull/115)) ### Fixes