Skip to content

Commit

Permalink
Follow ups for Blazor AOT
Browse files Browse the repository at this point in the history
* Add Emscripten packs to manifest
* Update acquire tool to use manifest from the dotnet sdk
* Add AOT option to templates
  • Loading branch information
pranavkm committed Mar 20, 2021
1 parent ef0c2fc commit 5a4130e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 69 deletions.
12 changes: 12 additions & 0 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@
<Dependency Name="Microsoft.NETCore.App.Runtime.AOT.win-x64.Cross.browser-wasm" Version="6.0.0-preview.3.21167.1">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>0f64b267ac0552f07b06f18103581b880c8c53c6</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Runtime.Emscripten.2.0.12.Node.win-x64" Version="6.0.0-preview.3.21167.1">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>0f64b267ac0552f07b06f18103581b880c8c53c6</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Runtime.Emscripten.2.0.12.Python.win-x64" Version="6.0.0-preview.3.21167.1">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>0f64b267ac0552f07b06f18103581b880c8c53c6</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64" Version="6.0.0-preview.3.21167.1">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>0f64b267ac0552f07b06f18103581b880c8c53c6</Sha>
</Dependency>
<Dependency Name="Microsoft.NETCore.BrowserDebugHost.Transport" Version="6.0.0-preview.3.21167.1">
<Uri>https://github.com/dotnet/runtime</Uri>
Expand Down
9 changes: 6 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@
<MicrosoftExtensionsDependencyModelVersion>6.0.0-preview.3.21167.1</MicrosoftExtensionsDependencyModelVersion>
<MicrosoftNETCoreAppRefVersion>6.0.0-preview.3.21167.1</MicrosoftNETCoreAppRefVersion>
<MicrosoftNETCoreAppRuntimewinx64Version>6.0.0-preview.3.21167.1</MicrosoftNETCoreAppRuntimewinx64Version>
<MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>6.0.0-preview.3.21167.1</MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>
<MicrosoftNETRuntimeWebAssemblySdkVersion>6.0.0-preview.3.21167.1</MicrosoftNETRuntimeWebAssemblySdkVersion>
<MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>6.0.0-preview.3.21167.1</MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>
<MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeMonoAOTCompilerTaskVersion>
<MicrosoftNETRuntimeEmscripten2012Nodewinx64Version>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeEmscripten2012Nodewinx64Version>
<MicrosoftNETRuntimeEmscripten2012Pythonwinx64Version>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeEmscripten2012Pythonwinx64Version>
<MicrosoftNETRuntimeEmscripten2012Sdkwinx64Version>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeEmscripten2012Sdkwinx64Version>
<MicrosoftNETRuntimeWebAssemblySdkVersion>6.0.0-preview.3.21169.6</MicrosoftNETRuntimeWebAssemblySdkVersion>
<MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>6.0.0-preview.3.21169.6</MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion>
<MicrosoftNETCoreBrowserDebugHostTransportVersion>6.0.0-preview.3.21167.1</MicrosoftNETCoreBrowserDebugHostTransportVersion>
<MicrosoftWin32RegistryVersion>6.0.0-preview.3.21167.1</MicrosoftWin32RegistryVersion>
<MicrosoftExtensionsCachingAbstractionsVersion>6.0.0-preview.3.21167.1</MicrosoftExtensionsCachingAbstractionsVersion>
Expand Down
101 changes: 36 additions & 65 deletions src/Components/WebAssembly/BlazorManifest/acquire/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,19 @@ static string GetDotnetPath()

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

try
{
var restore = Restore(tempDirectory, restoreDirectory, out var packs);
var packs = GetPacks(sdkDirectory);
var restore = RestorePacks(tempDirectory, restoreDirectory, packs);
if (restore != 0)
{
return restore;
}

var sourceManifestDirectory = Path.Combine(restoreDirectory, "microsoft.net.sdk.blazorwebassembly.aot", ManifestVersion);
var targetManifestDirectory = Path.Combine(sdkDirectory, "sdk-manifests", ManifestVersion, "Microsoft.NET.Sdk.BlazorWebAssembly.AOT");
Move(sourceManifestDirectory, targetManifestDirectory);

foreach (var (id, version) in packs)
{
var source = Path.Combine(restoreDirectory, id.ToLowerInvariant(), version);
Expand All @@ -59,7 +55,7 @@ static int Main(string[] args)
sdkVersionProc.WaitForExit();
var sdkVersion = sdkVersionProc.StandardOutput.ReadToEnd().Trim();
var sentinelPath = Path.Combine(sdkDirectory, "sdk", sdkVersion, "EnableWorkloadResolver.sentinel");
Console.WriteLine($"Writing sentinel to {sentinelPath}.");
Console.WriteLine($"Enabling Workloads support in dotnet SDK v{sdkVersion}.");

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

static int Restore(string tempDirectory, string restoreDirectory, out List<(string, string)> packs)
static List<(string Id, string Version)> GetPacks(string sdkDirectory)
{
packs = null;

var restoreProject = Path.Combine(tempDirectory, "restore", "Restore.csproj");
var restoreProjectDirectory = Directory.CreateDirectory(Path.GetDirectoryName(restoreProject));

File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.props"), "<Project />");
File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.targets"), "<Project />");

var projectFile = @"
<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include=""Microsoft.NET.Sdk.BlazorWebAssembly.AOT"" Version=""6.0.0-*"" />
</ItemGroup>
</Project>
";
File.WriteAllText(restoreProject, projectFile);

Console.WriteLine("Restoring...");

var process = Process.Start(new ProcessStartInfo
{
FileName = MuxerPath,
ArgumentList = { "restore", restoreProject },
Environment =
{
["NUGET_PACKAGES"] = restoreDirectory,
},
});
process.WaitForExit();
if (process.ExitCode != 0)
var manifestDirectory = Path.Combine(sdkDirectory, "sdk-manifests", ManifestVersion, "Microsoft.NET.Workload.BlazorWebAssembly");
if (!Directory.Exists(manifestDirectory))
{
Console.Error.WriteLine("Unable to restore Microsoft.NET.Sdk.BlazorWebAssembly.AOT workload.");
return 1;
throw new DirectoryNotFoundException($"Cound not find directory {manifestDirectory}. A 6.0-preview3 SDK or newer is required for this tool to function.");
}

var manifestDirectory = Path.Combine(restoreDirectory, "microsoft.net.sdk.blazorwebassembly.aot");
var version = Directory.EnumerateDirectories(manifestDirectory).First();

manifestDirectory = Path.Combine(manifestDirectory, ManifestVersion);
Directory.Move(version, manifestDirectory);

var manifestPath = Path.Combine(manifestDirectory, "WorkloadManifest.json");
var manifest = JsonSerializer.Deserialize<PackInformation>(File.ReadAllBytes(manifestPath), new JsonSerializerOptions(JsonSerializerDefaults.Web));

projectFile = @"
<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<NoWarn>$(NoWarn);NU1213</NoWarn>
</PropertyGroup>
<ItemGroup>
";
packs = new List<(string id, string version)>();
var packs = new List<(string, string)>();
foreach (var item in manifest.Packs)
{
var packageName = item.Key;
Expand All @@ -161,34 +110,56 @@ static int Restore(string tempDirectory, string restoreDirectory, out List<(stri
}
else
{
Console.Error.WriteLine("Unsupported platform.");
return 1;
throw new NotSupportedException("Unsupported OS platform.");
}
}
projectFile += @$"<PackageReference Include=""{packageName}"" Version=""{item.Value.Version}"" />";
packs.Add((packageName, item.Value.Version));
}

return packs;
}

static int RestorePacks(string tempDirectory, string restoreDirectory, List<(string Id, string Version)> packs)
{
var restoreProject = Path.Combine(tempDirectory, "restore", "Restore.csproj");
var restoreProjectDirectory = Directory.CreateDirectory(Path.GetDirectoryName(restoreProject));

File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.props"), "<Project />");
File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.targets"), "<Project />");

var projectFile = @"
<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<NoWarn>$(NoWarn);NU1213</NoWarn>
</PropertyGroup>
<ItemGroup>
";
foreach (var (Id, Version) in packs)
{
projectFile += $"<PackageReference Include=\"{Id}\" Version=\"{Version}\" />";
}

projectFile += @"
</ItemGroup>
</Project>
";
File.WriteAllText(restoreProject, projectFile);

process = Process.Start(new ProcessStartInfo
var process = Process.Start(new ProcessStartInfo
{
FileName = MuxerPath,
ArgumentList = { "restore", restoreProject },
#if !DEBUG
RedirectStandardError = true,
RedirectStandardOutput = true,
#endif
Environment =
{
["NUGET_PACKAGES"] = restoreDirectory,
},
});
process.WaitForExit();


return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
MicrosoftNETRuntimeMonoAOTCompilerTaskVersion=$(MicrosoftNETRuntimeMonoAOTCompilerTaskVersion);
MicrosoftNETRuntimeWebAssemblySdkVersion=$(MicrosoftNETRuntimeWebAssemblySdkVersion);
MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion=$(MicrosoftNETCoreAppRuntimeAOTwinx64CrossbrowserwasmVersion);
MicrosoftNETRuntimeEmscripten2012NodeVersion=$(MicrosoftNETRuntimeEmscripten2012Nodewinx64Version);
MicrosoftNETRuntimeEmscripten2012PythonVersion=$(MicrosoftNETRuntimeEmscripten2012Pythonwinx64Version);
MicrosoftNETRuntimeEmscripten2012SdkVersion=$(MicrosoftNETRuntimeEmscripten2012Sdkwinx64Version);
</_WorkloadManifestProperties>

<WorkloadManifestPath>$(IntermediateOutputPath)WorkloadManifest.json</WorkloadManifestPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"packs": [
"Microsoft.NET.Runtime.MonoAOTCompiler.Task",
"Microsoft.NET.Runtime.WebAssembly.Sdk",
"Microsoft.Netcore.App.Runtime.Aot.Cross.browser-wasm"
"Microsoft.Netcore.App.Runtime.Aot.Cross.browser-wasm",
"Microsoft.NET.Runtime.Emscripten.2.0.12.Node",
"Microsoft.NET.Runtime.Emscripten.2.0.12.Python",
"Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk"
]
}
},
Expand All @@ -28,6 +31,36 @@
"linux-x64": "microsoft.netcore.app.runtime.aot.linux-x64.cross.browser-wasm",
"osx-x64": "microsoft.netcore.app.runtime.aot.osx-x64.cross.browser-wasm"
}
},
"Microsoft.NET.Runtime.Emscripten.2.0.12.Node" : {
"kind": "Sdk",
"version": "${MicrosoftNETRuntimeEmscripten2012NodeVersion}",
"alias-to": {
"win-x86": "Microsoft.NET.Runtime.Emscripten.2.0.12.Node.win-x86",
"win-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Node.win-x64",
"linux-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Node.linux-x64",
"osx-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Node.osx-x64"
}
},
"Microsoft.NET.Runtime.Emscripten.2.0.12.Python" : {
"kind": "Sdk",
"version": "${MicrosoftNETRuntimeEmscripten2012PythonVersion}",
"alias-to": {
"win-x86": "Microsoft.NET.Runtime.Emscripten.2.0.12.Python.win-x86",
"win-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Python.win-x64",
"linux-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Python.linux-x64",
"osx-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Python.osx-x64"
}
},
"Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk" : {
"kind": "Sdk",
"version": "${MicrosoftNETRuntimeEmscripten2012SdkVersion}",
"alias-to": {
"win-x86": "Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x86",
"win-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.win-x64",
"linux-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.linux-x64",
"osx-x64": "Microsoft.NET.Runtime.Emscripten.2.0.12.Sdk.osx-x64"
}
}
}
}

0 comments on commit 5a4130e

Please sign in to comment.