From 381df49df169a9e0f3e4a3797c0612ca73bbb46c Mon Sep 17 00:00:00 2001 From: Victor Adossi <123968127+vados-cosmonic@users.noreply.github.com> Date: Tue, 26 Nov 2024 05:30:12 +0900 Subject: [PATCH] feat: allow custom weval bin (#522) * feat: allow custom weval bin This commit enables specifying a custom `weval` binary to use when performing AOT. Signed-off-by: Victor Adossi * chore: set node version to v20.18.0 Signed-off-by: Victor Adossi * chore(ci): install weval during CI Signed-off-by: Victor Adossi * refactor(ci): get weval version dynamically Signed-off-by: Victor Adossi --------- Signed-off-by: Victor Adossi --- .github/workflows/main.yml | 51 +++++++++++++++++++++++++++++++++++++- src/cmd/componentize.js | 1 + src/jco.js | 1 + test/cli.js | 11 +++++--- 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f00022a70..594bd04eb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,6 +45,13 @@ jobs: macos-latest ] node: [18.x, 20.x, latest] + include: + - os: windows-latest + weval-bin-path: .weval-bin/weval.exe + - os: ubuntu-latest + weval-bin-path: .weval-bin/weval + - os: macos-latest + weval-bin-path: .weval-bin/weval exclude: - os: macos-latest node: 20.x @@ -61,19 +68,61 @@ jobs: - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} + + # Determine weval version + - name: Determine weval version + id: weval-meta + shell: bash + run: | + export WEVAL_LATEST_URL=`curl -Ls -o /dev/null -w %{url_effective} https://github.com/bytecodealliance/weval/releases/latest` + export WEVAL_VERSION=${WEVAL_LATEST_URL#https://github.com/bytecodealliance/weval/releases/tag/} + echo -e "version=$WEVAL_VERSION" >> $GITHUB_OUTPUT + + # Use cached weval bin if present + - name: Cache weval bin + id: cache-weval-bin + uses: actions/cache@v4 + with: + path: .weval-bin + key: weval-bin-${{ steps.weval-meta.outputs.version }}-${{ matrix.os }} + + # (no cached weval bin) download weval release + - if: ${{ steps.cache-weval-bin.outputs.cache-hit != 'true' && matrix.os == 'ubuntu-latest' }} + run: | + curl -LO https://github.com/bytecodealliance/weval/releases/download/${{ steps.weval-meta.outputs.version }}/weval-${{ steps.weval-meta.outputs.version }}-x86_64-linux.tar.xz + tar -xvJf weval-${{ steps.weval-meta.outputs.version }}-x86_64-linux.tar.xz + mv weval-${{ steps.weval-meta.outputs.version }}-x86_64-linux/weval .weval-bin + - if: ${{ steps.cache-weval-bin.outputs.cache-hit != 'true' && matrix.os == 'windows-latest' }} + run: | + curl -LO https://github.com/bytecodealliance/weval/releases/download/${{ steps.weval-meta.outputs.version }}/weval-${{ steps.weval-meta.outputs.version }}-x86_64-windows.zip + unzip weval-${{ steps.weval-meta.outputs.version }}-x86_64-windows.zip + mv weval-${{ steps.weval-meta.outputs.version }}-x86_64-windows .weval-bin + - if: ${{ steps.cache-weval-bin.outputs.cache-hit != 'true' && matrix.os == 'macos-latest' }} + run: | + curl -LO https://github.com/bytecodealliance/weval/releases/download/${{ steps.weval-meta.outputs.version }}/weval-${{ steps.weval-meta.outputs.version }}-aarch64-macos.tar.xz + tar -xvJf weval-${{ steps.weval-meta.outputs.version }}-aarch64-macos.tar.xz + mkdir .weval-bin + mv weval-${{ steps.weval-meta.outputs.version }}-aarch64-macos/weval .weval-bin/ + + # Perform NPM install - name: Install NPM packages run: npm ci + - name: Download Build uses: actions/download-artifact@v4 with: name: jco-build path: obj + - name: Test LTS Node.js run: npm run test:lts if: matrix.node == '18.x' || matrix.node == '20.x' + - name: Test Latest Node.js - run: npm run test if: matrix.node == 'latest' + env: + WEVAL_BIN_PATH: ${{ matrix.weval-bin-path }} + run: npm run test build-wasi-tests: name: WASI Test Generation diff --git a/src/cmd/componentize.js b/src/cmd/componentize.js index 318d961d0..3890a09bc 100644 --- a/src/cmd/componentize.js +++ b/src/cmd/componentize.js @@ -10,6 +10,7 @@ export async function componentize (jsSource, opts) { const source = await readFile(jsSource, 'utf8'); const { component } = await componentizeFn(source, { enableAot: opts.aot, + wevalBin: opts.wevalBin, sourceName: basename(jsSource), witPath: resolve(opts.wit), worldName: opts.worldName, diff --git a/src/jco.js b/src/jco.js index 7809f1453..99ef7cde6 100755 --- a/src/jco.js +++ b/src/jco.js @@ -34,6 +34,7 @@ program.command('componentize') .requiredOption('-w, --wit ', 'WIT path to build with') .option('-n, --world-name ', 'WIT world to build') .option('--aot', 'Enable Weval AOT compilation of JS') + .option('--weval-bin ', 'Specify a custom weval binary to use') .addOption(new Option('-d, --disable ', 'disable WASI features').choices(['clocks', 'http', 'random', 'stdio', 'all'])) // .addOption(new Option('-e, --enable ', 'enable WASI features').choices(['http'])) .option('--preview2-adapter ', 'provide a custom preview2 adapter path') diff --git a/test/cli.js b/test/cli.js index 923f051c4..de4632f92 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,5 +1,5 @@ import { resolve } from "node:path"; -import { execArgv } from "node:process"; +import { execArgv, env } from "node:process"; import { deepStrictEqual, ok, strictEqual } from "node:assert"; import { mkdir, @@ -504,7 +504,7 @@ export async function cliTest(_fixtures) { }); test("Componentize", async () => { - const { stdout, stderr } = await exec( + const args = [ jcoPath, "componentize", "test/fixtures/componentize/source.js", @@ -515,7 +515,12 @@ export async function cliTest(_fixtures) { "test/fixtures/componentize/source.wit", "-o", outFile - ); + ]; + if (env.WEVAL_BIN_PATH) { + args.push("--weval-bin", env.WEVAL_BIN_PATH); + } + + const { stdout, stderr } = await exec(...args); strictEqual(stderr, ""); { const { stderr } = await exec(