Skip to content

Commit

Permalink
Updates for .native.worker.js -> mjs rename
Browse files Browse the repository at this point in the history
  • Loading branch information
radekdoulik committed Apr 5, 2024
1 parent a91ec44 commit d23f6fa
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 27 deletions.
4 changes: 2 additions & 2 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@
$(LibrariesNativeArtifactsPath)segmentation-rules.json;"
IsNative="true" />
<!-- for threaded wasm -->
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'browser' and Exists('$(LibrariesNativeArtifactsPath)dotnet.native.worker.js')"
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'browser' and Exists('$(LibrariesNativeArtifactsPath)dotnet.native.worker.mjs')"
Include="
$(LibrariesNativeArtifactsPath)dotnet.native.worker.js"
$(LibrariesNativeArtifactsPath)dotnet.native.worker.mjs"
IsNative="true" />
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'browser'"
Include="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
<PlatformManifestFileEntry Include="dotnet.runtime.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.runtime.js.map" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.native.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.native.worker.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.native.worker.mjs" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.native.js.symbols" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.d.ts" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.native.wasm" IsNative="true" />
Expand Down
4 changes: 2 additions & 2 deletions src/mono/browser/browser.proj
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)"
SkipUnchangedFiles="true" />

<Copy SourceFiles="$(NativeBinDir)dotnet.native.worker.js"
<Copy SourceFiles="$(NativeBinDir)dotnet.native.worker.mjs"
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)"
Condition="Exists('$(NativeBinDir)dotnet.native.worker.js')"
Condition="Exists('$(NativeBinDir)dotnet.native.worker.mjs')"
SkipUnchangedFiles="true" />

<Copy SourceFiles="$(NativeBinDir)dotnet.native.js.symbols"
Expand Down
6 changes: 3 additions & 3 deletions src/mono/browser/build/BrowserWasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

<PropertyGroup>
<_HasDotnetWasm Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.native.wasm'">true</_HasDotnetWasm>
<_HasDotnetJsWorker Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.native.worker.js'">true</_HasDotnetJsWorker>
<_HasDotnetJsWorker Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.native.worker.mjs'">true</_HasDotnetJsWorker>
<_HasDotnetJsSymbols Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.native.js.symbols'">true</_HasDotnetJsSymbols>
<_HasDotnetNativeJs Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.native.js'">true</_HasDotnetNativeJs>
<HybridGlobalization Condition="'$(InvariantGlobalization)' == 'true'">false</HybridGlobalization>
Expand All @@ -87,7 +87,7 @@
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.runtime.js" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.wasm" Condition="'$(_HasDotnetWasm)' != 'true'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.js" Condition="'$(_HasDotnetNativeJs)' != 'true'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.worker.js" Condition="'$(_HasDotnetJsWorker)' != 'true' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.worker.js')" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.worker.mjs" Condition="'$(_HasDotnetJsWorker)' != 'true' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.worker.mjs')" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.js.symbols"
Condition="'$(WasmEmitSymbolMap)' == 'true' and
'$(_HasDotnetJsSymbols)' != 'true' and
Expand Down Expand Up @@ -540,7 +540,7 @@
<ItemGroup>
<WasmNativeAsset Include="$(_WasmIntermediateOutputPath)dotnet.native.wasm" />
<WasmNativeAsset Include="$(_WasmIntermediateOutputPath)dotnet.native.js" />
<WasmNativeAsset Include="$(_WasmIntermediateOutputPath)dotnet.native.worker.js" Condition="Exists('$(_WasmIntermediateOutputPath)dotnet.native.worker.js')" />
<WasmNativeAsset Include="$(_WasmIntermediateOutputPath)dotnet.native.worker.mjs" Condition="Exists('$(_WasmIntermediateOutputPath)dotnet.native.worker.mjs')" />
<WasmNativeAsset Include="$(_WasmIntermediateOutputPath)dotnet.native.js.symbols" Condition="'$(WasmEmitSymbolMap)' == 'true' and Exists('$(_WasmIntermediateOutputPath)dotnet.native.js.symbols')" />
<_WasmAssembliesInternal Remove="$(_WasmDedupAssembly)"/>
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/mono/browser/runtime/loader/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ export function preloadWorkers() {
const workerNumber = loaderHelpers.workerNextNumber++;
const worker: Partial<PThreadWorker> = new Worker(jsModuleWorker.resolvedUrl!, {
name: "dotnet-worker-" + workerNumber.toString().padStart(3, "0"),
type: "module",
});
worker.info = {
workerNumber,
Expand Down
1 change: 1 addition & 0 deletions src/mono/browser/runtime/pthreads/ui-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ function allocateUnusedWorker(): PThreadWorker {
const workerNumber = loaderHelpers.workerNextNumber++;
const worker = new Worker(uri, {
name: "dotnet-worker-" + workerNumber.toString().padStart(3, "0"),
type: "module",
}) as PThreadWorker;
getUnusedWorkerPool().push(worker);
worker.loaded = false;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public string GetRuntimePackDir(string tfm = BuildTestBase.DefaultTargetFramewor
public string GetRuntimeNativeDir(string tfm = BuildTestBase.DefaultTargetFramework, RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded)
=> Path.Combine(GetRuntimePackDir(tfm, runtimeType), "runtimes", DefaultRuntimeIdentifier, "native");
public bool IsMultiThreadingRuntimePackAvailableFor(string tfm)
=> IsWorkload && File.Exists(Path.Combine(GetRuntimeNativeDir(tfm, RuntimeVariant.MultiThreaded), "dotnet.native.worker.js"));
=> IsWorkload && File.Exists(Path.Combine(GetRuntimeNativeDir(tfm, RuntimeVariant.MultiThreaded), "dotnet.native.worker.mjs"));

public static string WasmOverridePacksTargetsPath = Path.Combine(TestDataPath, "WasmOverridePacks.targets");

Expand Down
6 changes: 3 additions & 3 deletions src/mono/wasm/Wasm.Build.Tests/TestMainJsProjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public TestMainJsProjectProvider(ITestOutputHelper _testOutput, string? _project
{ "dotnet.native.js", false },
{ "dotnet.native.js.symbols", false },
{ "dotnet.native.wasm", false },
{ "dotnet.native.worker.js", false },
{ "dotnet.native.worker.mjs", false },
{ "dotnet.runtime.js", false },
{ "dotnet.runtime.js.map", false }
};
Expand All @@ -51,13 +51,13 @@ protected override IReadOnlySet<string> GetDotNetFilesExpectedSet(AssertBundleOp
res.Add("dotnet.native.wasm");
res.Add("dotnet.native.js");
res.Add("dotnet.runtime.js");
res.Add("dotnet.native.worker.js");
res.Add("dotnet.native.worker.mjs");

if (!assertOptions.IsPublish)
{
res.Add("dotnet.js.map");
res.Add("dotnet.runtime.js.map");
res.Add("dotnet.native.worker.js.map");
res.Add("dotnet.native.worker.mjs.map");
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public WasmSdkBasedProjectProvider(ITestOutputHelper _testOutput, string? _proje
{ "dotnet.native.js", true },
{ "dotnet.native.js.symbols", false },
{ "dotnet.native.wasm", false },
{ "dotnet.native.worker.js", true },
{ "dotnet.native.worker.mjs", true },
{ "dotnet.runtime.js", true },
{ "dotnet.runtime.js.map", false },
};
Expand All @@ -43,7 +43,7 @@ protected override IReadOnlySet<string> GetDotNetFilesExpectedSet(AssertBundleOp
};
if (assertOptions.RuntimeType is RuntimeVariant.MultiThreaded)
{
res.Add("dotnet.native.worker.js");
res.Add("dotnet.native.worker.mjs");
}

if (!assertOptions.IsPublish)
Expand Down Expand Up @@ -107,7 +107,7 @@ public void AssertBundle(AssertWasmSdkBundleOptions assertOptions)
string buildType = assertOptions.IsPublish ? "publish" : "build";
var nativeFilesToCheck = new List<string>() { "dotnet.native.wasm", "dotnet.native.js" };
if (assertOptions.RuntimeType == RuntimeVariant.MultiThreaded)
nativeFilesToCheck.Add("dotnet.native.worker.js");
nativeFilesToCheck.Add("dotnet.native.worker.mjs");
foreach (string nativeFilename in nativeFilesToCheck)
{
if (!actualDotnetFiles.TryGetValue(nativeFilename, out DotNetFileName? dotnetFile))
Expand All @@ -121,7 +121,7 @@ public void AssertBundle(AssertWasmSdkBundleOptions assertOptions)

if (assertOptions.ExpectedFileType != NativeFilesType.FromRuntimePack)
{
if (nativeFilename == "dotnet.native.worker.js")
if (nativeFilename == "dotnet.native.worker.mjs")
{
Console.WriteLine($"Skipping the verification whether {nativeFilename} is from the runtime pack. The check wouldn't be meaningful as the runtime pack file has the same size as the relinked file");
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public class AssetsComputingHelper
".ts" when fromMonoPackage && fileName == "dotnet.d" => "dotnet type definition is not used by Blazor",
".map" when !emitSourceMap && fromMonoPackage && (fileName == "dotnet.js" || fileName == "dotnet.runtime.js") => "source map file is not published",
".ts" when fromMonoPackage && fileName == "dotnet-legacy.d" => "dotnet type definition is not used by Blazor",
".js" when assetType == "native" && !(dotnetJsSingleThreadNames.Contains(fileName) || (enableThreads && fileName == "dotnet.native.worker")) => $"{fileName}{extension} is not used by Blazor",
".js" when assetType == "native" && !dotnetJsSingleThreadNames.Contains(fileName) => $"{fileName}{extension} is not used by Blazor",
".mjs" when assetType == "native" && !(enableThreads && fileName == "dotnet.native.worker") => $"{fileName}{extension} is not used by Blazor",
".pdb" when !copySymbols => "copying symbols is disabled",
".symbols" when fromMonoPackage => "extension .symbols is not required.",
_ => null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void AddDictionary(StringBuilder sb, Dictionary<string, string>? res)
public Dictionary<string, string>? GetNativeResourceTargetInBootConfig(BootJsonData bootConfig, string resourceName)
{
string resourceExtension = Path.GetExtension(resourceName);
if (resourceName.StartsWith("dotnet.native.worker", StringComparison.OrdinalIgnoreCase) && string.Equals(resourceExtension, ".js", StringComparison.OrdinalIgnoreCase))
if (resourceName.StartsWith("dotnet.native.worker", StringComparison.OrdinalIgnoreCase) && string.Equals(resourceExtension, ".mjs", StringComparison.OrdinalIgnoreCase))
return bootConfig.resources.jsModuleWorker ??= new();
else if (resourceName.StartsWith("dotnet.native", StringComparison.OrdinalIgnoreCase) && string.Equals(resourceExtension, ".js", StringComparison.OrdinalIgnoreCase))
return bootConfig.resources.jsModuleNative ??= new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ public override bool Execute()
var key = kvp.Key;
var asset = kvp.Value;
var isDotNetJs = IsAnyDotNetJs(key);
var isDotNetMJs = IsAnyDotNetMJs(key);
var isDotNetWasm = IsDotNetWasm(key);

if (!isDotNetJs && !isDotNetWasm)
if (!isDotNetJs && !isDotNetMJs && !isDotNetWasm)
{
if (resolvedNativeAssetToPublish.TryGetValue(Path.GetFileName(asset.GetMetadata("OriginalItemSpec")), out var existing))
{
Expand Down Expand Up @@ -203,28 +204,30 @@ public override bool Execute()
continue;
}

if (isDotNetJs)
if (isDotNetJs || isDotNetMJs)
{
var extension = ".js";
var baseName = Path.GetFileNameWithoutExtension(key);
if (baseName.StartsWith("dotnet.native.worker"))
if (baseName.StartsWith("dotnet.native.worker")) {
baseName = "dotnet.native.worker";
else if (baseName.StartsWith("dotnet.native"))
extension = ".mjs";
} else if (baseName.StartsWith("dotnet.native"))
baseName = "dotnet.native";
else if (baseName.StartsWith("dotnet.runtime"))
baseName = "dotnet.runtime";
else if (baseName.StartsWith("dotnet"))
baseName = "dotnet";

var aotDotNetJs = WasmAotAssets.SingleOrDefault(a => $"{a.GetMetadata("FileName")}{a.GetMetadata("Extension")}" == $"{baseName}.js");
var aotDotNetJs = WasmAotAssets.SingleOrDefault(a => $"{a.GetMetadata("FileName")}{a.GetMetadata("Extension")}" == $"{baseName}{extension}");
ITaskItem newDotNetJs = null;
if (aotDotNetJs != null)
{
newDotNetJs = new TaskItem(Path.GetFullPath(aotDotNetJs.ItemSpec), asset.CloneCustomMetadata());
newDotNetJs.SetMetadata("OriginalItemSpec", aotDotNetJs.ItemSpec);

string relativePath = baseName != "dotnet" || FingerprintDotNetJs
? $"_framework/{$"{baseName}.{DotNetJsVersion}.{FileHasher.GetFileHash(aotDotNetJs.ItemSpec)}.js"}"
: $"_framework/{baseName}.js";
? $"_framework/{$"{baseName}.{DotNetJsVersion}.{FileHasher.GetFileHash(aotDotNetJs.ItemSpec)}{extension}"}"
: $"_framework/{baseName}{extension}";

newDotNetJs.SetMetadata("RelativePath", relativePath);

Expand All @@ -239,7 +242,7 @@ public override bool Execute()

ApplyPublishProperties(newDotNetJs);
nativeStaticWebAssets.Add(newDotNetJs);
if (resolvedNativeAssetToPublish.TryGetValue($"{baseName}.js", out var resolved))
if (resolvedNativeAssetToPublish.TryGetValue($"{baseName}{extension}", out var resolved))
{
filesToRemove.Add(resolved);
}
Expand Down Expand Up @@ -296,6 +299,12 @@ static bool IsAnyDotNetJs(string key)
return fileName.StartsWith("dotnet.", StringComparison.Ordinal) && fileName.EndsWith(".js", StringComparison.Ordinal);
}

static bool IsAnyDotNetMJs(string key)
{
var fileName = Path.GetFileName(key);
return fileName.StartsWith("dotnet.", StringComparison.Ordinal) && fileName.EndsWith(".mjs", StringComparison.Ordinal);
}

static bool IsDotNetWasm(string key)
{
var name = Path.GetFileName(key);
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/WasmAppBuilder/WasmAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected override bool ExecuteInternal()
if (!FileCopyChecked(item.ItemSpec, dest, "NativeAssets"))
return false;

if (!IncludeThreadsWorker && name == "dotnet.native.worker.js")
if (!IncludeThreadsWorker && name == "dotnet.native.worker.mjs")
continue;

if (name == "dotnet.runtime.js.map" || name == "dotnet.js.map")
Expand Down

0 comments on commit d23f6fa

Please sign in to comment.