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

[wasm] InterpToNativeGenerator: use invariant culture when generating C #71460

Merged
merged 2 commits into from
Jun 30, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/tasks/WasmAppBuilder/InterpToNativeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public string Emit(char c)
throw new InvalidSignatureCharException(c);
}

return $"mono_wasm_interp_method_args_get_{char.ToLower(c)}arg (margs, {argIndex})";
return $"mono_wasm_interp_method_args_get_{char.ToLower(c, CultureInfo.InvariantCulture)}arg (margs, {argIndex})";
}
}
}
12 changes: 10 additions & 2 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,14 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
(int exitCode, string buildOutput) result;
try
{
result = AssertBuild(sb.ToString(), id, expectSuccess: options.ExpectSuccess, envVars: s_buildEnv.EnvVars);
var envVars = s_buildEnv.EnvVars;
if (options.ExtraBuildEnvironmentVariables is not null)
{
envVars = new Dictionary<string, string>(s_buildEnv.EnvVars);
foreach (var kvp in options.ExtraBuildEnvironmentVariables!)
envVars[kvp.Key] = kvp.Value;
}
result = AssertBuild(sb.ToString(), id, expectSuccess: options.ExpectSuccess, envVars: envVars);

//AssertRuntimePackPath(result.buildOutput);

Expand Down Expand Up @@ -898,7 +905,8 @@ public record BuildProjectOptions
string? Verbosity = null,
string? Label = null,
string? TargetFramework = null,
string? MainJS = null
string? MainJS = null,
IDictionary<string, string>? ExtraBuildEnvironmentVariables = null
);

public record BlazorBuildOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -115,6 +115,57 @@ public static int Main()
Assert.Contains("Main running", output);
}

[Theory]
[BuildAndRun(host: RunHost.V8, parameters: new object[] { "tr_TR.UTF-8" })]
public void BuildNativeInNonEnglishCulture(BuildArgs buildArgs, string culture, RunHost host, string id)
{
// Check that we can generate interp tables in non-english cultures
// Prompted by https://github.com/dotnet/runtime/issues/71149

string code = @"
using System;
using System.Runtime.InteropServices;

Console.WriteLine($""square: {square(5)}"");
return 42;

[DllImport(""simple"")] static extern int square(int x);
";

buildArgs = ExpandBuildArgs(buildArgs,
extraItems: @$"<NativeFileReference Include=""simple.c"" />",
extraProperties: buildArgs.AOT
? string.Empty
: "<WasmBuildNative>true</WasmBuildNative>");

var extraEnvVars = new Dictionary<string, string> {
{ "LANG", culture },
{ "LC_ALL", culture },
};

(_, string output) = BuildProject(buildArgs,
id: id,
new BuildProjectOptions(
InitProject: () =>
{
File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), code);
File.Copy(Path.Combine(BuildEnvironment.TestAssetsPath, "native-libs", "simple.c"),
Path.Combine(_projectDir!, "simple.c"));
},
Publish: buildArgs.AOT,
DotnetWasmFromRuntimePack: false,
ExtraBuildEnvironmentVariables: extraEnvVars
));

output = RunAndTestWasmApp(buildArgs,
buildDir: _projectDir,
expectedExitCode: 42,
host: host,
id: id,
envVars: extraEnvVars);
Assert.Contains("square: 25", output);
}

private (BuildArgs, string) BuildForVariadicFunctionTests(string programText, BuildArgs buildArgs, string id)
{
string filename = "variadic.o";
Expand Down
6 changes: 6 additions & 0 deletions src/tests/BuildWasmApps/testassets/native-libs/simple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdarg.h>

int square(int x)
{
return x * x;
}