From adf62fd21def1e2e19b5d631ca3676ca89e6f516 Mon Sep 17 00:00:00 2001 From: Jagger De Leo Date: Thu, 30 Sep 2021 16:37:29 -0400 Subject: [PATCH] Add basic macOS arm64 support This commit adds basic support for building on M1 Macs. For now, `libwasmtime.a` for macos_aarch64 must be built manually, but that part seems to be working fine. This workflow works on my M1 MacBook running Monterey: ``` cd wasmtime cargo build -p wasmtime-c-api --release cd ../wasmtime-go ./ci/local.sh ../wasmtime ``` --- build/macos-aarch64/empty.go | 1 + ci/local.sh | 8 +++++--- ffi.go | 1 + includebuild.go | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 build/macos-aarch64/empty.go diff --git a/build/macos-aarch64/empty.go b/build/macos-aarch64/empty.go new file mode 100644 index 0000000..018ddfa --- /dev/null +++ b/build/macos-aarch64/empty.go @@ -0,0 +1 @@ +package macos_aarch64 diff --git a/ci/local.sh b/ci/local.sh index 4c3f9f1..d3aa214 100755 --- a/ci/local.sh +++ b/ci/local.sh @@ -8,7 +8,7 @@ fi # Clean and re-create "build" directory hierarchy rm -rf build -for d in "include" "include/wasmtime" "linux-x86_64" "macos-x86_64" "windows-x86_64"; do +for d in "include" "include/wasmtime" "linux-x86_64" "macos-x86_64" "windows-x86_64" "macos-aarch64"; do path="build/$d" mkdir -p "$path" name=$(basename $d) @@ -26,8 +26,10 @@ if [ ! -f "$build/libwasmtime.a" ]; then echo 'Missing libwasmtime.a. Did you `cargo build -p wasmtime-c-api`?' fi -ln -s "$build/libwasmtime.a" build/linux-x86_64/libwasmtime.a -ln -s "$build/libwasmtime.a" build/macos-x86_64/libwasmtime.a +for d in "linux-x86_64" "macos-x86_64" "macos-aarch64"; do + ln -s "$build/libwasmtime.a" "build/$d/libwasmtime.a" +done + cp "$wasmtime"/crates/c-api/include/*.h build/include cp -r "$wasmtime"/crates/c-api/include/wasmtime build/include cp "$wasmtime"/crates/c-api/wasm-c-api/include/*.h build/include diff --git a/ffi.go b/ffi.go index 4468a6d..7d47d7b 100644 --- a/ffi.go +++ b/ffi.go @@ -7,6 +7,7 @@ package wasmtime // #cgo linux,amd64 LDFLAGS:-L${SRCDIR}/build/linux-x86_64 // #cgo linux,arm64 LDFLAGS:-L${SRCDIR}/build/linux-aarch64 // #cgo darwin,amd64 LDFLAGS:-L${SRCDIR}/build/macos-x86_64 +// #cgo darwin,arm64 LDFLAGS:-L${SRCDIR}/build/macos-aarch64 // #cgo windows,amd64 LDFLAGS:-L${SRCDIR}/build/windows-x86_64 // #include import "C" diff --git a/includebuild.go b/includebuild.go index f8eceb5..29ab90d 100644 --- a/includebuild.go +++ b/includebuild.go @@ -13,6 +13,7 @@ import ( _ "github.com/bytecodealliance/wasmtime-go/build/include" _ "github.com/bytecodealliance/wasmtime-go/build/include/wasmtime" _ "github.com/bytecodealliance/wasmtime-go/build/linux-x86_64" + _ "github.com/bytecodealliance/wasmtime-go/build/macos-aarch64" _ "github.com/bytecodealliance/wasmtime-go/build/macos-x86_64" _ "github.com/bytecodealliance/wasmtime-go/build/windows-x86_64" )