Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/tasks/AotCompilerTask/MonoAOTCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task
private FileCache? _cache;
private int _numCompiled;
private int _totalNumAssemblies;
private readonly Dictionary<string, string> _symbolNameFixups = new();

private bool ProcessAndValidateArguments()
{
Expand Down Expand Up @@ -928,7 +929,7 @@ private bool GenerateAotModulesTable(IEnumerable<ITaskItem> assemblies, string[]
if (!TryGetAssemblyName(asmPath, out string? assemblyName))
return false;

string symbolName = assemblyName.Replace ('.', '_').Replace ('-', '_').Replace(' ', '_');
string symbolName = FixupSymbolName(assemblyName);
symbols.Add($"mono_aot_module_{symbolName}_info");
}

Expand Down Expand Up @@ -1042,6 +1043,35 @@ private static IList<ITaskItem> ConvertAssembliesDictToOrderedList(ConcurrentDic
return outItems;
}

private string FixupSymbolName(string name)
{
if (_symbolNameFixups.TryGetValue(name, out string? fixedName))
return fixedName;

UTF8Encoding utf8 = new();
byte[] bytes = utf8.GetBytes(name);
StringBuilder sb = new();

foreach (byte b in bytes)
{
if ((b >= (byte)'0' && b <= (byte)'9') ||
(b >= (byte)'a' && b <= (byte)'z') ||
(b >= (byte)'A' && b <= (byte)'Z') ||
(b == (byte)'_'))
{
sb.Append((char)b);
}
else
{
sb.Append('_');
}
}

fixedName = sb.ToString();
_symbolNameFixups[name] = fixedName;
return fixedName;
}

internal sealed class PrecompileArguments
{
public PrecompileArguments(string ResponseFilePath, IDictionary<string, string> EnvironmentVariables, string WorkingDir, ITaskItem AOTAssembly, IList<ProxyFile> ProxyFiles)
Expand Down
39 changes: 26 additions & 13 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ void Run() => RunAndTestWasmApp(
}

[Theory]
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Release")]
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Debug")]
public void BuildThenPublishWithAOT(BuildArgs buildArgs, RunHost host, string id)
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Release", testUnicode: false)]
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Debug", testUnicode: false)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you are missing the corresponding changes to BuildAndRunAttribute?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With @radical we decided to introduce some changes to tests in net8 first, maybe it will help resolve #83497 and only then backport it.

[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Release", testUnicode: true)]
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Debug", testUnicode: true)]
public void BuildThenPublishWithAOT(BuildArgs buildArgs, RunHost host, string id, bool testUnicode)
{
string projectName = $"build_publish_{buildArgs.Config}";
string projectName = testUnicode ?
$"build_publish_{buildArgs.Config}_{s_unicodeChar}" :
$"build_publish_{buildArgs.Config}";

buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs, extraProperties: "<_WasmDevel>true</_WasmDevel>");
Expand Down Expand Up @@ -109,8 +113,13 @@ public void BuildThenPublishWithAOT(BuildArgs buildArgs, RunHost host, string id

_testOutput.WriteLine($"{Environment.NewLine}Publishing with no changes ..{Environment.NewLine}");

// relink by default for Release+publish
(_, output) = BuildProject(buildArgs,
// FIXME: relinking for paths with unicode does not work:
// [ActiveIssue("https://github.com/dotnet/runtime/issues/83497")]
// remove the condition when the issue is fixed
if (!testUnicode)
{
// relink by default for Release+publish
(_, output) = BuildProject(buildArgs,
id: id,
new BuildProjectOptions(
DotnetWasmFromRuntimePack: false,
Expand All @@ -119,13 +128,14 @@ public void BuildThenPublishWithAOT(BuildArgs buildArgs, RunHost host, string id
UseCache: false,
Label: "first_publish"));

var publishStat = StatFiles(pathsDict.Select(kvp => kvp.Value.fullPath));
Assert.True(publishStat["pinvoke.o"].Exists);
Assert.True(publishStat[$"{mainDll}.bc"].Exists);
CheckOutputForNativeBuild(expectAOT: true, expectRelinking: false, buildArgs, output);
CompareStat(firstBuildStat, publishStat, pathsDict.Values);
var publishStat = StatFiles(pathsDict.Select(kvp => kvp.Value.fullPath));
Assert.True(publishStat["pinvoke.o"].Exists);
Assert.True(publishStat[$"{mainDll}.bc"].Exists);
CheckOutputForNativeBuild(expectAOT: true, expectRelinking: false, buildArgs, output);
CompareStat(firstBuildStat, publishStat, pathsDict.Values);

Run(expectAOT: true);
Run(expectAOT: true);
}

// second build
(_, output) = BuildProject(buildArgs,
Expand All @@ -143,7 +153,10 @@ public void BuildThenPublishWithAOT(BuildArgs buildArgs, RunHost host, string id

// no native files changed
pathsDict.UpdateTo(unchanged: true);
CompareStat(publishStat, secondBuildStat, pathsDict.Values);
if (!testUnicode)
{
CompareStat(publishStat, secondBuildStat, pathsDict.Values);
}

void Run(bool expectAOT) => RunAndTestWasmApp(
buildArgs with { AOT = expectAOT },
Expand Down