-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
238 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: CI | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: ASDF plugin test | ||
strategy: | ||
matrix: | ||
platform: [ubuntu-latest, macos-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: asdf-vm/actions/plugin-test@v3 | ||
with: | ||
command: | | ||
wasm-opt --version | ||
env: | ||
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# asdf-binaryen | ||
|
||
[asdf](https://asdf-vm.com/) version manager plugin for installing [Binaryen](https://hermesengine.dev); the WebAssembly toolchain. | ||
|
||
## Installation | ||
|
||
```bash | ||
asdf plugin add https://github.com/cometkim/asdf-binaryen.git | ||
``` | ||
|
||
## Usage | ||
|
||
Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions. | ||
|
||
Library and header files are also included, you can find it in `$(asdf where binaryen)/lib/` and `$(asdf where binaryen)/include/` path. | ||
|
||
## LICENSE | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
current_script_path=${BASH_SOURCE[0]} | ||
plugin_dir=$(dirname "$(dirname "$current_script_path")") | ||
|
||
# shellcheck source=lib/utils.bash | ||
source "${plugin_dir}/lib/utils.bash" | ||
|
||
function download_version() { | ||
local version=$1 | ||
local download_path=$2 | ||
|
||
local bin_url | ||
bin_url=$(get_bin_url "$version") | ||
|
||
local tmpdir | ||
tmpdir=$(get_temp_dir) | ||
|
||
# shellcheck disable=SC2064 | ||
trap "rm -rf $tmpdir" EXIT | ||
|
||
( | ||
echo "Downloading Binaryen $version..." | ||
curl "${curl_opts[@]}" -o "$tmpdir/binaryen.tgz" "$bin_url" || fail "Couldn't download Binaryen from $bin_url" | ||
|
||
tar -xzf "$tmpdir/binaryen.tgz" -C "$tmpdir" | ||
cp -r "$tmpdir/binaryen-$version"/* $download_path" | ||
) || (rm -rf "$download_path"; fail "Failed to download Binaryen $version") | ||
} | ||
if [[ "$ASDF_INSTALL_TYPE" != "version" ]]; then | ||
fail "asdf-binaryen supports release install only" | ||
fi | ||
download_version "$ASDF_INSTALL_VERSION" "$ASDF_DOWNLOAD_PATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
current_script_path=${BASH_SOURCE[0]} | ||
plugin_dir=$(dirname "$(dirname "$current_script_path")") | ||
|
||
# shellcheck source=lib/utils.bash | ||
source "${plugin_dir}/lib/utils.bash" | ||
|
||
function install_version() { | ||
local version=$1 | ||
local download_path=$2 | ||
local install_path=$3 | ||
|
||
( | ||
mkdir -p "$install_path/bin" | ||
|
||
echo "Installing Hermes v$version..." | ||
|
||
cp -r "$download_path"/* "$install_path" | ||
chmod +x "$install_path/bin"/* | ||
|
||
echo "Binaryen $version is installed successfully!" | ||
echo "(Library and headers are also included)" | ||
) || (rm -rf "$install_path"; fail "Failed to install Binaryen $version") | ||
} | ||
|
||
if [[ "$ASDF_INSTALL_TYPE" != "version" ]]; then | ||
fail "asdf-binaryen supports release install only" | ||
fi | ||
|
||
install_version "$ASDF_INSTALL_VERSION" "$ASDF_DOWNLOAD_PATH" "$ASDF_INSTALL_PATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
current_script_path=${BASH_SOURCE[0]} | ||
plugin_dir=$(dirname "$(dirname "$current_script_path")") | ||
|
||
# shellcheck source=lib/utils.bash | ||
source "${plugin_dir}/lib/utils.bash" | ||
|
||
curl_opts=(-sI) | ||
|
||
if [ -n "${GITHUB_API_TOKEN:-}" ]; then | ||
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN") | ||
fi | ||
|
||
redirect_url=$(curl "${curl_opts[@]}" "$REPO_URL/releases/latest" | sed -n -e "s|^location: *||p" | sed -n -e "s|\r||p") | ||
version= | ||
printf "redirect url: %s\n" "$redirect_url" >&2 | ||
if [[ "$redirect_url" == "$REPO_URL/releases" ]]; then | ||
version="$(list_github_releases | sort_versions | tail -n1 | xargs echo)" | ||
else | ||
version="$(printf "%s\n" "$redirect_url" | sed 's|.*/tag/||')" | ||
fi | ||
|
||
printf "%s\n" "$version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
current_script_path=${BASH_SOURCE[0]} | ||
plugin_dir=$(dirname "$(dirname "$current_script_path")") | ||
|
||
# shellcheck source=lib/utils.bash | ||
source "${plugin_dir}/lib/utils.bash" | ||
|
||
list_github_releases | sort_versions | xargs echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
GITHUB_REPO="WebAssembly/binaryen" | ||
REPO_URL="https://github.com/$GITHUB_REPO" | ||
|
||
curl_opts=(-fsSL) | ||
if [ -n "${GITHUB_API_TOKEN:-}" ]; then | ||
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN") | ||
fi | ||
|
||
# stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942 | ||
function sort_versions() { | ||
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | | ||
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' | ||
} | ||
|
||
function list_github_releases() { | ||
curl "${curl_opts[@]}" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
"https://api.github.com/repos/$GITHUB_REPO/releases?per_page=100" | | ||
grep -o '"tag_name": "version_.*"' | | ||
sed -E 's/"tag_name": "(version_.*)"/\1/' | ||
} | ||
|
||
function get_platform() { | ||
case "$OSTYPE" in | ||
darwin*) echo -n "darwin" ;; | ||
linux*) echo -n "linux" ;; | ||
*) fail "Unsupported platform" ;; | ||
esac | ||
} | ||
|
||
function get_arch() { | ||
case "$(uname -m)" in | ||
x86_64) echo -n "x86_64" ;; | ||
arm64) echo -n "arm64";; | ||
aarch64) echo -n "aarch64" ;; | ||
*) fail "Unsupported architecture" ;; | ||
esac | ||
} | ||
|
||
function get_bin_target() { | ||
local version=$1 | ||
|
||
local platform | ||
platform=$(get_platform) | ||
|
||
local arch | ||
arch=$(get_arch) | ||
|
||
local target="$arch-$platform" | ||
|
||
echo -n "binaryen-$version-$target" | ||
} | ||
|
||
function get_bin_url() { | ||
local version=$1 | ||
|
||
local target | ||
target=$(get_bin_target $version) | ||
|
||
echo -n "$REPO_URL/releases/download/$version/$target.tar.gz" | ||
} | ||
|
||
function get_source_url() { | ||
local version=$1 | ||
|
||
echo -n "$REPO_URL/archive/$version.zip" | ||
} | ||
|
||
function get_temp_dir() { | ||
local base | ||
base="${TMPDIR:-/tmp}" | ||
base="${base%/}" | ||
|
||
local tmpdir | ||
tmpdir=$(mktemp -d "$base/asdf-binaryen.XXXX") | ||
|
||
echo -n "$tmpdir" | ||
} | ||
|
||
function fail() { | ||
echo -e "\e[31mFail:\e[m $*" 1>&2 | ||
exit 1 | ||
} |