Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] Fix encoding problem when publishing with AOT #89388

Closed
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 @@
}

[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)]

Check failure on line 73 in src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs

View check run for this annotation

Azure Pipelines / runtime (Build Browser wasm Linux Release WasmBuildTests)

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs#L73

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs(73,74): error CS1739: (NETCORE_ENGINEERING_TELEMETRY=Build) The best overload for 'BuildAndRunAttribute' does not have a parameter named 'testUnicode'

Check failure on line 73 in src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs

View check run for this annotation

Azure Pipelines / runtime

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs#L73

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs(73,74): error CS1739: (NETCORE_ENGINEERING_TELEMETRY=Build) The best overload for 'BuildAndRunAttribute' does not have a parameter named 'testUnicode'
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Debug", testUnicode: false)]

Check failure on line 74 in src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs

View check run for this annotation

Azure Pipelines / runtime (Build Browser wasm Linux Release WasmBuildTests)

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs#L74

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs(74,72): error CS1739: (NETCORE_ENGINEERING_TELEMETRY=Build) The best overload for 'BuildAndRunAttribute' does not have a parameter named 'testUnicode'

Check failure on line 74 in src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs

View check run for this annotation

Azure Pipelines / runtime

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs#L74

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs(74,72): error CS1739: (NETCORE_ENGINEERING_TELEMETRY=Build) The best overload for 'BuildAndRunAttribute' does not have a parameter named 'testUnicode'
Copy link
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
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)]

Check failure on line 75 in src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs

View check run for this annotation

Azure Pipelines / runtime (Build Browser wasm Linux Release WasmBuildTests)

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs#L75

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs(75,74): error CS1739: (NETCORE_ENGINEERING_TELEMETRY=Build) The best overload for 'BuildAndRunAttribute' does not have a parameter named 'testUnicode'

Check failure on line 75 in src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs

View check run for this annotation

Azure Pipelines / runtime

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs#L75

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs(75,74): error CS1739: (NETCORE_ENGINEERING_TELEMETRY=Build) The best overload for 'BuildAndRunAttribute' does not have a parameter named 'testUnicode'
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Debug", testUnicode: true)]

Check failure on line 76 in src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs

View check run for this annotation

Azure Pipelines / runtime (Build Browser wasm Linux Release WasmBuildTests)

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs#L76

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs(76,72): error CS1739: (NETCORE_ENGINEERING_TELEMETRY=Build) The best overload for 'BuildAndRunAttribute' does not have a parameter named 'testUnicode'

Check failure on line 76 in src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs

View check run for this annotation

Azure Pipelines / runtime

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs#L76

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildPublishTests.cs(76,72): error CS1739: (NETCORE_ENGINEERING_TELEMETRY=Build) The best overload for 'BuildAndRunAttribute' does not have a parameter named 'testUnicode'
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 @@

_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 @@
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 @@

// 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
Loading