Skip to content

Commit 5a4130e

Browse files
committed
Follow ups for Blazor AOT
* Add Emscripten packs to manifest * Update acquire tool to use manifest from the dotnet sdk * Add AOT option to templates
1 parent ef0c2fc commit 5a4130e

File tree

5 files changed

+91
-69
lines changed

5 files changed

+91
-69
lines changed

eng/Version.Details.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,18 @@
284284
<Dependency Name="Microsoft.NETCore.App.Runtime.AOT.win-x64.Cross.browser-wasm" Version="6.0.0-preview.3.21167.1">
285285
<Uri>https://github.com/dotnet/runtime</Uri>
286286
<Sha>0f64b267ac0552f07b06f18103581b880c8c53c6</Sha>
287+
</Dependency>
288+
<Dependency Name="Microsoft.NET.Runtime.Emscripten.2.0.12.Node.win-x64" Version="6.0.0-preview.3.21167.1">
289+
<Uri>https://github.com/dotnet/runtime</Uri>
290+
<Sha>0f64b267ac0552f07b06f18103581b880c8c53c6</Sha>
291+
</Dependency>
292+
<Dependency Name="Microsoft.NET.Runtime.Emscripten.2.0.12.Python.win-x64" Version="6.0.0-preview.3.21167.1">
293+
<Uri>https://github.com/dotnet/runtime</Uri>
294+
<Sha>0f64b267ac0552f07b06f18103581b880c8c53c6</Sha>
295+
</Dependency>
296+
<Dependency Name="Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64" Version="6.0.0-preview.3.21167.1">
297+
<Uri>https://github.com/dotnet/runtime</Uri>
298+
<Sha>0f64b267ac0552f07b06f18103581b880c8c53c6</Sha>
287299
</Dependency>
288300
<Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="6.0.0-preview.3.21167.1">
289301
<Uri>https://github.com/dotnet/runtime</Uri>

eng/Versions.props

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@
6868
<MicrosoftExtensionsDependencyModelVersion>6.0.0-preview.3.21167.1</MicrosoftExtensionsDependencyModelVersion>
6969
<MicrosoftNETCoreAppRefVersion>6.0.0-preview.3.21167.1</MicrosoftNETCoreAppRefVersion>
7070
<MicrosoftNETCoreAppRuntimewinx64Version>6.0.0-preview.3.21167.1</MicrosoftNETCoreAppRuntimewinx64Version>
71-
<MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>6.0.0-preview.3.21167.1</MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>
72-
<MicrosoftNETRuntimeWebAssemblySdkVersion>6.0.0-preview.3.21167.1</MicrosoftNETRuntimeWebAssemblySdkVersion>
73-
<MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>6.0.0-preview.3.21167.1</MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>
71+
<MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>
72+
<MicrosoftNETRuntimeEmscripten2012Nodewinx64Version>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeEmscripten2012Nodewinx64Version>
73+
<MicrosoftNETRuntimeEmscripten2012Pythonwinx64Version>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeEmscripten2012Pythonwinx64Version>
74+
<MicrosoftNETRuntimeEmscripten2012Sdkwinx64Version>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeEmscripten2012Sdkwinx64Version>
75+
<MicrosoftNETRuntimeWebAssemblySdkVersion>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeWebAssemblySdkVersion>
76+
<MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>6.0.0-preview.3.21169.6</MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>
7477
<MicrosoftNETCoreBrowserDebugHostTransportVersion>6.0.0-preview.3.21167.1</MicrosoftNETCoreBrowserDebugHostTransportVersion>
7578
<MicrosoftWin32RegistryVersion>6.0.0-preview.3.21167.1</MicrosoftWin32RegistryVersion>
7679
<MicrosoftExtensionsCachingAbstractionsVersion>6.0.0-preview.3.21167.1</MicrosoftExtensionsCachingAbstractionsVersion>

src/Components/WebAssembly/BlazorManifest/acquire/Program.cs

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,19 @@ static string GetDotnetPath()
2525

2626
static int Main(string[] args)
2727
{
28-
System.Console.WriteLine(MuxerPath);
2928
var sdkDirectory = args.Length > 0 ? args[0] : Path.GetDirectoryName(MuxerPath);
3029
var tempDirectory = Path.Combine(Directory.GetCurrentDirectory(), "tmp", Path.GetRandomFileName());
3130
var restoreDirectory = Path.Combine(tempDirectory, ".nuget");
3231

3332
try
3433
{
35-
var restore = Restore(tempDirectory, restoreDirectory, out var packs);
34+
var packs = GetPacks(sdkDirectory);
35+
var restore = RestorePacks(tempDirectory, restoreDirectory, packs);
3636
if (restore != 0)
3737
{
3838
return restore;
3939
}
4040

41-
var sourceManifestDirectory = Path.Combine(restoreDirectory, "microsoft.net.sdk.blazorwebassembly.aot", ManifestVersion);
42-
var targetManifestDirectory = Path.Combine(sdkDirectory, "sdk-manifests", ManifestVersion, "Microsoft.NET.Sdk.BlazorWebAssembly.AOT");
43-
Move(sourceManifestDirectory, targetManifestDirectory);
44-
4541
foreach (var (id, version) in packs)
4642
{
4743
var source = Path.Combine(restoreDirectory, id.ToLowerInvariant(), version);
@@ -59,7 +55,7 @@ static int Main(string[] args)
5955
sdkVersionProc.WaitForExit();
6056
var sdkVersion = sdkVersionProc.StandardOutput.ReadToEnd().Trim();
6157
var sentinelPath = Path.Combine(sdkDirectory, "sdk", sdkVersion, "EnableWorkloadResolver.sentinel");
62-
Console.WriteLine($"Writing sentinel to {sentinelPath}.");
58+
Console.WriteLine($"Enabling Workloads support in dotnet SDK v{sdkVersion}.");
6359

6460
File.WriteAllBytes(sentinelPath, Array.Empty<byte>());
6561
}
@@ -84,64 +80,17 @@ static void Move(string source, string destination)
8480
Directory.Move(source, destination);
8581
}
8682

87-
static int Restore(string tempDirectory, string restoreDirectory, out List<(string, string)> packs)
83+
static List<(string Id, string Version)> GetPacks(string sdkDirectory)
8884
{
89-
packs = null;
90-
91-
var restoreProject = Path.Combine(tempDirectory, "restore", "Restore.csproj");
92-
var restoreProjectDirectory = Directory.CreateDirectory(Path.GetDirectoryName(restoreProject));
93-
94-
File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.props"), "<Project />");
95-
File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.targets"), "<Project />");
96-
97-
var projectFile = @"
98-
<Project Sdk=""Microsoft.NET.Sdk"">
99-
<PropertyGroup>
100-
<TargetFramework>net6.0</TargetFramework>
101-
</PropertyGroup>
102-
<ItemGroup>
103-
<PackageReference Include=""Microsoft.NET.Sdk.BlazorWebAssembly.AOT"" Version=""6.0.0-*"" />
104-
</ItemGroup>
105-
</Project>
106-
";
107-
File.WriteAllText(restoreProject, projectFile);
108-
109-
Console.WriteLine("Restoring...");
110-
111-
var process = Process.Start(new ProcessStartInfo
112-
{
113-
FileName = MuxerPath,
114-
ArgumentList = { "restore", restoreProject },
115-
Environment =
116-
{
117-
["NUGET_PACKAGES"] = restoreDirectory,
118-
},
119-
});
120-
process.WaitForExit();
121-
if (process.ExitCode != 0)
85+
var manifestDirectory = Path.Combine(sdkDirectory, "sdk-manifests", ManifestVersion, "Microsoft.NET.Workload.BlazorWebAssembly");
86+
if (!Directory.Exists(manifestDirectory))
12287
{
123-
Console.Error.WriteLine("Unable to restore Microsoft.NET.Sdk.BlazorWebAssembly.AOT workload.");
124-
return 1;
88+
throw new DirectoryNotFoundException($"Cound not find directory {manifestDirectory}. A 6.0-preview3 SDK or newer is required for this tool to function.");
12589
}
12690

127-
var manifestDirectory = Path.Combine(restoreDirectory, "microsoft.net.sdk.blazorwebassembly.aot");
128-
var version = Directory.EnumerateDirectories(manifestDirectory).First();
129-
130-
manifestDirectory = Path.Combine(manifestDirectory, ManifestVersion);
131-
Directory.Move(version, manifestDirectory);
132-
13391
var manifestPath = Path.Combine(manifestDirectory, "WorkloadManifest.json");
13492
var manifest = JsonSerializer.Deserialize<PackInformation>(File.ReadAllBytes(manifestPath), new JsonSerializerOptions(JsonSerializerDefaults.Web));
135-
136-
projectFile = @"
137-
<Project Sdk=""Microsoft.NET.Sdk"">
138-
<PropertyGroup>
139-
<TargetFramework>net6.0</TargetFramework>
140-
<NoWarn>$(NoWarn);NU1213</NoWarn>
141-
</PropertyGroup>
142-
<ItemGroup>
143-
";
144-
packs = new List<(string id, string version)>();
93+
var packs = new List<(string, string)>();
14594
foreach (var item in manifest.Packs)
14695
{
14796
var packageName = item.Key;
@@ -161,34 +110,56 @@ static int Restore(string tempDirectory, string restoreDirectory, out List<(stri
161110
}
162111
else
163112
{
164-
Console.Error.WriteLine("Unsupported platform.");
165-
return 1;
113+
throw new NotSupportedException("Unsupported OS platform.");
166114
}
167115
}
168-
projectFile += @$"<PackageReference Include=""{packageName}"" Version=""{item.Value.Version}"" />";
169116
packs.Add((packageName, item.Value.Version));
170117
}
171118

119+
return packs;
120+
}
121+
122+
static int RestorePacks(string tempDirectory, string restoreDirectory, List<(string Id, string Version)> packs)
123+
{
124+
var restoreProject = Path.Combine(tempDirectory, "restore", "Restore.csproj");
125+
var restoreProjectDirectory = Directory.CreateDirectory(Path.GetDirectoryName(restoreProject));
126+
127+
File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.props"), "<Project />");
128+
File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.targets"), "<Project />");
129+
130+
var projectFile = @"
131+
<Project Sdk=""Microsoft.NET.Sdk"">
132+
<PropertyGroup>
133+
<TargetFramework>net6.0</TargetFramework>
134+
<NoWarn>$(NoWarn);NU1213</NoWarn>
135+
</PropertyGroup>
136+
<ItemGroup>
137+
";
138+
foreach (var (Id, Version) in packs)
139+
{
140+
projectFile += $"<PackageReference Include=\"{Id}\" Version=\"{Version}\" />";
141+
}
142+
172143
projectFile += @"
173144
</ItemGroup>
174145
</Project>
175146
";
176147
File.WriteAllText(restoreProject, projectFile);
177148

178-
process = Process.Start(new ProcessStartInfo
149+
var process = Process.Start(new ProcessStartInfo
179150
{
180151
FileName = MuxerPath,
181152
ArgumentList = { "restore", restoreProject },
153+
#if !DEBUG
182154
RedirectStandardError = true,
183155
RedirectStandardOutput = true,
156+
#endif
184157
Environment =
185158
{
186159
["NUGET_PACKAGES"] = restoreDirectory,
187160
},
188161
});
189162
process.WaitForExit();
190-
191-
192163
return 0;
193164
}
194165

src/Components/WebAssembly/BlazorManifest/src/BlazorManifest.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
MicrosoftNETRuntimeMonoAOTCompilerTaskVersion=$(MicrosoftNETRuntimeMonoAOTCompilerTaskVersion);
1818
MicrosoftNETRuntimeWebAssemblySdkVersion=$(MicrosoftNETRuntimeWebAssemblySdkVersion);
1919
MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion=$(MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion);
20+
MicrosoftNETRuntimeEmscripten2012NodeVersion=$(MicrosoftNETRuntimeEmscripten2012Nodewinx64Version);
21+
MicrosoftNETRuntimeEmscripten2012PythonVersion=$(MicrosoftNETRuntimeEmscripten2012Pythonwinx64Version);
22+
MicrosoftNETRuntimeEmscripten2012SdkVersion=$(MicrosoftNETRuntimeEmscripten2012Sdkwinx64Version);
2023
</_WorkloadManifestProperties>
2124

2225
<WorkloadManifestPath>$(IntermediateOutputPath)WorkloadManifest.json</WorkloadManifestPath>

src/Components/WebAssembly/BlazorManifest/src/WorkloadManifest.json.in

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"packs": [
77
"Microsoft.NET.Runtime.MonoAOTCompiler.Task",
88
"Microsoft.NET.Runtime.WebAssembly.Sdk",
9-
"Microsoft.Netcore.App.Runtime.Aot.Cross.browser-wasm"
9+
"Microsoft.Netcore.App.Runtime.Aot.Cross.browser-wasm",
10+
"Microsoft.NET.Runtime.Emscripten.2.0.12.Node",
11+
"Microsoft.NET.Runtime.Emscripten.2.0.12.Python",
12+
"Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk"
1013
]
1114
}
1215
},
@@ -28,6 +31,36 @@
2831
"linux-x64": "microsoft.netcore.app.runtime.aot.linux-x64.cross.browser-wasm",
2932
"osx-x64": "microsoft.netcore.app.runtime.aot.osx-x64.cross.browser-wasm"
3033
}
34+
},
35+
"Microsoft.NET.Runtime.Emscripten.2.0.12.Node" : {
36+
"kind": "Sdk",
37+
"version": "${MicrosoftNETRuntimeEmscripten2012NodeVersion}",
38+
"alias-to": {
39+
"win-x86": "Microsoft.NET.Runtime.Emscripten.2.0.12.Node.win-x86",
40+
"win-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Node.win-x64",
41+
"linux-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Node.linux-x64",
42+
"osx-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Node.osx-x64"
43+
}
44+
},
45+
"Microsoft.NET.Runtime.Emscripten.2.0.12.Python" : {
46+
"kind": "Sdk",
47+
"version": "${MicrosoftNETRuntimeEmscripten2012PythonVersion}",
48+
"alias-to": {
49+
"win-x86": "Microsoft.NET.Runtime.Emscripten.2.0.12.Python.win-x86",
50+
"win-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Python.win-x64",
51+
"linux-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Python.linux-x64",
52+
"osx-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Python.osx-x64"
53+
}
54+
},
55+
"Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk" : {
56+
"kind": "Sdk",
57+
"version": "${MicrosoftNETRuntimeEmscripten2012SdkVersion}",
58+
"alias-to": {
59+
"win-x86": "Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x86",
60+
"win-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64",
61+
"linux-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.linux-x64",
62+
"osx-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.osx-x64"
63+
}
3164
}
3265
}
3366
}

0 commit comments

Comments
 (0)