Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
dd5e3bc
Fix typescript build
maraf Nov 24, 2023
3c557bd
Build wasmruntime and include dotnet.js in framework
maraf Dec 5, 2023
bdb6bd0
Include additional wasmruntime files in ILC framework
maraf Dec 5, 2023
34462b4
Remove all cwraps. use dotnet.js when DotNetJsApi=true
maraf Dec 6, 2023
f420313
Make it work (TM)
maraf Dec 7, 2023
8e5a903
Extract DotNetJsApi link settings into a separate file
maraf Dec 7, 2023
014bdcb
Fix merge
maraf Dec 7, 2023
1a55814
Remove emcc files from package
maraf Dec 7, 2023
c19a2d7
Revert invoke-cs.ts
maraf Dec 7, 2023
6a2d69f
Ensure WasmObjDir
maraf Dec 7, 2023
4affb5c
Build wasm runtime for debug config
maraf Dec 8, 2023
61a07da
Add wasmruntime to clr.aot defaults
maraf Dec 8, 2023
73d85cf
Reduce EmscriptenEnvVars to default values
maraf Dec 9, 2023
e3bf8cb
Remove _DefaultEmccFlags, no-limited-postlink-optimizations
maraf Dec 9, 2023
4f6da2e
Remove ReadEmccProps
maraf Dec 9, 2023
eb73eec
Fix reading dotnet.js from RuntimeConfiguration outputs instead of LI…
maraf Dec 11, 2023
fc827a1
Fix for the previous "Fix reading dotnet.js from RuntimeConfiguration…
maraf Dec 11, 2023
1017725
Use constant to disable mono cwraps
maraf Dec 11, 2023
c065dda
Include js files only from es6 folder
maraf Dec 12, 2023
77062d4
Integrate copy files into build
maraf Dec 12, 2023
647f052
Copy WasmExtraFilesToDeploy to native and publish dirs
maraf Dec 12, 2023
167f02e
Fix using args from withApplicationArguments
maraf Dec 12, 2023
0dcdc9e
Clean up linkers args (1)
maraf Dec 12, 2023
a21a646
Some test with dotnet.js API
maraf Dec 12, 2023
da0df9f
Clean up linkers args (2)
maraf Dec 12, 2023
3333e5d
Remove math functions used by jiterpreter
maraf Dec 12, 2023
8eedfa7
Distribute "JS API" and "Runtime" props
maraf Dec 12, 2023
df2cddc
Use single link rsp file
maraf Dec 12, 2023
dbf5adf
Default config for native aot
maraf Dec 12, 2023
c672052
Replace comments with NativeAOT constant
maraf Dec 13, 2023
1897fd6
Add main.js as another expected test entrypoint?
maraf Dec 13, 2023
f9e9951
Fix typescript imports for NativeAOT
maraf Dec 13, 2023
3868406
Fix mono_exit
maraf Dec 13, 2023
b0293dd
Add package.json to test to support modules on node. Exit from node.
maraf Dec 13, 2023
26adcea
Fix result code
maraf Dec 13, 2023
cc6d39d
Update src/tests/nativeaot/SmokeTests/DotnetJs/DotnetJs.csproj
maraf Dec 13, 2023
eabddff
Check args. More straightforward exit code
maraf Dec 13, 2023
4d4d1c4
Revert import swap
maraf Dec 13, 2023
c766fbc
Revert removed empty line
maraf Dec 13, 2023
d210293
Rewrite typescript changes as append only
maraf Dec 13, 2023
ecb3f03
Rewrite typescript changes as append only (2)
maraf Dec 13, 2023
247c6bb
Use CLRTestTargetUnsupported
maraf Dec 13, 2023
19431c9
Reuse _FilesToCopyToNative in publish
maraf Dec 13, 2023
9935515
Minimize changes to wasm.proj
maraf Dec 13, 2023
1d32ee8
Guard mono_wasm_set_runtime_options for naot
maraf Dec 13, 2023
a105954
PrimaryRuntimeFlavor -> RuntimeFlavor
maraf Dec 14, 2023
f796292
Revert unintended TS changes
maraf Dec 14, 2023
6597228
Remove unused _WasmIntermediateOutputPath and _EmccLinkRsp
maraf Dec 14, 2023
934b85c
EmccInitialHeapSize only if not empty
maraf Dec 14, 2023
30c0d98
EmccStackSize to IlcWasmStackSize
maraf Dec 14, 2023
d2a5528
Dont link pal_random.lib.js when dotnetjsapi. Revert LLVM linker targ…
maraf Dec 14, 2023
42b12fe
Revert whitespace
maraf Dec 14, 2023
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
2 changes: 1 addition & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<DefaultCoreClrSubsets Condition="'$(PrimaryRuntimeFlavor)' != 'CoreCLR'">clr.iltools+clr.packages</DefaultCoreClrSubsets>

<DefaultNativeAotSubsets>clr.alljits+clr.tools+clr.nativeaotlibs+clr.nativeaotruntime</DefaultNativeAotSubsets>
<DefaultNativeAotSubsets Condition="'$(TargetArchitecture)' == 'wasm'">clr.nativeaotlibs+clr.nativeaotruntime+nativeaot.build</DefaultNativeAotSubsets>
<DefaultNativeAotSubsets Condition="'$(TargetArchitecture)' == 'wasm'">clr.nativeaotlibs+clr.nativeaotruntime+nativeaot.build+mono.wasmruntime</DefaultNativeAotSubsets>

<DefaultMonoSubsets Condition="'$(MonoEnableLLVM)' == 'true' and '$(MonoLLVMDir)' == ''">mono.llvm+</DefaultMonoSubsets>
<DefaultMonoSubsets Condition="'$(MonoAOTEnableLLVM)' == 'true' and '$(MonoLLVMDir)' == ''">mono.llvm+</DefaultMonoSubsets>
Expand Down
18 changes: 18 additions & 0 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<!-- Honor the RuntimeArtifactsPath property. -->
<CoreCLRArtifactsPath Condition="'$(CoreCLRArtifactsPath)' == '' and '$(RuntimeArtifactsPath)' != ''">$([MSBuild]::NormalizeDirectory('$(RuntimeArtifactsPath)'))</CoreCLRArtifactsPath>
<MonoArtifactsPath Condition="'$(MonoArtifactsPath)' == '' and '$(RuntimeArtifactsPath)' != ''">$([MSBuild]::NormalizeDirectory('$(RuntimeArtifactsPath)'))</MonoArtifactsPath>
<CoreCLRTargetOSConfigurationArchitecture Condition="'$(CoreCLRTargetOSConfigurationArchitecture)' == ''">$(TargetOS)-$(CoreCLRConfiguration)-$(TargetArchitecture)</CoreCLRTargetOSConfigurationArchitecture>
<LibrariesTargetOSConfigurationArchitecture Condition="'$(LibrariesTargetOSConfigurationArchitecture)' == ''">$(TargetOS)-$(LibrariesConfiguration)-$(TargetArchitecture)</LibrariesTargetOSConfigurationArchitecture>
</PropertyGroup>

Expand All @@ -27,6 +28,7 @@
<CoreCLRCrossILCompilerDir Condition="'$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(EnableNativeSanitizers)' != ''">$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', '$(BuildArchitecture)', 'ilc'))</CoreCLRCrossILCompilerDir>
<CoreCLRAotSdkDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'aotsdk'))</CoreCLRAotSdkDir>
<CoreCLRBuildIntegrationDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'build'))</CoreCLRBuildIntegrationDir>
<CoreCLRNativeArtifactsPath Condition="'$(CoreCLRNativeArtifactsPath)' == ''">$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin', 'native', '$(NetCoreAppCurrent)-$(CoreCLRTargetOSConfigurationArchitecture)'))</CoreCLRNativeArtifactsPath>

<Crossgen2Dir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', '$(BuildArchitecture)', 'crossgen2'))</Crossgen2Dir>

Expand Down Expand Up @@ -214,6 +216,22 @@
$(LibrariesNativeArtifactsPath)dotnet.native.js.symbols;
$(LibrariesNativeArtifactsPath)*.dat;"
IsNative="true" />

<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'browser' and '$(RuntimeFlavor)' == 'CoreCLR'"
Include="
$(CoreCLRNativeArtifactsPath)dotnet.js;
$(CoreCLRNativeArtifactsPath)dotnet.js.map;
$(CoreCLRNativeArtifactsPath)dotnet.runtime.js;
$(CoreCLRNativeArtifactsPath)dotnet.runtime.js.map;
$(CoreCLRNativeArtifactsPath)dotnet.d.ts;
$(CoreCLRNativeArtifactsPath)dotnet-legacy.d.ts;
$(CoreCLRNativeArtifactsPath)package.json;"
IsNative="true" />
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'browser' and '$(RuntimeFlavor)' == 'CoreCLR'"
Include="$(CoreCLRNativeArtifactsPath)src\es6\*.js"
NativeSubDirectory="src\es6"
IsNative="true" />

<!-- for threaded wasm -->
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'browser' and '$(RuntimeFlavor)' == 'Mono' and Exists('$(LibrariesNativeArtifactsPath)dotnet.native.worker.js')"
Include="
Expand Down
90 changes: 90 additions & 0 deletions src/coreclr/nativeaot/BuildIntegration/DotNetJsApi.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LinkNativeDependsOn Condition="'$(_targetOS)' == 'browser' and '$(DotNetJsApi)' == 'true'">$(LinkNativeDependsOn);PrepareDotNetJsApiForLinking</LinkNativeDependsOn>
<NativeBinary>$(NativeOutputPath)dotnet.native.js</NativeBinary>
</PropertyGroup>
<ItemGroup>
<EmccExportedFunction Include="_free" />
<EmccExportedFunction Include="_htons" />
<EmccExportedFunction Include="_malloc" />
<EmccExportedFunction Include="_memalign" />
<EmccExportedFunction Include="_memset" />
<EmccExportedFunction Include="_ntohs" />
<EmccExportedFunction Include="stackAlloc" />
<EmccExportedFunction Include="stackRestore" />
<EmccExportedFunction Include="stackSave" />
<EmccExportedRuntimeMethod Include="FS" />
<EmccExportedRuntimeMethod Include="out" />
<EmccExportedRuntimeMethod Include="err" />
<EmccExportedRuntimeMethod Include="ccall" />
<EmccExportedRuntimeMethod Include="cwrap" />
<EmccExportedRuntimeMethod Include="setValue" />
<EmccExportedRuntimeMethod Include="getValue" />
<EmccExportedRuntimeMethod Include="addRunDependency" />
<EmccExportedRuntimeMethod Include="addFunction" />
<EmccExportedRuntimeMethod Include="UTF8ToString" />
<EmccExportedRuntimeMethod Include="UTF8ArrayToString" />
<EmccExportedRuntimeMethod Include="stringToUTF8Array" />
<EmccExportedRuntimeMethod Include="FS_createPath" />
<EmccExportedRuntimeMethod Include="FS_createDataFile" />
<EmccExportedRuntimeMethod Include="removeRunDependency" />
<EmccExportedRuntimeMethod Include="safeSetTimeout" />
<EmccExportedRuntimeMethod Include="runtimeKeepalivePush" />
<EmccExportedRuntimeMethod Include="runtimeKeepalivePop" />
<EmccExportedRuntimeMethod Include="callMain" />
</ItemGroup>

<Target Name="PrepareDotNetJsApiForLinking">
<PropertyGroup>
<_EmccExportedLibraryFunction>&quot;[@(EmccExportedLibraryFunction -> '%27%(Identity)%27', ',')]&quot;</_EmccExportedLibraryFunction>
<_EmccExportedRuntimeMethods>&quot;[@(EmccExportedRuntimeMethod -> '%27%(Identity)%27', ',')]&quot;</_EmccExportedRuntimeMethods>
<_EmccExportedFunctions>@(EmccExportedFunction -> '%(Identity)',',')</_EmccExportedFunctions>
</PropertyGroup>
<ItemGroup>
<!-- Default values for flags passed from emscripten to dotnet/runtime.js. Left here only to minimize changes to typescript -->
<EmscriptenEnvVars Include="DISABLE_LEGACY_JS_INTEROP=1" />
<EmscriptenEnvVars Include="WASM_ENABLE_SIMD=0" />
<EmscriptenEnvVars Include="WASM_ENABLE_EH=1" />
<EmscriptenEnvVars Include="ENABLE_AOT_PROFILER=0" />
<EmscriptenEnvVars Include="ENABLE_BROWSER_PROFILER=0" />
<EmscriptenEnvVars Include="RUN_AOT_COMPILATION=0" />

<_DotNetJsLinkerFlag Include="-Wl,--export,__main_argc_argv" /><!-- Export main, a temporal solution until we have a way to export async main -->
<_DotNetJsLinkerFlag Include="-s EXPORT_ES6=1" /><!-- Produce ES6 module as expented by hosting API -->
<_DotNetJsLinkerFlag Include="-s MODULARIZE=1" /><!-- Produce ES6 module as expented by hosting API -->
<_DotNetJsLinkerFlag Include="-s INVOKE_RUN=0" /><!-- Don't automatically run main, it is called explicitly by ser -->
<_DotNetJsLinkerFlag Include="-s EXPORT_NAME=&quot;'createDotnetRuntime'&quot;" /><!-- Export emscripten factory as 'createDotnetRuntime', as expented by hosting API -->
<_DotNetJsLinkerFlag Include="-s ENVIRONMENT=&quot;'web,webview,worker,node,shell'&quot;" /><!-- Add support for all enviroments (default list is smaller) -->
<_DotNetJsLinkerFlag Condition="'$(EmccEnvironment)' != ''" Include="-s ENVIRONMENT=&quot;$(EmccEnvironment)&quot;" />
<_DotNetJsLinkerFlag Include="-s FORCE_FILESYSTEM=1" /><!-- We are using JS API for accessing FS -->
<_DotNetJsLinkerFlag Include="--emit-symbol-map" Condition="'$(WasmEmitSymbolMap)' == 'true'" />

<!-- JavaScript modifications to javascript produced by emscripten -->
<JSFileType Include="extpre.js" Kind="extern-pre-js" />
<JSFileType Include="iffe.js" Kind="extern-pre-js" />
<JSFileType Include="pre.js" Kind="pre-js" />
<JSFileType Include="lib.js" Kind="js-library" />
<JSFileType Include="post.js" Kind="post-js" />
<JSFileType Include="extpost.js" Kind="extern-post-js" />
<_WasmExtraJSFile Include="$(IlcFrameworkNativePath)src\es6\*.%(JSFileType.Identity)" Kind="%(JSFileType.Kind)" />
<_DotNetJsLinkerFlag Include="--%(_WasmExtraJSFile.Kind) &quot;%(_WasmExtraJSFile.Identity)&quot;" Condition="'%(_WasmExtraJSFile.Kind)' != ''" />

<!-- Exported functions required by user or runtime API -->
<_DotNetJsLinkerFlag Include="-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$(_EmccExportedLibraryFunction)" Condition="'$(_EmccExportedLibraryFunction)' != ''" />
<_DotNetJsLinkerFlag Include="-s EXPORTED_RUNTIME_METHODS=$(_EmccExportedRuntimeMethods)" />
<_DotNetJsLinkerFlag Include="-s EXPORTED_FUNCTIONS=$(_EmccExportedFunctions)" />
<_DotNetJsLinkerFlag Include="$(EmccExtraLDFlags)" />
</ItemGroup>
<ItemGroup>
<CustomLinkerArg Include="@(_DotNetJsLinkerFlag)" />
</ItemGroup>
</Target>
<Target Name="CopyDotnetJsAfterLinking" AfterTargets="LinkNativeLlvm">
<ItemGroup>
<_FilesToCopyToNative Include="$(IlcFrameworkNativePath)\dotnet*.js" />
<_FilesToCopyToNative Include="$(IlcFrameworkNativePath)\dotnet*.map" Condition="'$(WasmEmitSourceMap)' == 'true'" />
<_FilesToCopyToNative Include="@(WasmExtraFilesToDeploy)" /><!-- Use defined extra files to be included in the build output -->
</ItemGroup>
<Copy SourceFiles="@(_FilesToCopyToNative)" DestinationFolder="$(NativeOutputPath)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ItemGroup>
<_NativeIntermediateAssembly Include="@(IntermediateAssembly->'$(NativeOutputPath)%(Filename)$(NativeBinaryExt)')" />
<IntermediateAssembly Remove="@(IntermediateAssembly)" />
<IntermediateAssembly Include="@(_NativeIntermediateAssembly)" />
<IntermediateAssembly Include="@(_NativeIntermediateAssembly)" Condition="'$(DotNetJsApi)' != 'true'" />
</ItemGroup>
</Target>

Expand Down Expand Up @@ -96,13 +96,19 @@
<Target Name="CopyNativeBinary" AfterTargets="Publish">
<!-- replace apphost with binary we generated during native compilation -->
<Delete Files="$(PublishDir)\$(TargetName)$(NativeBinaryExt)" />
<Copy SourceFiles="$(NativeOutputPath)$(TargetName)$(NativeBinaryExt)" DestinationFolder="$(PublishDir)" />
<Copy SourceFiles="$(NativeOutputPath)$(TargetName)$(NativeBinaryExt)" DestinationFolder="$(PublishDir)" Condition="'$(DotNetJsApi)' != 'true'" />

<Delete Files="$(PublishDir)\$(TargetName).js" Condition="'$(_targetOS)' == 'browser'"/>
<Copy SourceFiles="$(NativeOutputPath)$(TargetName).js" DestinationFolder="$(PublishDir)" Condition="'$(_targetOS)' == 'browser'"/>
<Delete Files="$(PublishDir)\$(TargetName).js" Condition="'$(_targetOS)' == 'browser' and '$(DotNetJsApi)' != 'true'"/>
<Copy SourceFiles="$(NativeOutputPath)$(TargetName).js" DestinationFolder="$(PublishDir)" Condition="'$(_targetOS)' == 'browser' and '$(DotNetJsApi)' != 'true'"/>

<Delete Files="$(PublishDir)\$(TargetName).wasm" Condition="'$(_targetOS)' == 'browser'"/>
<Copy SourceFiles="$(NativeOutputPath)$(TargetName).wasm" DestinationFolder="$(PublishDir)" Condition="'$(_targetOS)' == 'browser'"/>
<Delete Files="$(PublishDir)\$(TargetName).wasm" Condition="'$(_targetOS)' == 'browser' and '$(DotNetJsApi)' != 'true'"/>
<Copy SourceFiles="$(NativeOutputPath)$(TargetName).wasm" DestinationFolder="$(PublishDir)" Condition="'$(_targetOS)' == 'browser' and '$(DotNetJsApi)' != 'true'"/>

<ItemGroup>
<_FilesToCopyToNative Include="$(NativeOutputPath)\dotnet.native.js" />
<_FilesToCopyToNative Include="$(NativeOutputPath)\dotnet.native.wasm" />
</ItemGroup>
<Copy SourceFiles="@(_FilesToCopyToNative)" DestinationFolder="$(PublishDir)" Condition="'$(_targetOS)' == 'browser' and '$(DotnetJsApi)' == 'true'"/>
</Target>

<Target Name="_CopyAotSymbols" AfterTargets="Publish"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ The .NET Foundation licenses this file to you under the MIT license.

<IlcLlvmTarget Condition="'$(_targetOS)' == 'wasi'">wasm32-unknown-wasi</IlcLlvmTarget>
<IlcWasmStackSize>1048576</IlcWasmStackSize> <!-- 1MB -->
<IlcWasmStackSize Condition="'$(EmccStackSize)' != ''">$(EmccStackSize)</IlcWasmStackSize>
<IlcWasmGlobalBase>1024</IlcWasmGlobalBase> <!-- This value is also hardcoded in the compiler -->
<IlcLlvmExceptionHandlingModel Condition="'$(WasmEnableExceptionHandling)' == 'true'">wasm</IlcLlvmExceptionHandlingModel>
<IlcLlvmExceptionHandlingModel Condition="'$(IlcLlvmExceptionHandlingModel)' == '' and '$(targetOS)' == 'browser'">cpp</IlcLlvmExceptionHandlingModel>
Expand Down Expand Up @@ -491,6 +492,8 @@ The .NET Foundation licenses this file to you under the MIT license.
strip -no_code_signature_warning $(_StripFlag) &quot;$(NativeBinary)&quot;" />
</Target>

<Import Project="$(MSBuildThisFileDirectory)DotNetJsApi.targets" Condition="'$(_targetArchitecture)' == 'wasm' and '$(DotNetJsApi)' == 'true'" />

<!-- NativeAOT-LLVM: separate target to reduce conflicts -->
<Target Name="LinkNativeLlvm"
Inputs="@(NativeObjects);@(NativeLibrary)"
Expand Down Expand Up @@ -524,7 +527,7 @@ The .NET Foundation licenses this file to you under the MIT license.
</ItemGroup>

<ItemGroup Condition = "'$(_targetOS)' == 'browser'" >
<CustomLinkerArg Include="--js-library &quot;$(IlcFrameworkNativePath)pal_random.lib.js&quot;" />
<CustomLinkerArg Include="--js-library &quot;$(IlcFrameworkNativePath)pal_random.lib.js&quot;" Condition="'$(DotNetJsApi)' != 'true'" />
<CustomLinkerArg Condition="'$(WasmHtmlTemplate)' != ''" Include="--shell-file &quot;$(WasmHtmlTemplate)&quot;" />
<CustomLinkerArg Condition="'$(ExportsFile)' != ''" Include="-s EXPORTED_FUNCTIONS=@&quot;$(ExportsFile)&quot;" />
<CustomLinkerArg Include="-s ALLOW_MEMORY_GROWTH=1" />
Expand All @@ -533,6 +536,11 @@ The .NET Foundation licenses this file to you under the MIT license.
<CustomLinkerArg Include="-s TOTAL_STACK=$(IlcWasmStackSize)" />
<CustomLinkerArg Condition="'$(WasmEnableJSBigIntIntegration)' == 'true'" Include="-s WASM_BIGINT=1" />
<CustomLinkerArg Condition="'$(IlcLlvmExceptionHandlingModel)' == 'cpp'" Include="-s DISABLE_EXCEPTION_CATCHING=0" />

<CustomLinkerArg Include="$(EmccFlags)" />
<CustomLinkerArg Include="-s MAXIMUM_MEMORY=$(EmccMaximumHeapSize)" Condition="'$(EmccMaximumHeapSize)' != ''" />
<CustomLinkerArg Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" Condition="'$(EmccInitialHeapSize)' != ''" />
<CustomLinkerArg Condition="'$(EmccEnableAssertions)' == 'true'" Include="-s ASSERTIONS=1" />
</ItemGroup>

<!-- wasm-ld only supports listing exports on the command line -->
Expand All @@ -557,7 +565,7 @@ The .NET Foundation licenses this file to you under the MIT license.
</ItemGroup>

<WriteLinesToFile File="$(NativeIntermediateOutputPath)link.rsp" Lines="@(CustomLinkerArg)" Overwrite="true" Encoding="utf-8" />
<Exec Command="$(WasmLinkerPath) @$(NativeIntermediateOutputPath)link.rsp $(EmccExtraArgs)" />
<Exec Command="$(WasmLinkerPath) @$(NativeIntermediateOutputPath)link.rsp $(EmccExtraArgs)" EnvironmentVariables="@(EmscriptenEnvVars)" />
</Target>

<Target Name="LinkNative"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<ItemGroup Condition="'$(PackageTargetRuntime)' != ''">
<File Include="@(LibrariesRuntimeFiles)">
<TargetPath>framework</TargetPath>
<TargetPath>framework/%(LibrariesRuntimeFiles.NativeSubDirectory)</TargetPath>
</File>
<File Include="$(CoreCLRILCompilerDir)*">
<TargetPath>tools</TargetPath>
Expand Down
4 changes: 3 additions & 1 deletion src/mono/wasm/runtime/cwraps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import NativeAOT from "consts:nativeAOT";
import MonoWasmThreads from "consts:monoWasmThreads";
import WasmEnableLegacyJsInterop from "consts:wasmEnableLegacyJsInterop";

Expand Down Expand Up @@ -348,7 +349,8 @@ function cwrap(name: string, returnType: string | null, argTypes: string[] | und

export function init_c_exports(): void {
const lfns = WasmEnableLegacyJsInterop && !linkerDisableLegacyJsInterop ? legacy_interop_cwraps : [];
const fns = [...fn_signatures, ...lfns];
const fns = NativeAOT ? [] : [...fn_signatures, ...lfns];

for (const sig of fns) {
const wf: any = wrapped_c_functions;
const [lazyOrSkip, name, returnType, argTypes, opts] = sig;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/es6/dotnet.es6.pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ if (_nativeModuleLoaded) throw new Error("Native module already loaded");
_nativeModuleLoaded = true;
// see https://github.com/emscripten-core/emscripten/issues/19832
Module["getMemory"] = function () { return wasmMemory; }
createDotnetRuntime = Module = createDotnetRuntime(Module);
moduleArg = Module = moduleArg(Module);
Copy link
Member

Choose a reason for hiding this comment

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

why ?

Copy link
Member Author

@maraf maraf Dec 7, 2023

Choose a reason for hiding this comment

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

Emscripten 3.1.47 generates

var createDotnetRuntime = (() => {
  var _scriptDir = import.meta.url;
  
  return (
async function(moduleArg = {}) {

I dunno yet if that can be configured somehow and I'm missing that flag or whether it's in empscripten (main has 3.1.34)

Copy link
Member

Choose a reason for hiding this comment

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

<_EmccLinkFlags Include="-s EXPORT_NAME="'createDotnetRuntime'"" />

Copy link
Member

Choose a reason for hiding this comment

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

maybe it's worth replacing the whole wasm.proj with latest from main ?

Copy link
Member Author

Choose a reason for hiding this comment

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

<_EmccLinkFlags Include="-s EXPORT_NAME="'createDotnetRuntime'"" />

I already have this one

<_EmccLDFlags Include="-s EXPORT_NAME=&quot;'createDotnetRuntime'&quot;" />

It produces the createDotnetRuntime, but the argument passed in is called moduleArg

Copy link
Member Author

Choose a reason for hiding this comment

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

Here is a sample dotnet.native.js that is generated by emcripten 3.1.47 dotnet.native.zip

Copy link
Member

Choose a reason for hiding this comment

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

hmmm, it seems we use createDotnetRuntime as default export in dotnet.d.ts but it seems it's a lie anyway.

Module["getMemory"] = function () { return wasmMemory; }
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/jiterpreter-support.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import NativeAOT from "consts:nativeAOT";
import MonoWasmThreads from "consts:monoWasmThreads";
import { NativePointer, ManagedPointer, VoidPtr } from "./types/emscripten";
import { Module, mono_assert, runtimeHelpers, linkerRunAOTCompilation } from "./globals";
Expand Down Expand Up @@ -2010,6 +2011,8 @@ function jiterpreter_allocate_table(type: JiterpreterTable, base: number, size:
let jiterpreter_tables_allocated = false;

export function jiterpreter_allocate_tables(module: any) {
if (NativeAOT)
return;
if (jiterpreter_tables_allocated)
return;
jiterpreter_tables_allocated = true;
Expand Down
4 changes: 4 additions & 0 deletions src/mono/wasm/runtime/jiterpreter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import NativeAOT from "consts:nativeAOT";
import { MonoMethod } from "./types/internal";
import { NativePointer } from "./types/emscripten";
import { Module, mono_assert, runtimeHelpers } from "./globals";
Expand Down Expand Up @@ -1088,6 +1089,9 @@ export function mono_jiterp_free_method_data_js(
}

export function jiterpreter_dump_stats(b?: boolean, concise?: boolean) {
if (NativeAOT) {
return;
}
if (!runtimeHelpers.runtimeReady) {
return;
}
Expand Down
17 changes: 17 additions & 0 deletions src/mono/wasm/runtime/loader/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import NativeAOT from "consts:nativeAOT";
import BuildConfiguration from "consts:configuration";

import type { MonoConfig, DotnetHostBuilder, DotnetModuleConfig, RuntimeAPI, LoadBootResourceCallback } from "../types";
Expand Down Expand Up @@ -477,6 +478,22 @@ async function initializeModules(es6Modules: [RuntimeModuleExportsInternal, Nati
}

async function createEmscriptenMain(): Promise<RuntimeAPI> {
if (NativeAOT && !loaderHelpers.config?.resources) {
if (!loaderHelpers.config) {
loaderHelpers.config = {};
}

loaderHelpers.config.resources = {
assembly: {},
jsModuleNative: { "dotnet.native.js": "" },
jsModuleWorker: {},
jsModuleRuntime: { "dotnet.runtime.js": "" },
wasmNative: { "dotnet.native.wasm": "" },
vfs: {},
satelliteResources: {},
};
}

if (!emscriptenModule.configSrc && (!loaderHelpers.config || Object.keys(loaderHelpers.config).length === 0 || (!loaderHelpers.config.assets && !loaderHelpers.config.resources))) {
// if config file location nor assets are provided
emscriptenModule.configSrc = "./blazor.boot.json";
Expand Down
Loading