Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/workflow/wasm-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ This document serves as a guide for contributors to the WebAssembly implementati

For debugging instructions including VS Code and Chrome DevTools setup, see the [WebAssembly Debugging Reference](debugging/mono/wasm-debugging.md).

### Running coreclr callhelpers generator

After building the runtime, use the `generate-coreclr-helpers` script for your platform (`.cmd` or `.sh`) in `src/tasks/WasmAppBuilder` to [re]generate the call helpers in `src/coreclr/vm/wasm`.

## Features and Configuration

### Runtime Features
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/WasmAppBuilder/WasmAppBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<UsingTask TaskName="ManagedToNativeGenerator" Runtime="NET" TaskFactory="TaskHostFactory" AssemblyFile="$(TargetPath)" />
<Target Name="RunGenerator" DependsOnTargets="Build" Condition="'$(AssembliesScanPath)' != ''">
<ItemGroup>
<WasmPInvokeAssembly Include="$(AssembliesScanPath)**/*.dll" />
<WasmPInvokeAssembly Include="$(AssembliesScanPath)*.dll" />
<WasmPInvokeModule Include="libSystem.Native" />
<WasmPInvokeModule Include="libSystem.Native.Browser" />
<WasmPInvokeModule Include="libSystem.IO.Compression.Native" />
Comment thread
radekdoulik marked this conversation as resolved.
Expand Down
92 changes: 92 additions & 0 deletions src/tasks/WasmAppBuilder/generate-coreclr-helpers.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@echo off
setlocal enabledelayedexpansion

:: Default configuration
set "configuration=Debug"
set "scan_path_override="

set "usage=Usage: %~nx0 [options]"
set "usage=!usage!^

^

Options:^

-c, --configuration ^<Checked^|Debug^|Release^> Build configuration (default: Debug)^

-s, --scan-path ^<path^> Override the default scan path^

-h, --help Show this help message"

:parse_args
if "%~1"=="" goto :done_args
if /i "%~1"=="-c" goto :set_configuration
if /i "%~1"=="--configuration" goto :set_configuration
if /i "%~1"=="-s" goto :set_scan_path
if /i "%~1"=="--scan-path" goto :set_scan_path
if /i "%~1"=="-h" goto :show_help
if /i "%~1"=="--help" goto :show_help

echo Unknown option: %~1
echo !usage!
exit /b 1

:set_configuration
set "configuration=%~2"
shift
shift
goto :parse_args

:set_scan_path
set "scan_path_override=%~2"
shift
shift
goto :parse_args

:show_help
echo !usage!
exit /b 0

:done_args

:: Validate configuration to prevent injection
if /i not "%configuration%"=="Debug" if /i not "%configuration%"=="Release" if /i not "%configuration%"=="Checked" (
echo Error: Invalid configuration "%configuration%". Must be Debug, Release, or Checked.
exit /b 1
)

:: Get the repo root (script is in src/tasks/WasmAppBuilder)
set "script_dir=%~dp0"
pushd "%script_dir%..\..\..\"
set "repo_root=%CD%"
popd

echo Configuration: %configuration%
echo Repo root: %repo_root%

if not "%scan_path_override%"=="" (
set "scan_path=%scan_path_override%"
) else (
set "scan_path=%repo_root%\artifacts\bin\testhost\net11.0-browser-%configuration%-wasm\shared\Microsoft.NETCore.App\11.0.0\"
)

if not exist "%scan_path%" (
echo Error: Scan path does not exist: %scan_path%
echo Please build the runtime first using: .\build.cmd clr+libs -os browser -c %configuration%
exit /b 1
)

cd /d "%repo_root%"
echo Scan path: %scan_path%

:: Run the generator - invoke directly without building a command string
echo Running generator...
echo .\dotnet.cmd build /t:RunGenerator /p:RuntimeFlavor=CoreCLR "/p:GeneratorOutputPath=%repo_root%\src\coreclr\vm\wasm\" "/p:AssembliesScanPath=%scan_path%" src\tasks\WasmAppBuilder\WasmAppBuilder.csproj
.\dotnet.cmd build /t:RunGenerator /p:RuntimeFlavor=CoreCLR "/p:GeneratorOutputPath=%repo_root%\src\coreclr\vm\wasm\" "/p:AssembliesScanPath=%scan_path%" src\tasks\WasmAppBuilder\WasmAppBuilder.csproj

if errorlevel 1 (
echo Generator failed!
exit /b 1
)

echo Done!
77 changes: 77 additions & 0 deletions src/tasks/WasmAppBuilder/generate-coreclr-helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash

set -euo pipefail

# Default configuration
configuration="Debug"
scan_path_override=""

usage="Usage: $0 [options]

Options:
-c, --configuration <Checked|Debug|Release> Build configuration (default: Debug)
-s, --scan-path <path> Override the default scan path
-h, --help Show this help message"

# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-c|--configuration)
configuration="$2"
shift 2
;;
-s|--scan-path)
scan_path_override="$2"
shift 2
;;
-h|--help)
echo "$usage"
exit 0
;;
*)
echo "Unknown option: $1"
echo "$usage"
exit 1
;;
esac
done

# Validate configuration to prevent injection (case-insensitive)
config_lower="$(echo "$configuration" | tr '[:upper:]' '[:lower:]')"
case "$config_lower" in
debug|release|checked)
;;
*)
echo "Error: Invalid configuration \"$configuration\". Must be Debug, Release, or Checked."
exit 1
;;
esac

# Get the repo root (script is in src/tasks/WasmAppBuilder)
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo_root="$(cd "$script_dir/../../.." && pwd)"

echo "Configuration: $configuration"
echo "Repo root: $repo_root"

if [[ -n "$scan_path_override" ]]; then
scan_path="$scan_path_override"
else
scan_path="$repo_root/artifacts/bin/testhost/net11.0-browser-$configuration-wasm/shared/Microsoft.NETCore.App/11.0.0/"
fi

if [[ ! -d "$scan_path" ]]; then
echo "Error: Scan path does not exist: $scan_path"
echo "Please build the runtime first using: ./build.sh clr+libs -os browser -c $configuration"
exit 1
fi

cd "$repo_root"
echo "Scan path: $scan_path"

# Run the generator - invoke directly without building a command string
echo "Running generator..."
echo "./dotnet.sh build /t:RunGenerator /p:RuntimeFlavor=CoreCLR /p:GeneratorOutputPath=$repo_root/src/coreclr/vm/wasm/ /p:AssembliesScanPath=$scan_path src/tasks/WasmAppBuilder/WasmAppBuilder.csproj"
./dotnet.sh build /t:RunGenerator /p:RuntimeFlavor=CoreCLR "/p:GeneratorOutputPath=$repo_root/src/coreclr/vm/wasm/" "/p:AssembliesScanPath=$scan_path" src/tasks/WasmAppBuilder/WasmAppBuilder.csproj

echo "Done!"