Problem
nogo_actual is built for a different exec platform than the one RunNogo executes on, causing an exec format error at build time.
Root cause
go_context_data declares the nogo attribute with cfg = "exec", which resolves the exec platform from --extra_execution_platforms ordering. The Go toolchain's RunNogo action independently resolves its exec platform via exec_compatible_with on the registered toolchain. When these two disagree, the nogo_actual binary is unusable on the exec platform where RunNogo actually runs.
Reproduction
- macOS host (darwin/arm64)
--extra_execution_platforms=//:linux_amd64,//:default_host_platform
- The darwin Go SDK toolchain has
exec_compatible_with = [darwin, arm64], so RunNogo runs on darwin
cfg = "exec" on the nogo attribute picks linux_amd64 (first in the list), so nogo_actual is a linux/amd64 binary
Error
nogo: fork/exec .../nogo_actual: exec format error
# Execution platform: //:default_host_platform
Expected behaviour
nogo_actual should be built for the same exec platform that RunNogo will execute on.
Possible fix
When applying this patch it seems to work. Would this be the right solution?
diff --git go/private/context.bzl go/private/context.bzl
index 64758f8..06c361d 100644
--- go/private/context.bzl
+++ go/private/context.bzl
@@ -46,6 +46,7 @@ load(
)
load(
"//go/private/rules:transition.bzl",
+ "go_tool_transition",
"non_request_nogo_transition",
"request_nogo_transition",
)
@@ -693,7 +694,7 @@ def _go_context_data_impl(ctx):
providers = [
GoContextInfo(
coverdata = ctx.attr.coverdata[0][GoArchive],
- nogo = ctx.attr.nogo[DefaultInfo].files_to_run,
+ nogo = ctx.attr.nogo[0][DefaultInfo].files_to_run,
),
ctx.attr.stdlib[GoStdLib],
ctx.attr.go_config[GoConfigInfo],
@@ -717,7 +718,7 @@ go_context_data = rule(
),
"nogo": attr.label(
mandatory = True,
- cfg = "exec",
+ cfg = go_tool_transition,
),
"stdlib": attr.label(
mandatory = True,
Problem
nogo_actual is built for a different exec platform than the one RunNogo executes on, causing an exec format error at build time.
Root cause
go_context_datadeclares thenogoattribute withcfg = "exec", which resolves the exec platform from--extra_execution_platformsordering. The Go toolchain'sRunNogoaction independently resolves its exec platform viaexec_compatible_withon the registered toolchain. When these two disagree, thenogo_actualbinary is unusable on the exec platform whereRunNogoactually runs.Reproduction
--extra_execution_platforms=//:linux_amd64,//:default_host_platformexec_compatible_with = [darwin, arm64], soRunNogoruns on darwincfg = "exec"on thenogoattribute pickslinux_amd64(first in the list), sonogo_actualis alinux/amd64binaryError
Expected behaviour
nogo_actualshould be built for the same exec platform thatRunNogowill execute on.Possible fix
When applying this patch it seems to work. Would this be the right solution?