go_workspace
Native Go module seed.
Description#
go_workspace asks the Go command which packages a module contains and emits
ordinary Go targets for them. Every directory with a go.mod gets its own
seed, so a repository with several modules is discovered without
configuration. Like the Go command, discovery skips modules under directories
whose names begin with _ or ., such as _examples. Go stays authoritative
for build constraints, file selection, and imports. Struo reads native module
requirements and runs Go's minimal version selection in its graph. Cacheable
actions acquire and authenticate individual module manifests as selection
converges. go.sum authenticates those bytes; it is not a selected-version
lockfile.
Once versions settle, offline readonly go list actions discover each
consumer's package closure with the host's default build tags and cgo setting.
They acquire sources only for modules that could provide that consumer's
imports. A reported module version that disagrees with the settled graph
fails discovery. Vendored workspaces retain native Go discovery and consistency
checks.
The seed publishes only its ready target and generated-name selectors before selection. Actual package and test names are established by the authenticated post-selection package probe, never by a modular native catalog before MVS.
When native Go selects a go.work, all its use modules participate in one
version selection. Workspace replacements take precedence over member
replacements. Imported member sources, every member manifest, and local
replacement manifests that affect the module graph become declared inputs,
even when no package from a replacement is imported. Fetches authenticate
against member go.sum files together with go.work.sum. Set GOWORK=off
to build modules independently.
Each first-party package becomes a go_library, or a go_binary when it is a
main package. Each package with tests also becomes a go_test that compiles
its internal and external test files together, as go test does, and runs
from the package directory so tests find testdata and other relative paths.
Every external module that provides a package becomes a go_module:
- A vendored module is read from
vendorwhen native automatic vendoring applies: the controlling Go version is at least 1.14 and the first-line workspace annotation matches the current mode. The directory is besidego.workin workspace mode orgo.modotherwise. Native Go checks consistency with the manifests. Older modules can also use vendor packages without module attribution; their files remain declared build inputs. - A module replaced by a local directory, such as
replace example.com/m => ../, is read from that directory, wherever it lies in the workspace. - Any other module has its own cacheable fetch action. Native
go mod downloadverifies its source and manifest against the selectedh1:entries ingo.sum, using an isolated module cache rather than trusting the host's extracted sources. Missing supported checksums fail with a native repair. Package compilation depends only on the modules it imports, directly or transitively, rather than every external module in the repository.
Compilation reads a consumer-scoped native-layout cache assembled from verified
module trees and the settled module metadata, with GOPROXY=off. Neither
metadata acquisition nor source acquisition trusts the host module cache.
Fetches honor effective Go proxy,
private-module, checksum-database and VCS settings, including values saved by
go env -w, and the host's HTTP proxy settings.
On a fresh clone, metadata actions can access the network, including for
requirements that no package imports. All relevant
requirements must settle before compilation because a late requirement can
upgrade an earlier choice. After that convergence, a package can compile
while an unrelated package's sources are still downloading. Builds do not
update go.mod, go.sum, go.work, or go.work.sum. Missing supported
checksums or requirements that need native root updates fail with a repair
command rather than silently choosing a different graph.
All Go actions in a workspace share one Go build cache under .struo. Go's
cache is content-addressed and never changes what a build produces, so the
standard library compiles once instead of once per package. Go's cache does not
track C headers that cgo flags include from outside a package directory, such
as -I${SRCDIR}/include, so Struo declares those headers as inputs and adds
their digest to the cgo flags.
A test's run inputs include every file in its package directory, except
dotfiles, and under its testdata directory, since go test runs there and
tests read such files by relative path. Changing one reruns the test rather
than replaying a cached result.
Test selection#
A changed Go file, embedded file, or cgo header selects the tests of its
package and of every package that imports it, directly or through other
packages. go.mod and go.sum select every test in the module and in modules
that replace it with a local directory. Workspace manifests and checksum
files select the workspace members' tests, since they can change shared
version selection. A file under a package's testdata
selects that package's tests. Any other file selects a test only when the
test's Go files name it, such as "expected.txt" or
path.Join(dir, "/../fixtures"). A
changed README or documentation file selects nothing. Files under a nested
go.mod or struo.toml belong to that package and are selected by its own
targets.
Attributes#
| Attribute | Type | Required | Default | Description |
|---|---|---|---|---|
go | string | no | go on the search path | Go command used for discovery |
resolver_inputs | list<string> | no | srcs | Text inputs available while deriving the graph |
Providers#
The target emits go_workspace.
Capabilities#
| Capability | Output groups |
|---|---|
build | none |
Direct Use#
Inspect the automatically derived graph, then build and test it:
struo query targets
struo build go
struo testNo struo.toml is required. To configure the resolver explicitly, author a
target equivalent to:
[[target]]
name = "go"
kind = "go_workspace"
srcs = ["go.mod"]
[target.attrs]
resolver_inputs = ["go.mod", "go.sum", "go.work", "go.work.sum", "vendor/modules.txt", "**/*.go"]Limitations#
- Graph-owned package discovery is experimental. A bounded Linux native-installation
bootstrap supports read-only graph and affected-test replay with empty
GODEBUGand a canonical workspace path. An unsetGOROOTselects the canonical SDK containing the selected native driver; an explicit root must match that SDK. Default cgo discovery requires a nonempty processCC, or normalized absolutePATHentries with a regular executable for Go's compiled default compiler. A missing compiler uses uncached discovery rather than recording a reusable miss. Private telemetry configuration disables bootstrap counter writes without changing the user's telemetry mode. Struo records configuration contents and absence, installation identity, compiler availability, and workspace discovery. Other configurations retain uncached probes and reject replay, even after building or testing. An incomplete or stale graph fails explicitly instead of returning a partial test set. Executable access is rechecked before cached discovery and during replay. General configuration replay remains incomplete. - Bootstrap configuration probes use
GOTOOLCHAIN=localand do not choose or download another Go toolchain. An installedGOROOTcontaining its native Go driver is required. User and installation configuration, compiler lookup, and workspace discovery remain observed inputs. This boundary assumes a trusted native Go driver; installation path checks do not authenticate the driver or establish a closed contract for wrappers. Probes override saved build flags and disable FIPS snapshot setup. Cached probes additionally disable native module/workspace discovery; Struo locates the workspace through observed file checks instead. Conflicting saved and processGOROOTsettings and noncanonical workspace paths use the uncached path. Configuration parsing preserves native precedence: process values override saved settings, duplicate user entries are last-wins, and duplicate installation entries are first-wins. Empty saved values still shadow installation settings. Cached download-policy queries read a private copy of validated settings, including explicit empty policy keys, so concurrent edits cannot inject proxy credentials into persisted query output. Newline-bearing policy values use uncached discovery. Native Go still supplies policy defaults. Action identity includes the selected driver bytes and installed SDK contents, including standard-library sources and compiler tools. Top-level SDK links resolve to their observed backing trees; nested directory links escaping those trees fail closed. Implicit SDK aliases and arbitrary wrapper dependencies are not reproduced. - Native module and workspace requirement/checksum proposals are available through
go_module_resolution. Missing checksums use native exact-version authentication. Publication is a separate explicitstruo edit sourcesoperation with original-input guards. This conservative reconciliation is notgo mod tidy,go get, orgo work sync. It does not infer requirements or directness from imports, or prune unused requirements/checksums. Standalone previews can request exact upgrades of declared requirements throughupgrade_versions; version queries, new-module discovery, downgrades and workspace requests remain unsupported. Workspace proposals add authenticated checksums for each updated member's selected dependency closure to its owngo.sum, preserving historical records. Newly acquired sums are also recorded ingo.work.sum. Requirement closures come from declarations, not package and test imports, so this does not provide full native workspace synchronization. - Builds pass
-trimpath, so compiled outputs do not contain the checkout path and action keys match across clones. Tests that expect absolute source paths fromruntime.Caller, orsrc/in standard library frames, behave as they do undergo test -trimpath. - Tests run offline. A test that runs
go mod downloador reaches the network fails. - Discovery uses the host's default build tags. Files behind other tags are not part of the graph.
- Workspace files and local modules must resolve inside the Struo workspace,
including through symlinks. An explicit
GOWORKmust use a normalized absolute path without..segments. Absolute local replacements and workspace member paths are accepted inside that boundary without rewriting the native manifests. Relocating absolute native paths to a different checkout or remote worker is not supported. - Proxy and routing values currently participate in fetch action keys. Changing a mirror can miss the cache. Credential-safe forwarding of private configuration and host authentication files is not yet supported. Credential-bearing proxy URLs fail with a redacted diagnostic before the fetch action is declared. Host TLS certificate paths are not portable to remote execution workers.
Sources#
go listdefines packages, files, imports, and providing modules.go mod graphdefines the module requirement graph.