Skip to content

[wasm] Add missing properties to PropertiesThatTriggerRelinking for WASM and WASI - #117983

Merged
ilonatommy merged 9 commits into
mainfrom
copilot/fix-105135
Aug 4, 2025
Merged

ilonatommy merged 9 commits into
mainfrom
copilot/fix-105135

Conversation

Copilot AI commented Jul 23, 2025 •

Copy link
Copy Markdown
Contributor

This PR addresses the missing properties in PropertiesThatTriggerRelinking for WASM and WASI builds as identified in the issue discussion.

Problem

Several important properties that affect the native build output were not marked as triggering relinking, which could lead to inconsistent builds when these properties change. This means developers might change configuration properties but not see their changes take effect because the native components weren't rebuilt.

Solution

Added the following properties to PropertiesThatTriggerRelinking:

WASM-only (browser.proj):

  • EmccInitialHeapSize - Controls memory layout together with EmccMaximumHeapSize. Heap size configuration applies only for browser scenarios, same as ExceptionHandling.

Both WASM and WASI:

  • WasmEnableThreads - Affects memory layout (e.g., usage of SharedArrayBuffer in browser or DISABLE_THREADS switches in runtime)
  • RunAOTCompilation - Native objects and linked outputs are no longer valid for new values and must be rebuilt
  • PublishTrimmed - The set of assemblies and code passed to the native linker changes significantly

Changes

  • Updated src/mono/browser/browser.proj to include all 4 properties in the generated wasm-props.json
  • Updated src/mono/wasi/wasi.proj to include the 3 shared properties in the generated wasm-props.json
  • Enhanced test coverage by adding WasmEnableThreads to the existing test framework in WasmNativeDefaultsTests.cs

Behavior

When any of these properties differs from the runtime pack default value, the build system will:

  1. Detect the change via _ChangedPropertiesThatTriggerRelinking comparison
  2. Set _WasmBuildNativeRequired=true
  3. Force WasmBuildNative=true to trigger native relinking
  4. Rebuild native components with the new configuration

This ensures developers get proper native rebuilds when changing these important configuration properties that affect memory layout, threading model, AOT compilation, or IL trimming.

Fixes #105135.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 23, 2025 15:12
… WASI

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot AI changed the title [WIP] [wasm] Review relink triggering properties [wasm] Add missing properties to PropertiesThatTriggerRelinking for WASM and WASI Jul 23, 2025
Copilot AI requested a review from ilonatommy July 23, 2025 15:26
@ilonatommy

Copy link
Copy Markdown
Member

@copilot, we have to document the changes.

Candidates for placing documentation:

## Properties That Trigger Relinking

### What is Relinking?

Relinking is the process of rebuilding the native WebAssembly runtime (`dotnet.native.js`, `dotnet.native.wasm`, etc.) with updated or trimmed content, often resulting in a smaller or more optimized output. This is necessary when certain configuration properties or source changes require regeneration of the native artifacts.

### Properties That Trigger Relinking in `browser.proj`

The following MSBuild properties and build flags will trigger a relinking (full rebuild of native artifacts) during the browser/wasm build process:

- **RunAOTCompilation**  
  - `/p:RunAOTCompilation=true`  
  - Enables Ahead-of-Time (AOT) compilation. Changing this from false to true (or vice versa) requires relinking to produce the correct output.

- **WasmBuildNative**  
  - `/p:WasmBuildNative=true`  
  - Forces a fresh build of the native runtime components.

- **WasmRelinkNative**  
  - `/p:WasmRelinkNative=true`  
  - Explicitly requests relinking, even if not otherwise required by other property changes.

- **WasmBuildArgs**  
  - Any change to arguments passed via `/p:WasmBuildArgs=...` (such as enabling/disabling additional features or options) will trigger a relink.

- **Configuration/Target Architecture**  
  - Changing `/p:Configuration=Debug|Release` or `/p:RuntimeIdentifier=browser-wasm`, etc., can require relinking for correct native output.

- **Source Changes**  
  - Any modification to native code (C/C++/Emscripten sources) in `src/mono/browser` or dependent directories will naturally trigger a relink.

#### Notes

- Relinking ensures that the produced WebAssembly binaries reflect the current set of build options and runtime features.
- For incremental developer workflows, minimizing unnecessary relinks speeds up build times.
- The relink process is managed by MSBuild targets in `browser.proj`—refer to that file for the most up-to-date logic.

For questions or advanced scenarios, see the [WebAssembly build instructions](../../../docs/workflow/building/libraries/webassembly-instructions.md) or reach out to the .NET runtime maintainers.
  • src/mono/wasi/README.md for WAS
## Properties That Trigger Relinking

### What is Relinking?

Relinking in WASI builds refers to regenerating the native WASI runtime artifacts (such as `dotnet.native.wasi`, supporting JS, etc.) to reflect changes in configuration, features, or source. This process is essential for producing correct, optimized binaries for WASI environments.

### Properties That Trigger Relinking in `wasi.proj`

The following MSBuild properties and build flags will trigger a relinking during the WASI build process:

- **RunAOTCompilation**  
  - `/p:RunAOTCompilation=true`  
  - Enables AOT compilation for WASI. Changing this property requires relinking for correct WASI output.

- **WasiBuildNative**  
  - `/p:WasiBuildNative=true`  
  - Forces a rebuild of all native WASI binaries, regardless of detected changes.

- **WasiRelinkNative**  
  - `/p:WasiRelinkNative=true`  
  - Explicitly requests relinking of native WASI artifacts.

- **WasiBuildArgs**  
  - Any change to `/p:WasiBuildArgs=...` (custom build flags or feature toggles) can trigger a relink.

- **Configuration/Target Architecture**  
  - Changing `/p:Configuration=Debug|Release` or `/p:RuntimeIdentifier=wasi-wasm`, etc., may require relinking.

- **Source Changes**  
  - Modifying native sources in `src/mono/wasi` or related directories will always trigger a relink.

#### Notes

- Correct relinking ensures WASI binaries are up-to-date and accurately reflect the intended configuration.
- Avoid unnecessary relinking for faster incremental builds.
- The relink logic is defined in `wasi.proj` and supporting MSBuild files.

For more detailed WASI build and configuration guidance, see the [WASI build documentation](../../../docs/workflow/building/libraries/webassembly-instructions.md) or consult with the .NET runtime community.

…ASI builds

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>

Copilot AI commented Jul 23, 2025

Copy link
Copy Markdown
Contributor Author

@copilot, we have to document the changes.

Candidates for placing documentation:
...

Added comprehensive documentation for properties that trigger relinking in both src/mono/browser/README.md and src/mono/wasi/README.md. The documentation includes:

  • Clear explanation of what relinking is and why it's needed
  • Complete list of MSBuild properties that trigger relinking for each platform
  • Usage examples with /p:PropertyName=value syntax
  • Notes about build performance and incremental workflows

This covers the newly added properties (EmccInitialHeapSize, WasmEnableThreads, RunAOTCompilation, PublishTrimmed) as well as the existing properties for better developer understanding.

Commit: 8540857

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds missing properties to PropertiesThatTriggerRelinking for WASM and WASI builds to ensure native components are properly rebuilt when configuration changes occur. The changes ensure that when developers modify important build properties like threading, AOT compilation, or trimming settings, the native runtime artifacts are correctly regenerated.

Key changes:

  • Added 4 new properties to WASM builds: EmccInitialHeapSize, WasmEnableThreads, RunAOTCompilation, PublishTrimmed
  • Added 3 new properties to WASI builds: WasmEnableThreads, RunAOTCompilation, PublishTrimmed
  • Enhanced test coverage and added comprehensive documentation for relinking behavior

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/mono/browser/browser.proj Added 4 properties to PropertiesThatTriggerRelinking JSON for WASM builds
src/mono/wasi/wasi.proj Added 3 properties to PropertiesThatTriggerRelinking JSON for WASI builds
src/mono/wasm/Wasm.Build.Tests/WasmNativeDefaultsTests.cs Added WasmEnableThreads to test coverage with explanatory comments
src/mono/browser/README.md Added comprehensive documentation section explaining relinking properties and behavior
src/mono/wasi/README.md Added comprehensive documentation section explaining relinking properties and behavior for WASI

@ilonatommy ilonatommy added this to the 10.0.0 milestone Jul 24, 2025
@ilonatommy ilonatommy added the arch-wasm WebAssembly architecture label Jul 24, 2025
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Comment thread src/mono/browser/browser.proj Outdated
Comment thread src/mono/browser/browser.proj Outdated
Comment thread src/mono/wasi/wasi.proj Outdated
Comment thread src/mono/wasi/README.md
Comment thread src/mono/wasi/README.md Outdated
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
…rRelinking

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Comment thread src/mono/wasm/Wasm.Build.Tests/WasmNativeDefaultsTests.cs Outdated
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>

@ilonatommy ilonatommy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All feedback applied.

@ilonatommy
ilonatommy enabled auto-merge (squash) July 25, 2025 14:44
@ilonatommy
ilonatommy requested review from maraf and pavelsavara July 29, 2025 14:04
@pavelsavara

Copy link
Copy Markdown
Member

Should we trigger re-link on all things that influence trimmer features ?
Like WasmEnableStreamingResponse. This has to re-build for AOT.
Maybe this is only about incremental build again.

We already have EnableDiagnostics because that also has native component.

@ilonatommy

Copy link
Copy Markdown
Member

Should we trigger re-link on all things that influence trimmer features ? Like WasmEnableStreamingResponse. This has to re-build for AOT. Maybe this is only about incremental build again.

WasmEnableStreamingResponse controls runtime (managed) feature, it looks like changing it does not affect native code. I do not see how changing WasmEnableStreamingResponse influences AOT.

@ilonatommy
ilonatommy merged commit d34cad0 into main Aug 4, 2025
@jkotas
jkotas deleted the copilot/fix-105135 branch August 28, 2025 21:08
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm] Review relink triggering properties

5 participants