Skip to content

Commit

Permalink
Add basic macOS arm64 support (#102)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
danielledeleo authored Oct 1, 2021
1 parent c9b7e4e commit ec2575c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions build/macos-aarch64/empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package macos_aarch64
8 changes: 5 additions & 3 deletions ci/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
1 change: 1 addition & 0 deletions ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <wasm.h>
import "C"
Expand Down
1 change: 1 addition & 0 deletions includebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit ec2575c

Please sign in to comment.