Skip to content

Commit

Permalink
feat: add install script (#11)
Browse files Browse the repository at this point in the history
* feat: add install script

* ci: test install script

* cleanup: print where extism-py was installed to

* ci: only run install script ci for PRs
  • Loading branch information
zshipko authored Sep 25, 2024
1 parent c266bbf commit 967e40d
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "CI Install Script"

on: [pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- name: linux
os: ubuntu-latest
- name: macos
os: macos-latest
# - name: windows
# os: windows-latest
steps:
- uses: actions/checkout@v2

- name: Test Install Script (Linux)
run: |
sh install.sh
~/.local/bin/extism-py --version
if: runner.os != 'Windows'

# - name: Test Install Script Part1 (Windows)
# run: |
# powershell -executionpolicy bypass -File .\install-windows.ps1
# if: runner.os == 'Windows'

# - name: Test Install Script Part2 (Windows)
# run: |
# $env:Path = "C:\Program Files\Extism\;C:\Program Files\Binaryen\;" + $env:Path
# extism-py --version
# if: runner.os == 'Windows'
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ This PDK uses [PyO3](https://github.com/PyO3/pyo3) and [wizer](https://github.co

We release the compiler as native binaries you can download and run. Check the [releases](https://github.com/extism/python-pdk/releases) page for the latest.

## Install Script

### Linux, macOS

```bash
curl -O https://raw.githubusercontent.com/extism/python-pdk/main/install.sh
sh install.sh
```

This will install `extism-py` (and `wasm-merge`/`wasm-opt` if not already installed) to `$HOME/.local/bin` and create `$HOME/.local/share/extism-py`

### Testing the Install

> *Note*: [Binaryen](https://github.com/WebAssembly/binaryen), specifically the `wasm-merge` and `wasm-opt` tools
Expand Down
73 changes: 73 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
set -e

OS=''
case `uname` in
Darwin*) OS="macos" ;;
Linux*) OS="linux" ;;
*) echo "unknown os: $OSTYPE" && exit 1 ;;
esac

ARCH=`uname -m`
case "$ARCH" in
ix86*|x86_64*) ARCH="x86_64" ;;
arm64*|aarch64*) ARCH="aarch64" ;;
*) echo "unknown arch: $ARCH" && exit 1 ;;
esac

export TAG=v0.1.0
export BINARYEN_TAG="version_116"

curl -L -o /tmp/extism-py.tar.gz "https://github.com/extism/python-pdk/releases/download/$TAG/extism-py-$ARCH-$OS-$TAG.tar.gz"

tar xzf /tmp/extism-py.tar.gz
mkdir -p $HOME/.local/bin $HOME/.local/share/extism-py
mv extism-py/bin/extism-py $HOME/.local/bin/extism-py
rm -rf $HOME/.local/share/extism-py
mv extism-py/share/extism-py $HOME/.local/share
chmod +x $HOME/.local/bin/extism-py
rm -r /tmp/extism-py.tar.gz extism-py

echo "extism-py installed to $HOME/.local/bin/extism-py"

if ! which "wasm-merge" > /dev/null || ! which "wasm-opt" > /dev/null; then
echo 'Missing binaryen tool(s)'

# binaryen use arm64 instead where as extism-py uses aarch64 for release file naming
case "$ARCH" in
aarch64*) ARCH="arm64" ;;
esac

# matches the case where the user installs extism-pdk in a Linux-based Docker image running on mac m1
# binaryen didn't have arm64 release file for linux
if [ $ARCH = "arm64" ] && [ $OS = "linux" ]; then
ARCH="x86_64"
fi

if [ $OS = "macos" ]; then
echo "Installing binaryen and wasm-merge using homebrew"
brew install binaryen
else
if [ ! -e "binaryen-$BINARYEN_TAG-$ARCH-$OS.tar.gz" ]; then
echo 'Downloading binaryen...'
curl -L -O "https://github.com/WebAssembly/binaryen/releases/download/$BINARYEN_TAG/binaryen-$BINARYEN_TAG-$ARCH-$OS.tar.gz"
fi
rm -rf 'binaryen' "binaryen-$BINARYEN_TAG"
tar xf "binaryen-$BINARYEN_TAG-$ARCH-$OS.tar.gz"
mv "binaryen-$BINARYEN_TAG"/ ./binaryen
if ! which 'wasm-merge' > /dev/null; then
echo "Installing wasm-merge..."
mv binaryen/bin/wasm-merge ~/.local/bin/wasm-merge
else
echo "wasm-merge is already installed"
fi
if ! which 'wasm-opt' > /dev/null; then
echo "Installing wasm-opt..."
mv binaryen/bin/wasm-opt ~/.local/bin/wasm-opt
else
echo "wasm-opt is already installed"
fi
fi
rm -rf ./binaryen
else
echo "wasm-merge and wasm-opt are already installed"
fi

0 comments on commit 967e40d

Please sign in to comment.