Skip to content

Commit

Permalink
Merge pull request #31 from Lay3rLabs/wasi_setup
Browse files Browse the repository at this point in the history
Easier WASI setup
  • Loading branch information
calvinrp authored Sep 30, 2024
2 parents 0c09a3b + bba5295 commit 0472008
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Compiled files and executables
/target/
artifacts/
components/
internal/

# Code coverage
Expand Down
2 changes: 1 addition & 1 deletion Cargo-component.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ name = "lay3r:avs"
[[package.version]]
requirement = "^0.3.0"
version = "0.3.0"
digest = "sha256:5ca2842d9fbc411429870dfe3b69cb6f787f7cea30598518849cf2edf03c7ce2"
digest = "sha256:891753e8eab23c067ef8095359c28e4296a65faf416103e797f468dcb5f6b4a5"
29 changes: 29 additions & 0 deletions scripts/build_wasi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
command -v shellcheck >/dev/null && shellcheck "$0"

# Compiles all WASI components, places the output in components dir


OUTDIR="components"

rm -rf "$OUTDIR"
mkdir -p "$OUTDIR"

rm -rf target/wasm32-wasip1/release/*.wasm "$OUTDIR"

BASEDIR=$(pwd)
for C in wasi/*/Cargo.toml; do
DIR=$(dirname "$C")
echo "Building WASI component in $DIR"
(
cd "$DIR";
cargo component build --release
)
done

cp target/wasm32-wasip1/release/*.wasm "$OUTDIR"

ls -l "$OUTDIR"
cd "$OUTDIR"
sha256sum -- *.wasm | tee checksums.txt
2 changes: 1 addition & 1 deletion scripts/collect_wasm.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Remoes old artifacts, compile new ones (not in docker, but faster), and places in artifacts dir with checksum
# Removes old artifacts, compile new ones (not in docker, but faster), and places in artifacts dir with checksum

# clear out old data and prepare space
rm -rf artifacts
Expand Down
41 changes: 41 additions & 0 deletions scripts/setup_wasi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
command -v shellcheck >/dev/null && shellcheck "$0"

# The minimum Rust version we support
MSRV="1.80.0"

# install rustup if not present
if ! which rustup > /dev/null; then
echo "Installing Rustup tooling"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
fi

# ensure we have a recent-enough version of Rust
V=$(cargo --version | cut -f2 -d' ')
if [[ $V < $MSRV ]]; then
echo "Upgrading Rust to $MSRV"
rustup update stable
fi

# install the wasm32-wasi target
echo "Adding WASI tooling..."
rustup target add wasm32-wasip1
cargo install cargo-component

# setup wkg
if [[ $OSTYPE == 'darwin'* ]]; then
WKG_DIR="$HOME/Library/Application Support/wasm-pkg"
elif [[ $OSTYPE == 'linux'* ]]; then
WKG_DIR="$HOME/.config/wasm-pkg"
else
echo "Unsupported OS: $OSTYPE"
exit 1
fi
WKG_FILE="$WKG_DIR/config.toml"

if [ ! -f "$WKG_FILE" ]; then
echo "Creating wkg config file at $WKG_FILE"
mkdir -p "$WKG_DIR"
echo 'default_registry = "wa.dev"' > "$WKG_FILE"
fi
2 changes: 2 additions & 0 deletions wasi/square/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ in simple test cases. You can find a [more complete example here](https://github

## Setup

You can automatically run this setup via `./scripts/setup_wasi.sh` ([see source](../../scripts/setup_wasi.sh))

This requires Rust 1.80+. Please ensure you have that installed via `rustup`
before continuing.

Expand Down

0 comments on commit 0472008

Please sign in to comment.