From 90a2d6e6dd1873b8d775e77ef2211785ba56f353 Mon Sep 17 00:00:00 2001 From: Paul Berberian Date: Sun, 1 Sep 2024 20:30:46 +0200 Subject: [PATCH] Try adding GitHub actions on PRs --- .github/workflows/checks.yml | 87 +++++++++++++++++++++++ .gitignore | 2 + Cargo.lock | 21 +++--- Cargo.toml | 2 +- package.json | 4 ++ scripts/install_binaryen.sh | 133 +++++++++++++++++++++++++++++++++++ scripts/update_gh-pages_demo | 1 + 7 files changed, 239 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/checks.yml create mode 100755 scripts/install_binaryen.sh diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..9db7812 --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,87 @@ +# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Wasp-HLS PR check + +on: + push: + branches: [stable, dev, legacy-v3] + pull_request: + types: [opened, synchronize, reopened] + +jobs: + format_check: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: "npm" + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - run: npm install + - run: rustup component add rustfmt + - run: npm run fmt:check + - run: npm run fmt:check + + typechecking_and_linting: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: "npm" + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - run: npm install + - run: rustup target add wasm32-unknown-unknown + - run: rustup component add clippy + - run: cargo install wasm-bindgen-cli@0.2.93 + - run: npm run build:all + - run: npm run check + - run: npm run clippy + + release_build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: "npm" + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - run: npm install + - run: rustup target add wasm32-unknown-unknown + - run: rustup component add clippy + - run: cargo install wasm-bindgen-cli@0.2.93 + - run: npm run build:release diff --git a/.gitignore b/.gitignore index 60adb41..8a0b972 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ /wasm.d.ts /worker.js /worker.d.ts + +/tmp diff --git a/Cargo.lock b/Cargo.lock index 610cfaa..823e1e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,19 +86,20 @@ checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -111,9 +112,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -121,9 +122,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -134,9 +135,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wasp-hls" diff --git a/Cargo.toml b/Cargo.toml index 8b76059..e3682a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,5 @@ crate-type = ["cdylib"] path = "src/rs-core/lib.rs" [dependencies] -wasm-bindgen = "0.2.84" +wasm-bindgen = "0.2.93" thiserror = "1.0.40" diff --git a/package.json b/package.json index c097a7f..5c01fa7 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,11 @@ "doc": "rm -rf doc/generated && docgen.ico doc build/doc", "fmt": "npm run fmtr && npm run fmtt", "fmtr": "cargo fmt", + "fmtr:check": "cargo fmt --check", "fmtt": "prettier --write . --loglevel warn", + "fmtt:check": "prettier . --check", + "fmt:check": "npm run fmtr:check && npm run fmtt:check", + "install:binaryen": "./scripts/install_binaryen.sh", "lint": "npm run lint:main && npm run lint:worker && npm run lint:transmux && npm run lint:common && npm run lint:demo", "lint:common": "cd src/ts-common && eslint .", "lint:demo": "cd demo && eslint src/**/*", diff --git a/scripts/install_binaryen.sh b/scripts/install_binaryen.sh new file mode 100755 index 0000000..68f3df8 --- /dev/null +++ b/scripts/install_binaryen.sh @@ -0,0 +1,133 @@ +#!/bin/sh + +# TODO Documentation + +# Log a line to stdout, prefixing it with the name of this script +log() { + printf 'wasp-hls > install_binaryen: %s\n' "$1" +} + +# Log a line to sterr, prefixing it with the name of this script +err() { + log "ERROR: $1" >&2 + echo "" + echo "Please install a rust toolchain (with the \"wasm32-unknown-unknown\" target) and binaryen manually" >&2 + exit 1 +} + +# Checks that the command in argument exists, exits after printing the issue to +# stderr if that's not the case +requires_cmd() { + if ! command -v "$1" >/dev/null 2>&1; then + err "Need '$1' (command not found)" + fi +} + +# Run a command that should never fail. If the command fails execution +# will immediately terminate with an error showing the failing +# command. +ensure() { + if ! "$@"; then + err "Command failed: $*" + fi +} + +log "This script will install binaryen locally in the following directory: $(pwd)/tmp" + +requires_cmd curl +requires_cmd tar + +ensure mkdir -p tmp +rm -rf tmp/binaryen +rm -rf tmp/binaryen.tar.gz + +ostype="$(uname -s)" +cpuarch="$(uname -m)" + +if [ "$ostype" = Linux ]; then + if [ "$(uname -o)" = Android ]; then + err "Unhandled OS type (Android), please install binaryen manually" + fi +fi + +if [ "$ostype" = Darwin ] && [ "$cpuarch" = i386 ]; then + # Darwin `uname -m` lies + if sysctl hw.optional.x86_64 | grep -q ': 1'; then + cpuarch=x86_64 + fi +fi + +case "$ostype" in +Linux) ;; +Darwin) ;; +MINGW* | MSYS* | CYGWIN* | Windows_NT) + ostype=Windows + ;; +*) + err "Unhandled OS type ($ostype), please install binaryen manually" + ;; +esac + +case "$cpuarch" in +aarch64 | arm64) + cpuarch=aarch64 + ;; +x86_64 | x86-64 | x64 | amd64) + cpuarch=x86_64 + ;; +*) + err "Unhandled CPU type ($cpuarch), please install binaryen manually" + ;; +esac + +# TODO automatically download last binaryen? +# We might need to detect which build is available. Targeting version 116 is +# good enough for now +if [ "${ostype}" = Darwin ]; then + if [ "${cpuarch}" = aarch64 ]; then + log "Architecture detected -> MacOS ARM" + binaryen_url=https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-arm64-macos.tar.gz + else + log "Architecture detected -> MacOS x86_64" + binaryen_url=https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-x86_64-macos.tar.gz + fi +elif [ "${ostype}" = Linux ]; then + if [ "${cpuarch}" != x86_64 ]; then + err "For Linux, only x86_64 is supported by our auto-install script. Please install binaryen manually." + fi + log "Architecture detected -> Linux x86_64" + binaryen_url=https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-x86_64-linux.tar.gz +elif [ "${ostype}" = Windows ]; then + if [ "${cpuarch}" != x86_64 ]; then + err "For Windows, only x86_64 is supported by our auto-install script. Please install binaryen manually." + fi + log "Architecture detected -> Windows x86_64" + binaryen_url=https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-x86_64-windows.tar.gz +fi + +log "Fetching binaryen 116..." +curl -L $binaryen_url >tmp/binaryen.tar.gz +if ! [ $? -eq 0 ]; then + err "Failed to fetch binaryen" +fi + +cd tmp +ensure tar xzf binaryen.tar.gz + +ensure mv binaryen-version_116 binaryen + +# TODO I don't know my windows, does that still work as an executable or is it just dumb? +if [ "${ostype}" = Windows ]; then + ensure cp binaryen/bin/wasm-opt.exe binaryen/bin/wasm-opt +fi + +rm binaryen.tar.gz +cd .. + +if ! [ -f tmp/binaryen/bin/wasm-opt ]; then + err "Error after installing binaryen: wasm-opt not available in ./tmp/binaryen/bin/wasm-opt" +fi + +log "Binaryen has been installed in $pwd/tmp/binaryen" +log "You may now run binaryen-linked scripts by first adding \"$pwd/tmp/binaryen\" to PATH:" +log "PATH=\$PATH:~/tmp/binaryen/bin npm run " diff --git a/scripts/update_gh-pages_demo b/scripts/update_gh-pages_demo index 18c0555..670b7e6 100755 --- a/scripts/update_gh-pages_demo +++ b/scripts/update_gh-pages_demo @@ -97,3 +97,4 @@ else fi git checkout main +