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

fix: Force sun.jnu.encoding to be UTF-8 in images #514

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
15 changes: 14 additions & 1 deletion internal/native_image/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def _graal_binary_implementation(ctx):
or install a GraalVM `native-image` toolchain.
""")

is_linux = ctx.target_platform_has_constraint(
ctx.attr._linux_constraint[platform_common.ConstraintValueInfo],
)
is_macos = ctx.target_platform_has_constraint(
ctx.attr._macos_constraint[platform_common.ConstraintValueInfo],
)
Expand Down Expand Up @@ -103,6 +106,16 @@ def _graal_binary_implementation(ctx):
if ctx.files.data:
direct_inputs.extend(ctx.files.data)

env = native_toolchain.env

# The native image will use the same native encoding (as determined by "sun.jnu.encoding")
# as the build environment, so we need to force a UTF-8 locale. On other platforms, the
# encoding is always UTF-8 (on macOS since JEP 400) or determined by the active code page
# on Windows.
# TODO: Match on the exec platform instead once Graal supports cross-compilation.
if is_linux:
env["LC_CTYPE"] = "C.UTF-8"

# assemble final inputs
inputs = depset(
direct_inputs,
Expand All @@ -113,7 +126,7 @@ def _graal_binary_implementation(ctx):
"executable": graal,
"inputs": inputs,
"mnemonic": "NativeImage",
"env": native_toolchain.env,
"env": env,
"execution_requirements": {k: "" for k in native_toolchain.execution_requirements},
"progress_message": "Native Image __target__ (__mode__) %{label}"
.replace("__mode__", _build_action_message(ctx))
Expand Down
Loading