Skip to content

feat(plugin-go): support target-ref Go toolchain (host bin, nix)#113

Open
raphaelvigee wants to merge 1 commit into
masterfrom
feat/plugin-go-target-toolchain
Open

feat(plugin-go): support target-ref Go toolchain (host bin, nix)#113
raphaelvigee wants to merge 1 commit into
masterfrom
feat/plugin-go-target-toolchain

Conversation

@raphaelvigee

Copy link
Copy Markdown
Member

What

gotool now accepts a third form besides "host" and a pinned version: a target address starting with // that produces the go toolchain.

mode gotool source
self-installed "1.26.4" hermetic go.dev download (unchanged)
host bin "//@heph/bin:go" hostbin provider
nix "//some/pkg:go" nix driver

How

Classify gotool via toolchain::classifyToolchain::{Host, Target(&str), Hermetic(&str)}.

In target mode the build deps that address in the gosdk group (read-only staged like the hermetic SDK) and passes the host module/cache env through (thirdparty modcache + wrapper PATH/HOME). The staged path isn't known ahead of time, so go/GOROOT are resolved from the staged output at runtime, auto-detecting a full GOROOT tree (a directory whose bin/go is used) vs. a bare go binary:

  • sh/exec targets (go_goroot_prelude): prelude reads $SRC_GOSDK; dir → $GOSDK/bin/go, file → the go binary; then GOROOT="$("$GO" env GOROOT)".
  • golist driver (in-process, no shell): finds the dep|gosdk|* ManagedRunInput, walks its artifact for go-named entries, pick_go_binary prefers .../bin/go over a bare wrapper, then go_env_goroot queries go env GOROOT (renamed from host_goroot, now shared by host + target).

Contract: the target must expose exactly one output — a go binary file or a GOROOT directory containing bin/go.

Files

  • toolchain.rsToolchain enum, classify, is_target_ref + module docs.
  • addr_util.rsgo_sdk_dep / go_host_runtime_pass_env / go_goroot_prelude handle all three kinds.
  • driver_golist.rs — Target branch, resolve_target_go, pick_go_binary, host_gorootgo_env_goroot, PATH passthrough for non-hermetic.
  • provider.rsgotool docs + error message.

Tests

279 plugin-go tests pass; production clippy clean. New unit tests cover classify, per-kind dep wiring, target env + read-only staging, prelude auto-detect, and pick_go_binary preference. No e2e (needs network + real nix/host go); coverage targets the pure logic.

Caveat

Nix wrappers reference /nix/store; the go build sandbox must be allowed to read /nix/store at runtime. That's a sandbox-exposure concern outside this plugin's wiring.

🤖 Generated with Claude Code

`gotool` now accepts a third form besides "host" and a pinned version: a
target address starting with `//` that produces the `go` toolchain — e.g.
`//@heph/bin:go` (host `go` via the hostbin provider) or `//some/pkg:go`
(a `go` built by the nix driver).

Classify `gotool` via `toolchain::classify` -> Toolchain::{Host, Target,
Hermetic}. In target mode the build deps that address in the `gosdk` group
(read-only staged like the hermetic SDK) and passes the host module/cache
env through. The staged path isn't known ahead of time, so `go`/`GOROOT`
are resolved from the staged output at runtime, auto-detecting a full
GOROOT tree (a directory whose `bin/go` is used) vs. a bare `go` binary:
- sh/exec targets: prelude reads `$SRC_GOSDK` and derives GOROOT from
  `go env GOROOT`.
- golist driver (in-process): finds the `dep|gosdk|*` input, walks its
  artifact for `go`-named entries, prefers `.../bin/go` over a wrapper,
  then queries `go env GOROOT`.

Contract: the target must expose exactly one output — a `go` binary file
or a GOROOT directory containing `bin/go`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant