Skip to content

Commit f288fd5

Browse files
marafCopilotlewing
authored
[browser] Library mode without workload (#122607)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Larry Ewing <lewing@microsoft.com>
1 parent 980c9d1 commit f288fd5

6 files changed

Lines changed: 25 additions & 20 deletions

File tree

src/mono/browser/build/BrowserWasmApp.targets

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@
5050
<ProjectCapability Include="DotNetCoreWeb"/>
5151
</ItemGroup>
5252

53-
<!-- When trimming non-exe projects, root the whole intermediate assembly. -->
54-
<Target Name="_RootEntireIntermediateAssembly" AfterTargets="PrepareForILLink" BeforeTargets="_RunILLink" Condition="'$(RuntimeIdentifier)' == 'browser-wasm' And '$(OutputType)' == 'Library'">
55-
<ItemGroup>
56-
<TrimmerRootAssembly Condition="'%(Identity)' == '$(AssemblyName)'">
57-
<RootMode>all</RootMode>
58-
</TrimmerRootAssembly>
59-
</ItemGroup>
60-
</Target>
61-
6253
<Import Project="$(MSBuildThisFileDirectory)EmSdkRepo.Defaults.props" Condition="'$(WasmUseEMSDK_PATH)' == 'true'" />
6354
<Target Name="_SetupEmscripten" BeforeTargets="_SetupToolchain">
6455
<PropertyGroup>

src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/Sdk.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
<TargetArchitecture>wasm</TargetArchitecture>
44
<TargetOS>browser</TargetOS>
55
<OutputType Condition="'$(OutputType)' == ''">Exe</OutputType>
6-
<PublishTrimmed Condition="'$(PublishTrimmed)' == ''">true</PublishTrimmed>
76
</PropertyGroup>
87
</Project>

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,4 +1245,11 @@ Copyright (c) .NET Foundation. All rights reserved.
12451245
Condition="Exists('$(_DotnetTypesSourcePath)')"
12461246
SkipUnchangedFiles="true" />
12471247
</Target>
1248+
1249+
<!-- When trimming non-exe projects, root the whole intermediate assembly. -->
1250+
<Target Name="_RootEntireIntermediateAssembly" AfterTargets="PrepareForILLink" BeforeTargets="_RunILLink" Condition="'$(RuntimeIdentifier)' == 'browser-wasm' And '$(OutputType)' == 'Library'">
1251+
<ItemGroup>
1252+
<TrimmerRootAssembly Include="$(AssemblyName)" RootMode="all" />
1253+
</ItemGroup>
1254+
</Target>
12481255
</Project>

src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest/WorkloadManifest.targets.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
</PropertyGroup>
3838

3939
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'browser-wasm'">
40-
<SelfContained>true</SelfContained>
4140
<WasmNativeWorkloadAvailable Condition="'$(TargetsCurrent)' == 'true'">$(WasmNativeWorkload11)</WasmNativeWorkloadAvailable>
4241
<WasmNativeWorkloadAvailable Condition="'$(TargetsNet10)' == 'true'">$(WasmNativeWorkload10)</WasmNativeWorkloadAvailable>
4342
<WasmNativeWorkloadAvailable Condition="'$(TargetsNet9)' == 'true'">$(WasmNativeWorkload9)</WasmNativeWorkloadAvailable>
@@ -64,7 +63,6 @@
6463
'$(WasmProfilers)' != '' or
6564
'$(RunAOTCompilation)' == 'true' or
6665
'$(WasmBuildNative)' == 'true' or
67-
'$(_UsingBlazorOrWasmSdk)' != 'true' or
6866
'$(EmccInitialHeapSize)' != '' or
6967
'$(EmccMaximumHeapSize)' != '' " >true</_WasmNativeWorkloadNeeded>
7068

src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,12 @@ void AssertFile(string suffix)
300300
}
301301
}
302302

303-
[Theory]
304-
// [InlineData(false)] https://github.com/dotnet/runtime/issues/123477
305-
[InlineData(true)]
306-
public async Task LibraryModeBuild(bool useWasmSdk)
303+
[Theory, TestCategory("no-workload")]
304+
[InlineData(false, false)]
305+
[InlineData(false, true)]
306+
[InlineData(true, false)]
307+
[InlineData(true, true)]
308+
public async Task LibraryMode(bool useWasmSdk, bool isPublish)
307309
{
308310
var config = Configuration.Release;
309311
ProjectInfo info = CopyTestAsset(config, aot: false, TestAsset.LibraryModeTestApp, "libraryMode");
@@ -313,13 +315,22 @@ public async Task LibraryModeBuild(bool useWasmSdk)
313315
{ "Microsoft.NET.Sdk.WebAssembly", "Microsoft.NET.Sdk" }
314316
});
315317
}
316-
BuildProject(info, config, new BuildOptions(AssertAppBundle: useWasmSdk));
318+
319+
// Without WASM SDK, the project is a plain library with browser-wasm RID.
320+
// It should build and publish successfully but won't produce a wasm app bundle.
321+
if (isPublish)
322+
PublishProject(info, config, new PublishOptions(AssertAppBundle: useWasmSdk));
323+
else
324+
BuildProject(info, config, new BuildOptions(AssertAppBundle: useWasmSdk));
325+
317326
if (useWasmSdk)
318327
{
319-
var result = await RunForBuildWithDotnetRun(new BrowserRunOptions(config, ExpectedExitCode: 100));
328+
var result = isPublish
329+
? await RunForPublishWithWebServer(new BrowserRunOptions(config, ExpectedExitCode: 100))
330+
: await RunForBuildWithDotnetRun(new BrowserRunOptions(config, ExpectedExitCode: 100));
331+
320332
Assert.Contains("WASM Library MyExport is called", result.TestOutput);
321333
}
322-
323334
}
324335

325336
[Theory]

src/mono/wasm/testassets/WasmBasicTestApp/LazyLibrary/LazyLibrary.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
55
<OutputType>Library</OutputType>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7-
<UseMonoRuntime>true</UseMonoRuntime>
87
</PropertyGroup>
98
</Project>

0 commit comments

Comments
 (0)