diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c5541612..9e459d3e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,11 +20,32 @@ jobs: test: name: Make test - runs-on: core + strategy: + matrix: + target: [ + x86_64-unknown-linux-gnu, + x86_64-apple-darwin, + aarch64-apple-darwin, + ] + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + - target: x86_64-apple-darwin + os: macos-latest-large + - target: aarch64-apple-darwin + os: macos-latest-xlarge + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - uses: dsherret/rust-toolchain-file@v1 - run: rustup target add wasm32-unknown-unknown - run: rustup component add rust-src + + - run: sudo apt update && sudo apt install -y clang lld + if: ${{ contains(matrix.target, 'linux') }} + + - run: brew install llvm + if: ${{ contains(matrix.target, 'apple') }} + - name: Run `make test` run: make test diff --git a/Makefile b/Makefile index cae8124c..f1230d30 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,9 @@ contracts: setup-compiler ## Build example contracts @contracts/c-example/build.sh @find target/wasm64-unknown-unknown/release -maxdepth 1 -name "*.wasm" \ | xargs -I % basename % \ - | xargs -I % wasm-tools strip -a \ + | xargs -I % ./scripts/strip.sh \ target/wasm64-unknown-unknown/release/% \ - -o target/stripped/% + target/stripped/% test: contracts cold-reboot assert-counter-contract-small ## Run all tests @cargo test \ diff --git a/scripts/strip.sh b/scripts/strip.sh new file mode 100755 index 00000000..dd1ee2d4 --- /dev/null +++ b/scripts/strip.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# The script should check whether the inputs are set, or print usage +# information otherwise. +if [ -z "$1" ] || [ -z "$2" ]; then + echo "Usage: $0 " + exit 1 +fi + +TRIPLE=$(rustc -vV | sed -n 's|host: ||p') +ARCH=$(echo "$TRIPLE" | cut -f 1 -d'-') + +# This is a bit of a mess because target triples are pretty inconsistent +OS=$(echo "$TRIPLE" | cut -f 2 -d'-') +# If OS is not currently linux, or apple, then we get it again +if [ "$OS" != "linux" ] && [ "$OS" != "apple" ]; then + OS=$(echo "$TRIPLE" | cut -f 3 -d'-') +fi +if [ "$OS" != "linux" ] && [ "$OS" != "apple" ]; then + echo "OS not supported: $OS" + exit 1 +fi +# If OS is apple, change it to macos +if [ "$OS" = "apple" ]; then + OS="macos" +fi + +RELEASES_URL=https://github.com/bytecodealliance/wasm-tools/releases/download + +PROGRAM_VERSION=1.0.54 + +ARTIFACT_NAME=wasm-tools-$PROGRAM_VERSION-$ARCH-$OS.tar.gz +ARTIFACT_URL=$RELEASES_URL/wasm-tools-$PROGRAM_VERSION/$ARTIFACT_NAME + +ARTIFACT_DIR=$PWD/target/wasm-tools/$PROGRAM_VERSION +ARTIFACT_PATH=$ARTIFACT_DIR/$ARTIFACT_NAME + +# If the artifact doesn't already exist in the target directory, download it, +# otherwise skip. +if [ ! -f "$ARTIFACT_PATH" ]; then + echo "Downloading wasm-tools version $PROGRAM_VERSION" + mkdir -p "$ARTIFACT_DIR" + curl -L "$ARTIFACT_URL" -o "$ARTIFACT_PATH" +fi + +# Extract the tarball, if they aren't already extracted +EXTRACTED_DIR=$ARTIFACT_DIR/extracted + +if [ ! -d "$EXTRACTED_DIR" ]; then + mkdir -p "$EXTRACTED_DIR" + tar -xzf "$ARTIFACT_PATH" -C "$EXTRACTED_DIR" --strip-components=1 +fi + +"$EXTRACTED_DIR"/wasm-tools strip -a "$1" -o "$2"