Skip to content

Commit 2bdc3cb

Browse files
marafradical
andauthored
[wasm] Make WasmMainJSPath optional (#81484)
Use WasmMainJSPath only on command-like hosts like v8 or node. Co-authored-by: Ankit Jain <[email protected]>
1 parent fb13c2c commit 2bdc3cb

32 files changed

+106
-122
lines changed

eng/testing/tests.browser.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
<WasmAppDir>$(BundleDir)</WasmAppDir>
136136
<WasmMainAssemblyFileName Condition="'$(WasmMainAssemblyFileName)' == ''">WasmTestRunner.dll</WasmMainAssemblyFileName>
137137
<WasmMainJSPath Condition="'$(WasmMainJSPath)' == ''">$(MonoProjectRoot)\wasm\test-main.js</WasmMainJSPath>
138+
<WasmMainJSFileName>$([System.IO.Path]::GetFileName('$(WasmMainJSPath)'))</WasmMainJSFileName>
139+
<WasmMainHtmlPath>$(PublishDir)index.html</WasmMainHtmlPath>
138140
<WasmInvariantGlobalization>$(InvariantGlobalization)</WasmInvariantGlobalization>
139141
<WasmGenerateRunV8Script>true</WasmGenerateRunV8Script>
140142

@@ -151,6 +153,9 @@
151153
</ItemGroup>
152154

153155
<ItemGroup>
156+
<WasmExtraFilesToDeploy Include="$(WasmMainJSPath)" />
157+
<WasmExtraFilesToDeploy Include="$(WasmMainHtmlPath)" />
158+
154159
<WasmAssembliesToBundle Include="$(PublishDir)\**\*.dll" Condition="'$(BuildAOTTestsOnHelix)' == 'true'" />
155160
<WasmFilesToIncludeInFileSystem Include="@(ContentWithTargetPath)" />
156161

@@ -169,6 +174,8 @@
169174
TargetPath="%(WasmFilesToIncludeFromPublishDir.Identity)"
170175
Condition="'%(WasmFilesToIncludeFromPublishDir.Identity)' != ''" />
171176
</ItemGroup>
177+
178+
<WriteLinesToFile File="$(WasmMainHtmlPath)" Lines="&lt;html&gt;&lt;body&gt;&lt;script type='module' src='$(WasmMainJSFileName)'&gt;&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;" Overwrite="True" Condition="!Exists('$(WasmMainHtmlPath)')"/>
172179
</Target>
173180

174181
<Target Name="_PrepareForAOTOnHelix">

src/mono/sample/mbr/browser/WasmDelta.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<OutputPath>bin</OutputPath>
88

99
<WasmAppDir>$(MSBuildProjectDirectory)\bin\$(Configuration)\AppBundle\</WasmAppDir>
10-
<WasmMainJSPath>main.js</WasmMainJSPath>
1110
<EnableDefaultItems>false</EnableDefaultItems>
1211

1312
<!-- Important - deltas don't support trimming! -->

src/mono/sample/wasi/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
</Target>
1919

2020
<Import Project="$(RepositoryEngineeringDir)testing\wasi-provisioning.targets" />
21-
</Project>
21+
</Project>

src/mono/sample/wasm/DefaultBrowserSample.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project>
22
<PropertyGroup>
33
<WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
4-
<WasmMainJSPath>main.js</WasmMainJSPath>
54
<DebugSymbols>true</DebugSymbols>
65
<DebugType>embedded</DebugType>
76
<!-- note that enabling debugger disables interp optimizations -->

src/mono/sample/wasm/Directory.Build.targets

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,30 @@
3434
bin/$(Configuration)/AppBundle/dotnet.wasm;
3535
bin/$(Configuration)/AppBundle/$(_WasmMainJSFileName);
3636
">
37-
<Error Condition="'$(WasmMainJSPath)' == ''" Text="%24(WasmMainJSPath) property needs to be set" />
3837
<PropertyGroup>
3938
<_ScriptExt Condition="'$(OS)' == 'Windows_NT'">.cmd</_ScriptExt>
4039
<_ScriptExt Condition="'$(OS)' != 'Windows_NT'">.sh</_ScriptExt>
4140
<_Dotnet>$(RepoRoot)dotnet$(_ScriptExt)</_Dotnet>
4241
<_AOTFlag Condition="'$(RunAOTCompilation)' != ''">/p:RunAOTCompilation=$(RunAOTCompilation)</_AOTFlag>
43-
<_WasmMainJSFileName>$([System.IO.Path]::GetFileName('$(WasmMainJSPath)'))</_WasmMainJSFileName>
4442
<_SampleProject Condition="'$(_SampleProject)' == ''">$(MSBuildProjectFile)</_SampleProject>
4543
<_SampleAssembly Condition="'$(_SampleAssembly)' == ''">$(TargetFileName)</_SampleAssembly>
4644
<BuildAdditionalArgs Condition="'$(MonoDiagnosticsMock)' != ''">$(BuildAdditionalArgs) /p:MonoDiagnosticsMock=$(MonoDiagnosticsMock) </BuildAdditionalArgs>
4745
</PropertyGroup>
4846
<Exec Command="$(_Dotnet) publish -bl /p:Configuration=$(Configuration) /p:TargetArchitecture=wasm /p:TargetOS=browser $(_AOTFlag) $(_SampleProject) $(BuildAdditionalArgs)" />
4947
</Target>
50-
<Target Name="RunSampleWithV8" DependsOnTargets="BuildSampleInTree">
48+
<Target Name="_ComputeMainJSFileName">
49+
<Error Condition="'$(WasmMainJSPath)' == ''" Text="%24(WasmMainJSPath) property needs to be set" />
50+
<PropertyGroup>
51+
<_WasmMainJSFileName>$([System.IO.Path]::GetFileName('$(WasmMainJSPath)'))</_WasmMainJSFileName>
52+
</PropertyGroup>
53+
</Target>
54+
<Target Name="RunSampleWithV8" DependsOnTargets="BuildSampleInTree;_ComputeMainJSFileName">
5155
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="v8 --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
5256
</Target>
53-
<Target Name="RunSampleWithNode" DependsOnTargets="BuildSampleInTree">
57+
<Target Name="RunSampleWithNode" DependsOnTargets="BuildSampleInTree;_ComputeMainJSFileName">
5458
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
5559
</Target>
56-
<Target Name="DebugSampleWithNode" DependsOnTargets="BuildSampleInTree">
60+
<Target Name="DebugSampleWithNode" DependsOnTargets="BuildSampleInTree;_ComputeMainJSFileName">
5761
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args) --inspect=9222" IgnoreExitCode="true" />
5862
</Target>
5963
<Target Name="CheckServe">

src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<WasmProfilers>browser;</WasmProfilers>
1212
</PropertyGroup>
1313
<ItemGroup>
14+
<WasmExtraFilesToDeploy Include="main.js" />
1415
<!-- add export GL object from Module -->
1516
<EmccExportedRuntimeMethod Include="GL" />
1617
<NativeFileReference Include="fibonacci.c" />

src/mono/sample/wasm/browser-bench/Wasm.Browser.Bench.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
44
<!-- don't need to run this on helix -->
55
<WasmCopyAppZipToHelixTestDir>false</WasmCopyAppZipToHelixTestDir>
6-
<WasmMainJSPath>main.js</WasmMainJSPath>
76
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
87
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
98
<EnableAggressiveTrimming Condition="'$(EnableAOTAndTrimming)' != ''">$(EnableAOTAndTrimming)</EnableAggressiveTrimming>
@@ -13,6 +12,7 @@
1312

1413
<ItemGroup>
1514
<WasmExtraFilesToDeploy Include="index.html" />
15+
<WasmExtraFilesToDeploy Include="main.js" />
1616
<WasmExtraFilesToDeploy Include="appstart-frame.html" />
1717
<WasmExtraFilesToDeploy Include="frame-main.js" />
1818
<WasmExtraFilesToDeploy Include="style.css" />

src/mono/sample/wasm/browser-nextjs/Wasm.Browser.NextJs.Sample.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<WasmCopyAppZipToHelixTestDir>false</WasmCopyAppZipToHelixTestDir>
4-
<WasmMainJSPath>package.json</WasmMainJSPath>
54
<WasmAppDir>public</WasmAppDir>
65
</PropertyGroup>
76

src/mono/sample/wasm/browser-profile/Wasm.BrowserProfile.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
4-
<WasmMainJSPath>main.js</WasmMainJSPath>
54
<WasmProfilers>aot;</WasmProfilers>
65
<WasmBuildNative>true</WasmBuildNative>
76
<WasmNativeStrip>false</WasmNativeStrip>
87
</PropertyGroup>
98

109
<ItemGroup>
1110
<WasmExtraFilesToDeploy Include="index.html" />
11+
<WasmExtraFilesToDeploy Include="main.js" />
1212
</ItemGroup>
1313

1414
<Target Name="RunSample" DependsOnTargets="RunSampleWithBrowser" />

src/mono/sample/wasm/browser-threads/Wasm.Browser.Threads.Sample.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<WasmEnableThreads>true</WasmEnableThreads>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<WasmExtraFilesToDeploy Include="main.js" />
9+
</ItemGroup>
10+
711
<!-- set the condition to false and you will get a CA1416 error about the call to Thread.Start from a browser-wasm project -->
812
<ItemGroup Condition="true">
913
<!-- TODO: some .props file that automates this. Unfortunately just adding a ProjectReference to Microsoft.NET.WebAssembly.Threading.proj doesn't work - it ends up bundling the ref assemblies into the publish directory and breaking the app. -->

0 commit comments

Comments
 (0)