diff --git a/.github/actions/setup-binaryen/action.yml b/.github/actions/setup-binaryen/action.yml deleted file mode 100644 index f528df4..0000000 --- a/.github/actions/setup-binaryen/action.yml +++ /dev/null @@ -1,131 +0,0 @@ -name: 'Setup Binaryen' -description: 'Install Binaryen WebAssembly toolchain' -inputs: - version: - description: 'Binaryen version to install' - required: false - default: '124' - install-path: - description: 'Directory to install Binaryen to' - required: false - default: '/opt/binaryen' - -outputs: - binaryen-path: - description: 'Path to the installed Binaryen' - value: ${{ steps.install-unix.outputs.binaryen-path || steps.install-windows.outputs.binaryen-path }} - binaryen-version: - description: 'Version of Binaryen that was installed' - value: ${{ inputs.version }} - -runs: - using: 'composite' - steps: - - name: Detect platform - id: platform - shell: bash - run: | - case "$RUNNER_OS" in - Linux) - echo "os=linux" >> $GITHUB_OUTPUT - ;; - macOS) - echo "os=macos" >> $GITHUB_OUTPUT - ;; - Windows) - echo "os=windows" >> $GITHUB_OUTPUT - ;; - *) - echo "Unsupported OS: $RUNNER_OS" - exit 1 - ;; - esac - - case "$RUNNER_ARCH" in - X64) - if [ "$RUNNER_OS" = "Linux" ]; then - echo "arch=x86_64" >> $GITHUB_OUTPUT - else - echo "arch=x86_64" >> $GITHUB_OUTPUT - fi - ;; - ARM64) - if [ "$RUNNER_OS" = "Linux" ]; then - echo "arch=aarch64" >> $GITHUB_OUTPUT - else - echo "arch=arm64" >> $GITHUB_OUTPUT - fi - ;; - *) - echo "Unsupported architecture: $RUNNER_ARCH" - exit 1 - ;; - esac - - - name: Download and install Binaryen (Unix) - id: install-unix - if: runner.os != 'Windows' - shell: bash - env: - VERSION: ${{ inputs.version }} - INSTALL_PATH: ${{ inputs.install-path }} - OS: ${{ steps.platform.outputs.os }} - ARCH: ${{ steps.platform.outputs.arch }} - run: | - TARBALL="binaryen-version_${VERSION}-${ARCH}-${OS}.tar.gz" - URL="https://github.com/WebAssembly/binaryen/releases/download/version_${VERSION}/${TARBALL}" - - echo "Downloading Binaryen ${VERSION} for ${ARCH}-${OS}" - echo "URL: ${URL}" - - curl -L -o binaryen.tar.gz "${URL}" - - mkdir -p "${INSTALL_PATH}" - tar -xzf binaryen.tar.gz -C "${INSTALL_PATH}" --strip-components=1 - rm binaryen.tar.gz - - echo "binaryen-path=${INSTALL_PATH}" >> $GITHUB_OUTPUT - echo "${INSTALL_PATH}/bin" >> $GITHUB_PATH - - echo "Binaryen installed to ${INSTALL_PATH}" - - - name: Download and install Binaryen (Windows) - id: install-windows - if: runner.os == 'Windows' - shell: pwsh - env: - VERSION: ${{ inputs.version }} - INSTALL_PATH: ${{ inputs.install-path }} - OS: ${{ steps.platform.outputs.os }} - ARCH: ${{ steps.platform.outputs.arch }} - run: | - $TARBALL = "binaryen-version_$env:VERSION-$env:ARCH-$env:OS.tar.gz" - $URL = "https://github.com/WebAssembly/binaryen/releases/download/version_$env:VERSION/$TARBALL" - - Write-Host "Downloading Binaryen $env:VERSION for $env:ARCH-$env:OS" - Write-Host "URL: $URL" - - Invoke-WebRequest -Uri $URL -OutFile binaryen.tar.gz - - New-Item -ItemType Directory -Force -Path $env:INSTALL_PATH | Out-Null - tar -xzf binaryen.tar.gz -C $env:INSTALL_PATH --strip-components=1 - Remove-Item binaryen.tar.gz - - Write-Output "binaryen-path=$env:INSTALL_PATH" >> $env:GITHUB_OUTPUT - Write-Output "$env:INSTALL_PATH\bin" >> $env:GITHUB_PATH - - Write-Host "Binaryen installed to $env:INSTALL_PATH" - - - name: Verify installation (Unix) - if: runner.os != 'Windows' - shell: bash - run: | - wasm-opt --version - echo "Binaryen installation verified" - - - name: Verify installation (Windows) - if: runner.os == 'Windows' - shell: pwsh - run: | - & wasm-opt --version - Write-Host "Binaryen installation verified" diff --git a/.github/actions/setup-wabt/action.yml b/.github/actions/setup-wabt/action.yml deleted file mode 100644 index 6c1d226..0000000 --- a/.github/actions/setup-wabt/action.yml +++ /dev/null @@ -1,123 +0,0 @@ -name: 'Setup WABT' -description: 'Install WebAssembly Binary Toolkit (WABT)' -inputs: - version: - description: 'WABT version to install' - required: false - default: '1.0.39' - install-path: - description: 'Directory to install WABT to' - required: false - default: '/opt/wabt' - -outputs: - wabt-path: - description: 'Path to the installed WABT' - value: ${{ steps.install-unix.outputs.wabt-path || steps.install-windows.outputs.wabt-path }} - wabt-version: - description: 'Version of WABT that was installed' - value: ${{ inputs.version }} - -runs: - using: 'composite' - steps: - - name: Detect platform - id: platform - shell: bash - run: | - case "$RUNNER_OS" in - Linux) - echo "os=linux" >> $GITHUB_OUTPUT - ;; - macOS) - echo "os=macos" >> $GITHUB_OUTPUT - ;; - Windows) - echo "os=windows" >> $GITHUB_OUTPUT - ;; - *) - echo "Unsupported OS: $RUNNER_OS" - exit 1 - ;; - esac - - case "$RUNNER_ARCH" in - X64) - echo "arch=x64" >> $GITHUB_OUTPUT - ;; - ARM64) - echo "arch=arm64" >> $GITHUB_OUTPUT - ;; - *) - echo "Unsupported architecture: $RUNNER_ARCH" - exit 1 - ;; - esac - - - name: Download and install WABT (Unix) - id: install-unix - if: runner.os != 'Windows' - shell: bash - env: - VERSION: ${{ inputs.version }} - INSTALL_PATH: ${{ inputs.install-path }} - OS: ${{ steps.platform.outputs.os }} - ARCH: ${{ steps.platform.outputs.arch }} - run: | - TARBALL="wabt-${VERSION}-${OS}-${ARCH}.tar.gz" - URL="https://github.com/WebAssembly/wabt/releases/download/${VERSION}/${TARBALL}" - - echo "Downloading WABT ${VERSION} for ${OS}-${ARCH}" - echo "URL: ${URL}" - - curl -L -o wabt.tar.gz "${URL}" - - mkdir -p "${INSTALL_PATH}" - tar -xzf wabt.tar.gz -C "${INSTALL_PATH}" --strip-components=1 - rm wabt.tar.gz - - echo "wabt-path=${INSTALL_PATH}" >> $GITHUB_OUTPUT - echo "${INSTALL_PATH}/bin" >> $GITHUB_PATH - - echo "WABT installed to ${INSTALL_PATH}" - - - name: Download and install WABT (Windows) - id: install-windows - if: runner.os == 'Windows' - shell: pwsh - env: - VERSION: ${{ inputs.version }} - INSTALL_PATH: ${{ inputs.install-path }} - OS: ${{ steps.platform.outputs.os }} - ARCH: ${{ steps.platform.outputs.arch }} - run: | - $TARBALL = "wabt-$env:VERSION-$env:OS-$env:ARCH.tar.gz" - $URL = "https://github.com/WebAssembly/wabt/releases/download/$env:VERSION/$TARBALL" - - Write-Host "Downloading WABT $env:VERSION for $env:OS-$env:ARCH" - Write-Host "URL: $URL" - - Invoke-WebRequest -Uri $URL -OutFile wabt.tar.gz - - New-Item -ItemType Directory -Force -Path $env:INSTALL_PATH | Out-Null - tar -xzf wabt.tar.gz -C $env:INSTALL_PATH --strip-components=1 - Remove-Item wabt.tar.gz - - Write-Output "wabt-path=$env:INSTALL_PATH" >> $env:GITHUB_OUTPUT - Write-Output "$env:INSTALL_PATH\bin" >> $env:GITHUB_PATH - - Write-Host "WABT installed to $env:INSTALL_PATH" - - - name: Verify installation (Unix) - if: runner.os != 'Windows' - shell: bash - run: | - wasm-objdump --version - echo "WABT installation verified" - - - name: Verify installation (Windows) - if: runner.os == 'Windows' - shell: pwsh - run: | - & wasm-objdump --version - Write-Host "WABT installation verified" diff --git a/.github/workflows/build-module.yml b/.github/workflows/build-module.yml deleted file mode 100644 index bf26032..0000000 --- a/.github/workflows/build-module.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Build hako.wasm -on: - push: - tags: - - 'v*' - branches: - - '**' - pull_request: - branches: - - '**' - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Install WASI SDK - uses: konsumer/install-wasi-sdk@v1 - with: - version: "27" - - - name: Setup Binaryen - uses: ./.github/actions/setup-binaryen - - - name: Setup Bun - uses: oven-sh/setup-bun@v2 - - - name: Setup WABT - uses: ./.github/actions/setup-wabt - - - name: Build hako.wasm - working-directory: engine - run: ./release-hako.sh - - - name: Generate bindings - working-directory: engine - run: bun run codegen.ts parse hako.wasm hako.h bindings.json - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: hako-wasm - path: | - engine/hako.wasm - engine/bindings.json - retention-days: 90 - if-no-files-found: error diff --git a/.github/workflows/dotnet-test.yml b/.github/workflows/dotnet-test.yml deleted file mode 100644 index 4cb015d..0000000 --- a/.github/workflows/dotnet-test.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: .NET Host Tests -on: - push: - branches: - - '**' - paths: - - 'hosts/dotnet/**' - - 'engine/**' - - '.github/workflows/dotnet-test.yml' - pull_request: - branches: - - '**' - paths: - - 'hosts/dotnet/**' - - 'engine/**' - - '.github/workflows/dotnet-test.yml' - workflow_call: - workflow_dispatch: - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Install WASI SDK - uses: konsumer/install-wasi-sdk@v1 - with: - version: "27" - - - name: Setup Binaryen - uses: ./.github/actions/setup-binaryen - - - name: Setup Bun - uses: oven-sh/setup-bun@v2 - - - name: Setup WABT - uses: ./.github/actions/setup-wabt - - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: | - 10.0.x - 9.0.x - dotnet-quality: 'preview' - - - name: Build engine - working-directory: hosts/dotnet/scripts - run: ./build-engine.sh - - - name: Restore solution - working-directory: hosts/dotnet - run: dotnet restore - - - name: Test Hako.Analyzers.Tests - working-directory: hosts/dotnet/Hako.Analyzers.Tests - run: dotnet test - - - name: Test Hako.SourceGenerator.Tests - working-directory: hosts/dotnet/Hako.SourceGenerator.Tests - run: dotnet test - - - name: Test Hako.Tests - working-directory: hosts/dotnet/Hako.Tests - run: dotnet test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d90de0..bc80ebb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,168 +1,101 @@ -name: Release +name: Publish to NPM on: push: tags: - 'v*' - jobs: - tests: - uses: ./.github/workflows/dotnet-test.yml - - package: - name: Package NuGet Packages - needs: [tests] + publish: runs-on: ubuntu-latest - env: - DevBuild: 'false' + + permissions: + contents: read + id-token: write + deployments: write + steps: - - name: Checkout repository + - name: checkout repository uses: actions/checkout@v4 with: submodules: recursive - - name: Install WASI SDK - uses: konsumer/install-wasi-sdk@v1 + - uses: actions/setup-node@v4 with: - version: "27" - - - name: Setup Binaryen - uses: ./.github/actions/setup-binaryen - - - name: Setup Bun + node-version: '22.14.0' + registry-url: 'https://registry.npmjs.org' + + - name: setup bun uses: oven-sh/setup-bun@v2 - - - name: Setup WABT - uses: ./.github/actions/setup-wabt - - - name: Setup .NET - uses: actions/setup-dotnet@v5 with: - dotnet-version: | - 10.0.x - 9.0.x - dotnet-quality: 'preview' + bun-version: '1.2.9' - - name: Extract version from tag - id: version - run: echo "VERSION=${GITHUB_REF_NAME:1}" >> $GITHUB_OUTPUT - - name: Build engine - working-directory: hosts/dotnet/scripts - run: ./build-engine.sh - - - name: Restore solution - working-directory: hosts/dotnet - run: dotnet restore - - - name: Pack Hako - working-directory: hosts/dotnet/Hako - run: dotnet pack -c Release /p:Packing=true /p:HakoVersion=${{ steps.version.outputs.VERSION }} /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg - - - name: Pack Hako.Backend - working-directory: hosts/dotnet/Hako.Backend - run: dotnet pack -c Release /p:Packing=true /p:HakoVersion=${{ steps.version.outputs.VERSION }} /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg - - - name: Pack Hako.Backend.Wasmtime - working-directory: hosts/dotnet/Hako.Backend.Wasmtime - run: dotnet pack -c Release /p:Packing=true /p:HakoVersion=${{ steps.version.outputs.VERSION }} /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg - - - name: Pack Hako.Backend.WACS - working-directory: hosts/dotnet/Hako.Backend.WACS - run: dotnet pack -c Release /p:Packing=true /p:HakoVersion=${{ steps.version.outputs.VERSION }} /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg - - - name: Pack Hako.Analyzers - working-directory: hosts/dotnet/Hako.Analyzers - run: dotnet pack -c Release /p:Packing=true /p:HakoVersion=${{ steps.version.outputs.VERSION }} /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg - - - name: Pack Hako.SourceGenerator - working-directory: hosts/dotnet/Hako.SourceGenerator - run: dotnet pack -c Release /p:Packing=true /p:HakoVersion=${{ steps.version.outputs.VERSION }} /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg - - - name: Upload packages - uses: actions/upload-artifact@v4 + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@802fa1a2c4e212495c05bf94dba2704a92a472be with: - name: nuget-packages - path: | - hosts/dotnet/**/bin/Release/*.nupkg - hosts/dotnet/**/bin/Release/*.snupkg - retention-days: 30 - if-no-files-found: error - - create-release: - name: Create GitHub Release - needs: package - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Get tag name - id: tag - run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - - - name: Download packages - uses: actions/download-artifact@v4 - with: - name: nuget-packages - path: packages - - - name: Generate checksums - run: | - cd packages - find . -name "*.nupkg" -o -name "*.snupkg" | xargs shasum -a 256 > checksums.txt - cat checksums.txt - - - name: Create Release - uses: softprops/action-gh-release@v2 - if: github.ref_type == 'tag' - with: - files: | - packages/**/*.nupkg - packages/**/*.snupkg - packages/checksums.txt - body: | - ## Hako ${{ steps.tag.outputs.TAG_NAME }} - - ### .NET Packages - - Install via NuGet: - ```bash - dotnet add package Hako --version ${{ steps.tag.outputs.TAG_NAME }} - dotnet add package Hako.Backend.Wasmtime --version ${{ steps.tag.outputs.TAG_NAME }} - ``` - - ### Packages Included + cmake-version: '4.0.x' - - `Hako` - Core JavaScript engine - - `Hako.Backend` - Backend abstraction - - `Hako.Backend.Wasmtime` - [wasmtime](https://wasmtime.dev/) backend - - `Hako.Backend.WACS` - [WACS](https://github.com/kelnishi/WACS) backend - - `Hako.Analyzers` - Roslyn analyzers - - `Hako.SourceGenerator` - Source generators for bindings + - name: envsetup + run: chmod +x tools/envsetup.sh && tools/envsetup.sh - ### Checksums + - name: patch + run: chmod +x tools/patch.sh && tools/patch.sh - See `checksums.txt` for SHA-256 checksums of all packages. - draft: false - prerelease: false + # the TypeScript embedder is up first - publish: - name: Publish to NuGet - needs: create-release - runs-on: ubuntu-latest - steps: - - name: Download packages - uses: actions/download-artifact@v4 - with: - name: nuget-packages - path: packages - - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: '9.0.x' - - - name: Publish to NuGet + - name: install dependencies (TS) + working-directory: embedders/ts run: | - for package in packages/**/*.nupkg packages/**/*.snupkg; do - dotnet nuget push "$package" -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate - done \ No newline at end of file + # npm has a bug, nothing we can do. + rm -rf package-lock.json + npm i + # just until uwasi deploys a new version + npm run patch:deps + + - name: generate builds (TS) + working-directory: embedders/ts + run: npm run generate:builds + + - name: generate version (TS) + working-directory: embedders/ts + run: npm run generate:version + + - name: lint (TS) + working-directory: embedders/ts + run: | + source ${{ github.workspace }}/tools/third-party/env.sh + npm run lint + + - name: test (TS) + working-directory: embedders/ts + run: npm run test + + - name: build (TS) + working-directory: embedders/ts + run: npm run build + + # we will publish in a bit, let's build and publish REPL + - name: install dependencies (REPL) + working-directory: examples/repl + run: bun install + + - name: generate build (REPL) + working-directory: examples/repl + run: bun run build + + - name: publish REPL to cloudflare pages + uses: cloudflare/pages-action@v1 + with: + apiToken: ${{ secrets.PAGE_PUBLISH_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: hakorepl + directory: dist + gitHubToken: ${{ secrets.GITHUB_TOKEN }} + branch: production + workingDirectory: examples/repl + wranglerVersion: '3' + + - name: Publish package to NPM + working-directory: embedders/ts + run: npm publish --provenance --access public --tag latest + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index d4cbc4b..14dbdd1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,4 @@ hako.sln *.g.ts obj bin -tools/third-party -build -.idea \ No newline at end of file +tools/third-party \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 2b084d3..cf86ba2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "engine"] - path = engine - url = https://github.com/6over3/quickjs -[submodule "hosts/dotnet/modules/Ben.Demystifier"] - path = hosts/dotnet/modules/Ben.Demystifier - url = https://github.com/6over3/Ben.Demystifier +[submodule "primjs"] + path = primjs + url = https://github.com/lynx-family/primjs diff --git a/README.md b/README.md index 9147a31..40b84f2 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,61 @@
-
-
Hako (箱) means "box" in Japanese
+ +Hako (ha-ko) or 箱 means “box” in Japanese.
-[](https://github.com/6over3/hako/actions/workflows/build-module.yml) -[](https://github.com/6over3/hako/actions/workflows/dotnet-test.yml) -[](https://github.com/6over3/hako/actions/workflows/release.yml) [](https://www.apache.org/licenses/LICENSE-2.0.txt) + +Hako is a embeddable, lightweight, secure, high-performance JavaScript engine. It is a fork of PrimJS; Hako has full support for ES2019 and later ESNext features, and offers superior performance and a better development experience when compared to QuickJS. +
+
+
+
+
Hako (ha-ko) or 箱 means “box” in Japanese.
+ + +[](https://www.apache.org/licenses/LICENSE-2.0.txt) + + +Hako is a embeddable, lightweight, secure, high-performance JavaScript engine. It is a fork of PrimJS; Hako has full support for ES2019 and later ESNext features, and offers superior performance and a better development experience when compared to QuickJS. + +