<ProjectReference Include="$(RepoRoot)src\mono\wasm\host\WasmAppHost.csproj" />
<PackageFile Include="Sdk\AutoImport.props" TargetPath="Sdk" />
+ <PackageFile Include="Sdk\Sdk.props" TargetPath="Sdk" />
<PackageFile Include="$(RepoRoot)\src\mono\wasm\build\WasmApp.props" TargetPath="Sdk" />
<PackageFile Include="$(RepoRoot)\src\mono\wasm\build\WasmApp.targets" TargetPath="Sdk" />
<PackageFile Include="$(RepoRoot)\src\mono\wasm\build\WasmApp.Native.*" TargetPath="Sdk" />
<PropertyGroup>
<WasmNativeWorkload>true</WasmNativeWorkload>
</PropertyGroup>
-</Project>
\ No newline at end of file
+</Project>
--- /dev/null
+<Project>
+ <PropertyGroup Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' != 'true'">
+ <TargetArchitecture>wasm</TargetArchitecture>
+ <TargetOS>browser</TargetOS>
+ <UseMonoRuntime>true</UseMonoRuntime>
+ <OutputType>Exe</OutputType>
+ <PublishTrimmed Condition="'$(PublishTrimmed)' == ''">true</PublishTrimmed>
+ </PropertyGroup>
+</Project>
<WasmAppBuilderTasksAssemblyPath>$(_TasksDir)WasmAppBuilder.dll</WasmAppBuilderTasksAssemblyPath>
<WasmBuildTasksAssemblyPath>$(_TasksDir)WasmBuildTasks.dll</WasmBuildTasksAssemblyPath>
<WasmAppHostDir>$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', 'WasmAppHost'))</WasmAppHostDir>
+
+ <!-- only for non-blazor projects -->
+ <WasmEmitSymbolMap Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' != 'true' and '$(WasmEmitSymbolMap)' == '' and '$(RunAOTCompilation)' != 'true'">true</WasmEmitSymbolMap>
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)\WasmApp.props" />
<ImportGroup Condition="'$(RuntimeIdentifier)' == 'browser-wasm' and '$(UsingBrowserRuntimeWorkload)' == 'true'">
<Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk" />
+ <Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.WebAssembly.Sdk" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Runtime.WebAssembly.Sdk" />
<Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.browser-wasm" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk" />
<_DriverGenCNeeded Condition="'$(_DriverGenCNeeded)' == '' and '$(_WasmShouldAOT)' == 'true'">true</_DriverGenCNeeded>
- <_WasmDevel Condition="'$(WasmBuildNative)' == 'true' and '$(Configuration)' == 'Debug'">true</_WasmDevel>
+ <_WasmDevel Condition="'$(_WasmDevel)' == '' and '$(WasmBuildNative)' == 'true' and '$(Configuration)' == 'Debug'">true</_WasmDevel>
<_EmccAssertionLevelDefault Condition="'$(_EmccAssertionLevelDefault)' == ''">0</_EmccAssertionLevelDefault>
- <_EmccOptimizationFlagDefault Condition="'$(_WasmDevel)' == 'true'">-O0 -s ASSERTIONS=$(_EmccAssertionLevelDefault)</_EmccOptimizationFlagDefault>
+ <_EmccOptimizationFlagDefault Condition="'$(_WasmDevel)' == 'true'">-O0</_EmccOptimizationFlagDefault>
<_EmccOptimizationFlagDefault Condition="'$(_EmccOptimizationFlagDefault)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">-O1</_EmccOptimizationFlagDefault>
<_EmccOptimizationFlagDefault Condition="'$(_EmccOptimizationFlagDefault)' == ''">-Oz</_EmccOptimizationFlagDefault>
<!-- Adding optimization flag at the top, so it gets precedence -->
<_EmccCFlags Include="$(EmccCompileOptimizationFlag)" />
+ <_EmccCFlags Include="-s ASSERTIONS=$(_EmccAssertionLevelDefault)" Condition="'$(_WasmDevel)' == 'true'" />
<_EmccCFlags Include="@(_EmccCommonFlags)" />
<_EmccCFlags Include="-DDISABLE_PERFTRACING_LISTEN_PORTS=1" />
<!-- Adding optimization flag at the top, so it gets precedence -->
<_EmccLDFlags Include="$(EmccLinkOptimizationFlag)" />
+ <_EmccLDFlags Include="-s ASSERTIONS=$(_EmccAssertionLevelDefault)" Condition="'$(_WasmDevel)' == 'true'" />
<_EmccLDFlags Include="@(_EmccCommonFlags)" />
<_EmccLDFlags Include="-Wl,--allow-undefined" />
<_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
- <TargetArchitecture>wasm</TargetArchitecture>
- <TargetOS>browser</TargetOS>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
- <UseMonoRuntime>true</UseMonoRuntime>
<WasmMainJSPath>main.js</WasmMainJSPath>
<OutputType>Exe</OutputType>
- <PublishTrimmed>true</PublishTrimmed>
- <WasmEmitSymbolMap Condition="'$(RunAOTCompilation)' != 'true'">true</WasmEmitSymbolMap>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
- <TargetArchitecture>wasm</TargetArchitecture>
- <TargetOS>browser</TargetOS>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
- <UseMonoRuntime>true</UseMonoRuntime>
<WasmMainJSPath>main.mjs</WasmMainJSPath>
<OutputType>Exe</OutputType>
- <PublishTrimmed>true</PublishTrimmed>
- <WasmEmitSymbolMap Condition="'$(RunAOTCompilation)' != 'true'">true</WasmEmitSymbolMap>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
if (!urlAvailable.Task.IsCompleted)
throw new Exception("Timed out waiting for the app host url");
+ var url = new Uri(urlAvailable.Task.Result);
Playwright = await Microsoft.Playwright.Playwright.CreateAsync();
Browser = await Playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions{
ExecutablePath = s_chromePath.Value,
- Headless = headless
+ Headless = headless,
+ Args = OperatingSystem.IsWindows()
+ ? new[] { $"--explicitly-allowed-ports={url.Port}" }
+ : Array.Empty<string>()
});
IPage page = await Browser.NewPageAsync();
{
InitPaths(id);
InitProjectDir(id);
+
+ File.WriteAllText(Path.Combine(_projectDir, "Directory.Build.props"), "<Project />");
+ File.WriteAllText(Path.Combine(_projectDir, "Directory.Build.targets"),
+ """
+ <Project>
+ <ItemGroup>
+ <EmscriptenEnvVars Include="FROZEN_CACHE=" Condition="'$(OS)' == 'Windows_NT'" />
+ </ItemGroup>
+ </Project>
+ """);
+
new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false)
.WithWorkingDirectory(_projectDir!)
.ExecuteWithCapturedOutput($"new {template}")
// Release+publish defaults to native relinking
bool dotnetWasmFromRuntimePack = !nativeRelink && !buildArgs.AOT && buildArgs.Config != "Release";
+ string extraProperties = (nativeRelink ? $"<WasmBuildNative>true</WasmBuildNative>" : string.Empty)
+ // make ASSERTIONS=1 so that we test with it
+ + $"<EmccCompileOptimizationFlag>-O0 -sASSERTIONS=1</EmccCompileOptimizationFlag>"
+ + $"<EmccLinkOptimizationFlag>-O1</EmccLinkOptimizationFlag>";
+
buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs,
projectTemplate: s_resourcesProjectTemplate,
- extraProperties: (nativeRelink ? $"<WasmBuildNative>true</WasmBuildNative>" : string.Empty)
- // make ASSERTIONS=1 so that we test with it
- + $"<EmccCompileOptimizationFlag>{ (buildArgs.Config == "Debug" ? "-O0 -sASSERTIONS=1" : "-O0 -sASSERTIONS=1")}</EmccCompileOptimizationFlag>"
- );
+ extraProperties: extraProperties);
BuildProject(buildArgs,
id: id,
args: argCulture,
host: host, id: id,
// check that downloading assets doesn't have timing race conditions
- extraXHarnessMonoArgs: "--fetch-random-delay=200");
+ extraXHarnessMonoArgs: host is RunHost.Chrome ? "--fetch-random-delay=200" : string.Empty);
}
[Theory]
string projectName = $"SatelliteAssemblyFromProjectRef";
bool dotnetWasmFromRuntimePack = !nativeRelink && !buildArgs.AOT;
+ string extraProperties = $"<WasmBuildNative>{(nativeRelink ? "true" : "false")}</WasmBuildNative>"
+ // make ASSERTIONS=1 so that we test with it
+ + $"<EmccCompileOptimizationFlag>-O0 -sASSERTIONS=1</EmccCompileOptimizationFlag>"
+ + $"<EmccLinkOptimizationFlag>-O1</EmccLinkOptimizationFlag>";
+
buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs,
projectTemplate: s_resourcesProjectTemplate,
- extraProperties: $"<WasmBuildNative>{(nativeRelink ? "true" : "false")}</WasmBuildNative>",
+ extraProperties: extraProperties,
extraItems: $"<ProjectReference Include=\"..\\LibraryWithResources\\LibraryWithResources.csproj\" />");
BuildProject(buildArgs,
_projectDir = Path.Combine(rootDir, projectName);
Directory.CreateDirectory(_projectDir);
- Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, "SatelliteAssemblyFromProjectRef"), rootDir);
+ Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, projectName), rootDir);
+
+ // D.B.* used for wasm projects should be moved next to the wasm project, so it doesn't
+ // affect the non-wasm library project
+ File.Move(Path.Combine(rootDir, "Directory.Build.props"), Path.Combine(_projectDir, "Directory.Build.props"));
+ File.Move(Path.Combine(rootDir, "Directory.Build.targets"), Path.Combine(_projectDir, "Directory.Build.targets"));
+
CreateProgramForCultureTest(_projectDir, "LibraryWithResources.resx.words", "LibraryWithResources.Class1");
+
+ // The root D.B* should be empty
+ File.WriteAllText(Path.Combine(rootDir, "Directory.Build.props"), "<Project />");
+ File.WriteAllText(Path.Combine(rootDir, "Directory.Build.targets"), "<Project />");
}));
RunAndTestWasmApp(buildArgs,
}
[ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
- [InlineData("Debug")]
- [InlineData("Release")]
- public void ConsoleBuildAndRun(string config)
+ [InlineData("Debug", false)]
+ [InlineData("Debug", true)]
+ [InlineData("Release", false)]
+ [InlineData("Release", true)]
+ public void ConsoleBuildAndRun(string config, bool relinking)
{
string id = $"{config}_{Path.GetRandomFileName()}";
string projectFile = CreateWasmTemplateProject(id, "wasmconsole");
string projectName = Path.GetFileNameWithoutExtension(projectFile);
updateProgramCS();
+ if (relinking)
+ AddItemsPropertiesToProject(projectFile, "<WasmBuildNative>true</WasmBuildNative>");
var buildArgs = new BuildArgs(projectName, config, false, id, null);
buildArgs = ExpandBuildArgs(buildArgs);
BuildProject(buildArgs,
id: id,
new BuildProjectOptions(
- DotnetWasmFromRuntimePack: true,
+ DotnetWasmFromRuntimePack: !relinking,
CreateProject: false,
HasV8Script: false,
MainJS: "main.mjs",
TargetFramework: "net7.0"
));
- AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: true);
+ AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: !relinking);
(int exitCode, string output) = RunProcess(s_buildEnv.DotNet, _testOutput, args: $"run --no-build -c {config} x y z", workingDir: _projectDir);
Assert.Equal(42, exitCode);
}
[ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
- [InlineData("Debug", false)]
- [InlineData("Debug", true)]
- [InlineData("Release", false)]
- [InlineData("Release", true)]
- public void ConsolePublishAndRun(string config, bool aot)
+ [InlineData("Debug", false, false)]
+ [InlineData("Debug", false, true)]
+ [InlineData("Debug", true, false)]
+ [InlineData("Release", false, false)] // Release relinks by default
+ [InlineData("Release", true, false)]
+ public void ConsolePublishAndRun(string config, bool aot, bool relinking)
{
string id = $"{config}_{Path.GetRandomFileName()}";
string projectFile = CreateWasmTemplateProject(id, "wasmconsole");
string projectName = Path.GetFileNameWithoutExtension(projectFile);
updateProgramCS();
-
+
if (aot)
AddItemsPropertiesToProject(projectFile, "<RunAOTCompilation>true</RunAOTCompilation>");
+ else if (relinking)
+ AddItemsPropertiesToProject(projectFile, "<WasmBuildNative>true</WasmBuildNative>");
var buildArgs = new BuildArgs(projectName, config, aot, id, null);
buildArgs = ExpandBuildArgs(buildArgs);
- bool expectRelinking = config == "Release" || aot;
+ bool expectRelinking = config == "Release" || aot || relinking;
BuildProject(buildArgs,
id: id,
new BuildProjectOptions(
TargetFramework: "net7.0",
UseCache: false));
- AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: !expectRelinking);
+ if (!aot)
+ {
+ // These are disabled for AOT explicitly
+ AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: !expectRelinking);
+ }
+ else
+ {
+ AssertFilesDontExist(Path.Combine(GetBinDir(config), "AppBundle"), new[] { "dotnet.js.symbols" });
+ }
// FIXME: pass envvars via the environment, once that is supported
string runArgs = $"run --no-build -c {config}";