-
Notifications
You must be signed in to change notification settings - Fork 18
Replace wasm-pack #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
timokoessler
wants to merge
12
commits into
new-instrumentation
Choose a base branch
from
replace-wasm-pack
base: new-instrumentation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+315
−22
Open
Replace wasm-pack #690
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7b38396
Replace wasm-pack
timokoessler 58b10b7
Remove checksum check
timokoessler cb30942
Fix path, print dl url
timokoessler 46606cc
Fix wasm-bindgen linux gnu and musl
timokoessler 0edb697
Add some more output
timokoessler 04c2bf9
Support building wasm on windows
timokoessler e18545b
Merge branch 'new-instrumentation' into replace-wasm-pack
timokoessler 8f2cc17
Bump wasm-bindgen version
timokoessler 14c490d
Merge branch 'new-instrumentation' into replace-wasm-pack
timokoessler 3dc67dd
Bump binaryen
timokoessler 1b1ee7c
Fix linting
timokoessler 6aacd51
Merge branch 'new-instrumentation' into replace-wasm-pack
timokoessler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| target/ | ||
| target/ | ||
| .bin/ |
This file contains hidden or 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 hidden or 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,122 @@ | ||
| #!/usr/bin/env pwsh | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| # ------ CONFIGURATION ------ | ||
| $TARGET = "nodejs" | ||
| $OUT_DIR = "..\library\agent\hooks\instrumentation\wasm" | ||
| $GENERATE_DTS = $false | ||
|
|
||
| $BINARYEN_VERSION = 124 | ||
| $WASM_BINDGEN_VERSION = "0.2.101" | ||
|
|
||
| # --------------------------- | ||
|
|
||
| Write-Host "Starting build process for wasm module" | ||
|
|
||
| # Always run from script's own directory | ||
| $SCRIPT_DIR = Split-Path -Parent (Resolve-Path $MyInvocation.MyCommand.Path) | ||
| Push-Location $SCRIPT_DIR | ||
|
|
||
| # Create directories | ||
| New-Item -ItemType Directory -Path ".\.bin\tmp" -Force | Out-Null | ||
| New-Item -ItemType Directory -Path $OUT_DIR -Force | Out-Null | ||
|
|
||
| function Download-Binaryen { | ||
timokoessler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $BINARYEN_BASE_URL = "https://github.com/WebAssembly/binaryen/releases/download/version_$BINARYEN_VERSION" | ||
| $BINARYEN_EXTRACT_DIR = "binaryen" | ||
| $ARCH = "x86_64" | ||
| $OS = "windows" | ||
|
|
||
| $FILE = "binaryen-version_${BINARYEN_VERSION}-${ARCH}-${OS}.tar.gz" | ||
|
|
||
| Push-Location ".\.bin\tmp" | ||
| Write-Host "Downloading from $BINARYEN_BASE_URL/$FILE" | ||
| Invoke-WebRequest "$BINARYEN_BASE_URL/$FILE" -OutFile $FILE | ||
| New-Item -ItemType Directory -Path "..\$BINARYEN_EXTRACT_DIR" -Force | Out-Null | ||
| tar -xzf $FILE -C "..\$BINARYEN_EXTRACT_DIR" --strip-components=1 | ||
| Pop-Location | ||
| } | ||
|
|
||
| function Download-WasmBindgen { | ||
| $WASM_BINDGEN_URL_BASE = "https://github.com/wasm-bindgen/wasm-bindgen/releases/download/$WASM_BINDGEN_VERSION" | ||
| $WASM_BINDGEN_DIR = "wasm-bindgen" | ||
| $ARCH = "x86_64" | ||
| $OS = "pc-windows-msvc" | ||
|
|
||
| $FILE = "wasm-bindgen-${WASM_BINDGEN_VERSION}-${ARCH}-${OS}.tar.gz" | ||
|
|
||
| Push-Location ".\.bin\tmp" | ||
| Write-Host "Downloading from $WASM_BINDGEN_URL_BASE/$FILE" | ||
| Invoke-WebRequest "$WASM_BINDGEN_URL_BASE/$FILE" -OutFile $FILE | ||
| New-Item -ItemType Directory -Path "..\$WASM_BINDGEN_DIR" -Force | Out-Null | ||
| tar -xzf $FILE -C "..\$WASM_BINDGEN_DIR" --strip-components=1 | ||
| Pop-Location | ||
| } | ||
|
|
||
| # Ensure rustc >= 1.30.0 | ||
| $MIN_RUSTC_VERSION = "1.30.0" | ||
| $RUSTC_VERSION = (& rustc --version).Split()[1] | ||
|
|
||
| if ([Version]$RUSTC_VERSION -lt [Version]$MIN_RUSTC_VERSION) { | ||
| Write-Error "rustc >= $MIN_RUSTC_VERSION required, found $RUSTC_VERSION" | ||
| exit 1 | ||
| } | ||
|
|
||
| Write-Host "Using rustc version: $RUSTC_VERSION" | ||
|
|
||
| # Ensure wasm32 target is installed | ||
| $LIBDIR = & rustc --target wasm32-unknown-unknown --print target-libdir | ||
| if (-not (Test-Path $LIBDIR)) { | ||
| Write-Host "Target wasm32-unknown-unknown not installed. Installing..." | ||
| if (-not (Get-Command rustup -ErrorAction SilentlyContinue)) { | ||
| Write-Error "rustup not installed. Install target manually or install rustup." | ||
| exit 1 | ||
| } | ||
| rustup target add wasm32-unknown-unknown | ||
| } | ||
|
|
||
| # Check binaryen | ||
| if (-not (Test-Path ".bin\binaryen")) { | ||
| Write-Host "Downloading binaryen..." | ||
| Download-Binaryen | ||
| } | ||
| else { | ||
| Write-Host "Found existing binaryen installation." | ||
| } | ||
|
|
||
| # Check wasm-bindgen | ||
| if (-not (Test-Path ".bin\wasm-bindgen")) { | ||
| Write-Host "Downloading wasm-bindgen..." | ||
| Download-WasmBindgen | ||
| } | ||
| else { | ||
| Write-Host "Found existing wasm-bindgen installation." | ||
| } | ||
|
|
||
| Remove-Item -Recurse -Force ".\.bin\tmp" | ||
|
|
||
| # Build wasm module | ||
| Write-Host "Building wasm module..." | ||
|
|
||
| cargo build --target wasm32-unknown-unknown --release | ||
|
|
||
| # Extract crate name using PowerShell JSON parsing | ||
| $metadata = & cargo metadata --format-version=1 --no-deps | ||
| $CRATE_NAME = ($metadata | ConvertFrom-Json).packages[0].name | ||
| $WASM_PATH = "target\wasm32-unknown-unknown\release\${CRATE_NAME}.wasm" | ||
|
|
||
| # wasm-bindgen | ||
| Write-Host "Running wasm-bindgen..." | ||
| $WASM_BINDGEN_OPTS = @("--out-dir", $OUT_DIR, "--target", $TARGET) | ||
| if (-not $GENERATE_DTS) { | ||
| $WASM_BINDGEN_OPTS += "--no-typescript" | ||
| } | ||
| & ".\.bin\wasm-bindgen\wasm-bindgen.exe" @WASM_BINDGEN_OPTS $WASM_PATH | ||
|
|
||
| # wasm-opt | ||
| Write-Host "Running wasm-opt..." | ||
| & ".\.bin\binaryen\bin\wasm-opt.exe" -O3 --enable-bulk-memory --enable-nontrapping-float-to-int -o "$OUT_DIR\${CRATE_NAME}_bg.wasm" "$OUT_DIR\${CRATE_NAME}_bg.wasm" | ||
|
|
||
| Write-Host "Build completed successfully. Output is in $OUT_DIR" | ||
|
|
||
| Pop-Location | ||
This file contains hidden or 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,181 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| # ------ CONFIGURATION ------ | ||
|
|
||
| TARGET=nodejs | ||
| OUT_DIR=../library/agent/hooks/instrumentation/wasm | ||
| GENERATE_DTS=false | ||
|
|
||
| BINARYEN_VERSION=124 # wasm-opt | ||
| WASM_BINDGEN_VERSION=0.2.101 | ||
|
|
||
| # --------------------------- | ||
|
|
||
| echo "Starting build process for wasm module" | ||
|
|
||
| # Always run from script's own directory and return at the end | ||
| SCRIPT_DIR="$(cd "$(dirname "$(realpath "$0")")" && pwd)" | ||
| pushd "$SCRIPT_DIR" > /dev/null | ||
|
|
||
| # Create directories | ||
| mkdir -p ./.bin/tmp | ||
| mkdir -p "$OUT_DIR" | ||
|
|
||
| # ------ Functions ------ | ||
|
|
||
| download_binaryen() { | ||
| set -e | ||
|
|
||
| BINARYEN_BASE_URL="https://github.com/WebAssembly/binaryen/releases/download/version_$BINARYEN_VERSION" | ||
| BINARYEN_EXTRACT_DIR="binaryen" | ||
|
|
||
| # Detect OS | ||
| case "$(uname -s)" in | ||
| Linux*) OS="linux" ;; | ||
| Darwin*) OS="macos" ;; | ||
| *) echo "Unsupported OS"; exit 1 ;; | ||
| esac | ||
|
|
||
| # Detect ARCH | ||
| case "$(uname -m)" in | ||
| x86_64) ARCH="x86_64" ;; | ||
| aarch64|arm64) ARCH="arm64" ;; | ||
| *) echo "Unsupported arch"; exit 1 ;; | ||
| esac | ||
|
|
||
| # Adjust ARM label for Linux | ||
| [ "$ARCH" = "arm64" ] && [ "$OS" = "linux" ] && ARCH="aarch64" | ||
|
|
||
| FILE="binaryen-version_${BINARYEN_VERSION}-${ARCH}-${OS}.tar.gz" | ||
|
|
||
| mkdir -p ./.bin/tmp | ||
| cd ./.bin/tmp | ||
|
|
||
| echo "Downloading from $BINARYEN_BASE_URL/$FILE" | ||
|
|
||
| curl -LO --fail "$BINARYEN_BASE_URL/$FILE" | ||
|
|
||
| mkdir -p "../$BINARYEN_EXTRACT_DIR" | ||
| tar -xzf "$FILE" -C "../$BINARYEN_EXTRACT_DIR" --strip-components=1 | ||
|
|
||
| cd ../.. | ||
| rm -rf ./.bin/tmp | ||
| } | ||
|
|
||
| download_wasm_bindgen() { | ||
| set -e | ||
|
|
||
| WASM_BINDGEN_URL_BASE="https://github.com/wasm-bindgen/wasm-bindgen/releases/download/$WASM_BINDGEN_VERSION" | ||
| WASM_BINDGEN_DIR="wasm-bindgen" | ||
|
|
||
| # Detect OS and ARCH for wasm-bindgen | ||
| case "$(uname -s)" in | ||
| Linux*) | ||
| case "$(uname -m)" in | ||
| x86_64) | ||
| OS="unknown-linux-musl" | ||
| ARCH="x86_64" | ||
| ;; | ||
| aarch64|arm64) | ||
| OS="unknown-linux-gnu" | ||
| ARCH="aarch64" | ||
| ;; | ||
| *) echo "Unsupported arch for Linux"; exit 1 ;; | ||
| esac | ||
| ;; | ||
| Darwin*) | ||
| OS="apple-darwin" | ||
| case "$(uname -m)" in | ||
| x86_64) ARCH="x86_64" ;; | ||
| aarch64|arm64) ARCH="aarch64" ;; | ||
| *) echo "Unsupported arch for Darwin"; exit 1 ;; | ||
| esac | ||
| ;; | ||
| *) echo "Unsupported OS"; exit 1 ;; | ||
| esac | ||
|
|
||
| FILE="wasm-bindgen-${WASM_BINDGEN_VERSION}-${ARCH}-${OS}.tar.gz" | ||
|
|
||
| mkdir -p ./.bin/tmp | ||
| cd ./.bin/tmp | ||
|
|
||
| echo "Downloading from $WASM_BINDGEN_URL_BASE/$FILE" | ||
|
|
||
| curl -LO --fail "$WASM_BINDGEN_URL_BASE/$FILE" | ||
|
|
||
| mkdir -p "../$WASM_BINDGEN_DIR" | ||
| tar -xzf "$FILE" -C "../$WASM_BINDGEN_DIR" --strip-components=1 | ||
|
|
||
| cd ../.. | ||
| rm -rf ./.bin/tmp | ||
| } | ||
|
|
||
| # ------ Main Script ------ | ||
|
|
||
| # Ensure rustc >= 1.30.0 | ||
| MIN_RUSTC_VERSION=1.30.0 | ||
| RUSTC_VERSION=$(rustc --version | cut -d' ' -f2) | ||
|
|
||
| # Compare versions using sort | ||
| if ! printf '%s\n%s\n' "$MIN_RUSTC_VERSION" "$RUSTC_VERSION" | sort -VC; then | ||
| echo "rustc >= $MIN_RUSTC_VERSION required, found $RUSTC_VERSION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Using rustc version: $RUSTC_VERSION" | ||
|
|
||
| # Ensure wasm32 target is installed | ||
| LIBDIR=$(rustc --target wasm32-unknown-unknown --print target-libdir) | ||
|
|
||
| if [ ! -d "$LIBDIR" ]; then | ||
| echo "Target wasm32-unknown-unknown not installed. Installing using rustup..." | ||
|
|
||
| # Check if rustup is installed | ||
| if ! command -v rustup &> /dev/null; then | ||
| echo "rustup is not installed. Please install the wasm32-unknown-unknown target manually or install rustup." | ||
| exit 1 | ||
| fi | ||
|
|
||
| rustup target add wasm32-unknown-unknown | ||
| fi | ||
|
|
||
| # Check if binaryen is already downloaded | ||
| if [ ! -d ".bin/binaryen" ]; then | ||
| echo "Downloading binaryen..." | ||
| download_binaryen | ||
| else | ||
| echo "Found existing binaryen installation." | ||
| fi | ||
|
|
||
| # Check if wasm-bindgen is already downloaded | ||
| if [ ! -d ".bin/wasm-bindgen" ]; then | ||
| echo "Downloading wasm-bindgen..." | ||
| download_wasm_bindgen | ||
| else | ||
| echo "Found existing wasm-bindgen installation." | ||
| fi | ||
|
|
||
| # Build the wasm module | ||
| echo "Building wasm module..." | ||
| cargo build --target wasm32-unknown-unknown --release | ||
|
|
||
| CRATE_NAME=$(basename "$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].name')") | ||
| WASM_PATH=target/wasm32-unknown-unknown/release/${CRATE_NAME}.wasm | ||
|
|
||
| # wasm-bindgen | ||
| echo "Running wasm-bindgen..." | ||
| WASM_BINDGEN_OPTS=(--out-dir "$OUT_DIR" --target "$TARGET") | ||
| if [ "$GENERATE_DTS" != true ]; then | ||
| WASM_BINDGEN_OPTS+=(--no-typescript) | ||
| fi | ||
| ./.bin/wasm-bindgen/wasm-bindgen "${WASM_BINDGEN_OPTS[@]}" "$WASM_PATH" | ||
|
|
||
| # wasm-opt | ||
| echo "Running wasm-opt..." | ||
| ./.bin/binaryen/bin/wasm-opt -O3 --enable-bulk-memory --enable-nontrapping-float-to-int -o "$OUT_DIR/${CRATE_NAME}_bg.wasm" "$OUT_DIR/${CRATE_NAME}_bg.wasm" | ||
|
|
||
| echo "Build completed successfully. Output is in $OUT_DIR" | ||
|
|
||
| # Switch back to the original directory | ||
| popd > /dev/null |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.