Repository navigation
go: generate Go 1.27 modules, and build entrypoint modules with dagger/go's per-package build - #100
Conversation
A module whose go.mod requires Go 1.27 fails to generate: the context parameter of each function becomes an ordinary argument, and the generated bindings declare ctx twice. Signed-off-by: Erik Sipsma <[email protected]>
Go 1.27 writes export data version 5. golang.org/x/tools v0.45.0 reads at most version 4, so loading a Go 1.27 module failed to import every standard library package. The context parameter's type was invalid, the generator took it for an argument, and the generated bindings declared ctx twice. x/tools v0.50.0 is the first release that reads version 5. Signed-off-by: Erik Sipsma <[email protected]>
When the Go toolchain writes export data that golang.org/x/tools cannot decode, every standard library import fails to type-check. Generation went on with invalid types: the context parameter became an argument, and the error surfaced later as ctx redeclared in the generated bindings. Fail on the module's second load and name the import instead. Only standard library imports are checked. The loader type-checks with cgo while the build disables it, so a dependency that fails only with cgo is not an error in the module. Signed-off-by: Erik Sipsma <[email protected]>
The generated entrypoint built a module in golang:<version>-alpine and ran it in alpine:3.22, by tag, so every session that built or ran the module looked both up in the registry again: 70 to 90 ms each, one after the other, before the module's process started. The generator now resolves both as it generates, through the workspace's lock, and writes them by digest, which the engine reads from its own store. Signed-off-by: Erik Sipsma <[email protected]>
With daggerGo, the generated entrypoint's dispatch member is dagger/go's build of the module's process, by its package's directory in the module's context as a workspace, instead of a go build of its own on the module's Go cache volumes: the same per-package builds, cached the same way, as any dagger/go build. dagger/go is the entrypoint's own dependency, written into the module's manifest as manifest version 2 lists an entrypoint's dependencies, and into the schema the entrypoint is checked against. The module's Go bindings come from the schema without it, so the module compiles none of dagger/go's API. versions.toml pins the dagger/go a release builds modules with. Unset, daggerGo applies to new entrypoint modules and keeps what an existing one does. A manifest that lists an entrypoint's dependencies needs the engine release that reads them (daggerGoFloor), so a module targeting an older release builds with go build, and setting daggerGo there is refused with how to fix it. Signed-off-by: Erik Sipsma <[email protected]>
…t call The entrypoint builds the module's dispatch binary in a private member that only call reads, so the build runs inside the module's first call. A module calls the modules it uses through their clients, and each of those builds its own binary in its own first call, so a chain of modules builds them one after another. Declare a prebuild member that returns the same binary. An engine that knows the member evaluates it ahead of the module's first call; the call then finds the binary built, or joins the build in flight. An engine that doesn't ignores the member. Signed-off-by: Erik Sipsma <[email protected]>
Since new modules default to a pre-cut target on every path, the target the daggerGo floor is compared with is never empty. Signed-off-by: Erik Sipsma <[email protected]>
versions.toml pinned dagger/go at an earlier commit of the per-package build. 40b4d0d is that build as it stands, with module downloads shared across builds, plans keyed by the headers they read, Go's pack tool among the archive builds' results, and gobuild's entrypoint prebuild member, which an engine reads to build gobuild's binary ahead of its first call. Signed-off-by: Erik Sipsma <[email protected]>
A new module's go.mod now says go 1.27 instead of go 1.26.1. A module without a go.mod yet also generates and builds on Go 1.27, so its dispatcher's compiler matches the version its new go.mod declares. Existing modules are unchanged: generation still uses the Go version their go.mod declares, and the generators' minimum stays 1.26.1. The checks that build a newly generated module now do so on Go 1.27. Signed-off-by: Erik Sipsma <[email protected]>
The client generator and the starter renderer built on the generators' minimum, Go 1.26.1, while a new module now builds on Go 1.27, so initializing a module pulled two Go images. They now build on the default, and a new module pulls one. The minimum stays 1.26.1: a module keeps generating on the Go version its go.mod declares. Signed-off-by: Erik Sipsma <[email protected]>
8472f1a to
b80b387
Compare
Generating a module tidies while its bindings are bootstrap ones, which import no telemetry. That drops the requirements only the real bindings use, and the versions they held up. The later pin of otel-go at its minimum then resolves everything from the minimums, so regenerating lowers what the module chose: a module raised to otel-go's newer commit went back to v1.43.0, and otel/log from v0.19.0 to v0.17.0, on every pass. Remember what go.mod requires before the bootstrap, and require any version it lost again before the final tidy, which drops whatever the module doesn't use. Signed-off-by: Erik Sipsma <[email protected]>
The generated entrypoint names its images by digest, so the checks match the image's tag followed by its digest. Signed-off-by: Erik Sipsma <[email protected]>
d7cc3ec to
5bd64f4
Compare
Signed-off-by: Erik Sipsma <[email protected]>
The module generator's tests take about two minutes on an 8-core machine. In CI they ran past Go's default 10-minute limit for a test package twice, with nothing hung and no assertion failing: the nested engine starts with an empty Go module cache, and one go list alone took 2m29s. Signed-off-by: Erik Sipsma <[email protected]>
Released go-sdk v1.4.0 drops the requirements a module raised during its bootstrap tidy, so regenerating with it lowers otel-go and x/net below what sdk/go requires. go-sdk#100's head keeps them. The pin moves to #100's merged commit once it merges. Signed-off-by: Erik Sipsma <[email protected]>
Released go-sdk v1.4.0 drops the requirements a module raised during its bootstrap tidy, so regenerating with it lowers otel-go and x/net below what sdk/go requires. dagger/go-sdk#100's head keeps them. The pin moves to dagger/go-sdk#100's merged commit once it merges. Signed-off-by: Erik Sipsma <[email protected]>
Released go-sdk v1.4.0 drops the requirements a module raised during its bootstrap tidy, so regenerating with it lowers otel-go and x/net below what sdk/go requires. dagger/go-sdk#100's head keeps them. The pin moves to dagger/go-sdk#100's merged commit once it merges. Signed-off-by: Erik Sipsma <[email protected]>
A module that targets v1.0.0-beta.26 or later builds its process's binary for a platform its entrypoint's prebuild member is given, the engine's when none is, with the engine's own Go toolchain, and declares it as made for that platform (Directory.withPlatform). An engine of that platform then finds the binary an engine of another platform built, so an engine image can ship a module's binary for an image of another platform, as gobuild's. A module that targets an earlier release gets the entrypoint as before. Signed-off-by: Erik Sipsma <[email protected]>
targetVersion accepted releases up to defaultTarget, the release the SDK is built for, so no module could target the next engine release before the SDK's default moved to it. A new newestTarget, v1.0.0-beta.26, is the upper bound instead; defaultTarget stays v1.0.0-beta.24. A module that pins a release after defaultTarget generates on an engine of that release. With unified clients it still needs that release's dagger.io/dagger published, or replaced in go.mod for development, as before. Signed-off-by: Erik Sipsma <[email protected]>
daggerGo writes an entrypoint's dependencies into the module's manifest. v1.0.0-beta.25 shipped without reading them, so the first release that does is v1.0.0-beta.26: a module that targets v1.0.0-beta.25 builds with go build, and setting daggerGo there is refused. Signed-off-by: Erik Sipsma <[email protected]>
The bump helpers decode versions.toml into their own type and write it back, so a field they don't declare is dropped, and the SDK then fails to read the file. They now declare newestTarget, daggerGo and daggerGoFloor. Signed-off-by: Erik Sipsma <[email protected]>
The SDK's helpers and new modules build on golang:1.27-alpine, but neither lock pinned it, so go-sdk's own runs resolved the tag from the registry each time. Pin it in the workspace lock and in the nested lock that older engines read, as the helpers' previous image was. Signed-off-by: Erik Sipsma <[email protected]>
Every generated entrypoint declares the image its calls run the module's process in as a runtimeImage member, for the engine's platform or one it is given, and its calls start from it. The engine reads it there (Module._runtimeImage), such as to ship it in the entries of an engine image of any platform, instead of from the entrypoint's text. The member uses nothing newer than the entrypoint itself, so a module of any target declares it, and an engine that doesn't read it ignores it. Signed-off-by: Erik Sipsma <[email protected]>
The generated entrypoint named the Go image with the address the engine returned from imageRef. Released engines identify a resolved image by its digest and platform alone, so within a session imageRef can report another tag that resolved to the same image. In dagger/go, whose own checks use golang:1.27.3-alpine, generation wrote golang:1.27.3-alpine or golang:1.27-alpine for one source, depending on which a run resolved first, and its staleness check passed or failed with it. The generator now writes the tag it asked for with the digest the engine resolved, so the same source generates the same entrypoint on any engine. Signed-off-by: Erik Sipsma <[email protected]>
The e2e checks run in one session in CI. When another check resolved golang:1.27-alpine first, the image-tag check could not resolve another tag of it first, and its setup failed with the fix in place. The check now generates a module that declares Go 1.27.0, an image only it uses. Signed-off-by: Erik Sipsma <[email protected]>
An engine can pre-warm the builds a new module needs: the packages outside the standard library that its generated dispatcher, module client and bindings import, with dagger.io/dagger at defaultTarget. Until now the engine kept its own copy of that list, which nothing compared with what this SDK generates. generated-imports.txt is that list, beside versions.toml, and the e2e check generatedImportsCheck generates a new module and fails when its generated code imports anything else, or stops importing a listed package. Signed-off-by: Erik Sipsma <[email protected]>
… collection dagger/go's GoPlatforms is a collection, and a client reads one of its entries with get, as the entrypoint already reads a package from GoPackages: the entrypoint of a module that targets v1.0.0-beta.26 called GoPlatforms.platform, the name dagger/go gives its get function, and the generated module failed go-sdk's entrypoint contract check: field "platform" not found in Dagger.GoPlatforms. Signed-off-by: Erik Sipsma <[email protected]>
A module that targets v1.0.0-beta.26 builds with dagger/go, and its generated entrypoint is checked against dagger/go's schema only during generation on an engine of that release. The template's unit test matched the entrypoint's text, so a field dagger/go doesn't have passed it. TargetChecks.daggerGoEngineCheck generates such a module, with the dagger.io/dagger replace generation asks for while that release is unpublished, and calls it. It is not a check, and CI does not run it: go-sdk's CI runs the e2e checks on engines of v1.0.0-beta.18, which can't load a module that lists an entrypoint's dependencies. It is run by hand, with an engine built from dagger/dagger's change that adds them: dagger -m .dagger/modules/e2e call target dagger-go-engine-check --ws . Once a Dagger release carries that change, engine-e2e's development engine can move to it and this becomes an ordinary @check. Signed-off-by: Erik Sipsma <[email protected]>
dagger/go bc3a611 builds a module's binary for the platform it is asked for, on any machine, which the entrypoint of a module that targets v1.0.0-beta.26 relies on. Dagger's built-in Go SDK pins the same commit, and the engine image's build requires the two to match. Only a module that targets v1.0.0-beta.26 or later builds with dagger/go, so modules on the default target are unchanged. Signed-off-by: Erik Sipsma <[email protected]>
From v1.0.0-beta.26, the engine's view names enum members by their values, FunctionCachePolicy.PER_SESSION rather than PerSession, and no view has both. The entrypoint of a module that targets that release is served at that view, so an entrypoint with a cached function failed the contract check: field "PerSession" not found in Dagger.FunctionCachePolicy. The entrypoint now names the members as its target's view does. TargetChecks.daggerGoEngineCheck's module gains a session-cached function. It runs by hand on an engine of that release, as before; the unit test runs in CI. Signed-off-by: Erik Sipsma <[email protected]>
… too Generation writes the files a module's build reads outside its directory, which sources already returns, into dagger-module.toml as include, relative to the module directory, and include = [] for a module that reads nothing outside. The list excludes test files outside the module and keeps the module's own, as sources does: include = ["../lib/go.mod", "../lib/greet/*.go", ..., "!../**/*_test.go", "**/*_test.go"] An engine that reads a version 2 manifest's include loads those files with the module and does not run sources, so a module load evaluates no Dang code for them. A released engine ignores include and runs sources, as before. The entrypoint keeps its sources member, so the module loads on both. Signed-off-by: Erik Sipsma <[email protected]>
main moves defaultTarget to v1.0.0-beta.25. This branch had made newestTarget, v1.0.0-beta.26, the highest release a scope can pin, so the two meet in versions.toml and in the target tests: - versions.toml takes defaultTarget = "v1.0.0-beta.25" and keeps newestTarget, daggerGo and daggerGoFloor; - the refusal tests keep newestTarget as the bound, so v1.0.0-beta.27 is refused and v1.0.0-beta.26 resolves; - the default cases resolve to v1.0.0-beta.25, and an explicit v1.0.0-beta.24 still resolves. Signed-off-by: Erik Sipsma <[email protected]>
dagger/go 917e87b makes fewer requests while building a module. Dagger's built-in Go SDK pins the same commit, and the engine image's build requires the two to match. Only a module that targets v1.0.0-beta.26 or later builds with dagger/go, so modules on the default target are unchanged. Signed-off-by: Erik Sipsma <[email protected]>
…eturns A module's bindings, outside dagger.io/dagger's core package, built each core object a list field returned, a nullable object field returned or an ID field named from its ID with WithGraphQLQuery, which leaves the ID unset and asks the engine for it again on every use: one request per object the module passes on, though the request that returned the list had the IDs. Bindings that target v1.0.0-beta.26 or later, whose library has core.Loaded, build them with it and keep the ID. A default-target module, which pins the released library, keeps the old code. Signed-off-by: Erik Sipsma <[email protected]>
dagger/go ebb1e6b makes fewer requests while building a module and fixes a golden file's title. Dagger's built-in Go SDK pins the same commit, and the engine image's build requires the two to match. Only a module that targets v1.0.0-beta.26 or later builds with dagger/go, so modules on the default target are unchanged. Signed-off-by: Erik Sipsma <[email protected]>
dagger/go ce511d9 walks a module's dependencies in one cached call. Dagger's built-in Go SDK pins the same commit, and the engine image's build requires the two to match. Only a module that targets v1.0.0-beta.26 or later builds with dagger/go, so modules on the default target are unchanged. Signed-off-by: Erik Sipsma <[email protected]>
dagger/go f8c4b0b discovers a module's packages in one call. Dagger's built-in Go SDK pins the same commit, and the engine image's build requires the two to match. Only a module that targets v1.0.0-beta.26 or later builds with dagger/go, so modules on the default target are unchanged. Signed-off-by: Erik Sipsma <[email protected]>
| # flight (not yet released). | ||
| newestTarget = "v1.0.0-beta.26" |
There was a problem hiding this comment.
@sipsma : I wonder if instead we shouldn't simply remove the ceiling mechanism. With this value it means we only allow for a single next version, and maybe we should just allow everything.
If a user selects a version that doesn't exist, build will fail, and maybe that's enough.
There was a problem hiding this comment.
(my issue is not the value itself, it's the need to update and maintain it)
There was a problem hiding this comment.
Agreed on the maintenance point: newestTarget only ever means "the release after defaultTarget", so it shouldn't be a field anyone has to remember to bump. I'm dropping it and computing the ceiling from defaultTarget instead. defaultTarget already moves every release, so there's nothing extra to maintain.
I do want to keep the guard itself, though, rather than allow any targetVersion. The generated code isn't purely driven by the engine's schema: the templates are written against a known API view per target, so a module pinned to a release this SDK has never seen can generate code that is subtly wrong, not just fail to find a version. We hit that twice this week on beta.26 targets (a template bug that only showed on a dev engine, and an enum member the beta.26 view no longer serves). With the guard, the user gets an immediate refusal that names the allowed range and says to install the SDK release built for that target; without it, they get a late compile failure at best, or a module that builds and misbehaves.
So: the allowed targets stay sourcesFloor up to the release after defaultTarget, the refusal messages and the e2e check stay, and the field goes. Pushing that shortly.
versions.toml named the newest release a scope can pin, newestTarget, which had to change with every release. The newest is the release after defaultTarget, the one in flight, so it is now derived: the next number of a prerelease's last identifier (v1.0.0-beta.25 gives v1.0.0-beta.26), or the next patch of a final release. The guard stays. The generator's templates are written against the API view of each release it knows, so a target it has never seen can get code for another view: this week two templates generated broken entrypoints for v1.0.0-beta.26, a platform read and a renamed enum member, before the SDK learned that release. A refusal that names the range and says to install the SDK release built for the target is better than a late compile failure or a module that misbehaves. Signed-off-by: Erik Sipsma <[email protected]>
main's dagger.lock gained pins next to this branch's golang:1.27-alpine pin; both are kept. Signed-off-by: Erik Sipsma <[email protected]>
… workspace Generation writes into the user's workspace through mergeGenerated, which applies only the generated files, so a file .gitignore excludes is never uploaded. Two manifest writes this branch added before that change still wrote with Workspace.withDirectory, which uploads the whole workspace: the manifest's include list, and the daggerGo dependency tables. Git merged them cleanly because the conflict was in meaning, not in lines. Both now go through mergeGenerated. The ignored-file checks now cover the include write, which runs for every entrypoint module. The dependency-table write runs only for modules that target v1.0.0-beta.26, which CI doesn't generate, so it was checked by hand on an engine of that release with TargetChecks.daggerGoEngineCheck. Signed-off-by: Erik Sipsma <[email protected]>
TargetChecks.daggerGoEngineCheck replaces the unpublished v1.0.0-beta.26 library with the published one. Since unified bindings for that release keep the IDs a request returns with core.Loaded, which the published library lacks, the module no longer compiled. Embedded bindings don't use it and still build with dagger/go, which is what the check covers. Signed-off-by: Erik Sipsma <[email protected]>
go-sdk moves from 916c9a9 on its sipsma/collections-line branch to d43dbee on main, the merge of dagger/go-sdk#100, which lets go-sdk generate a module on Go 1.27. Regenerating picks up what go-sdk main gained since: the module targets v1.0.0-beta.25 by default, so the Go library and the entrypoint's Dagger import name it; the manifest lists the files the build reads outside the module (none); and the entrypoint names its runtime image in a function of its own. The entrypoint still needs Dagger v1.0.0-beta.18 or later. Signed-off-by: Erik Sipsma <[email protected]>
Go modules with a Dang entrypoint now generate on Go 1.27, and new modules default to it. This PR also carries go-sdk's side of building a module's process with dagger/go's per-package build.
Go 1.27
Today a module whose
go.modsaysgo 1.27fails to generate: every generated method gets a secondctxparameter, and the bindings don't compile (ctx redeclared in this block). Go 1.27 writes export data thatgolang.org/x/toolsv0.45.0 can't read, so the generator loses the type ofcontext.Contextand treatsctxas an ordinary argument.golang.org/x/toolsmoves to v0.50.0, the first release that reads Go 1.27's export data.ctx redeclared.go 1.27, and the SDK's own helpers build on Go 1.27, so a new module pulls one Go image.go.moddeclares, and these Go 1.27 changes leave the output for modules on Go 1.26 byte-identical to main.Go images pulled on a machine that has none of them:
go 1.26.1go 1.27Each image is about 75 MB compressed, and 1.27 and 1.26.1 share no layers. Engines v1.0.0-beta.18 to beta.23 ship Go 1.26, so on them an existing
go 1.26.1module pulls Go 1.27 as well.Per-package build
daggerGo. An entrypoint module's process can be built by dagger/go's per-package build, cached like any dagger/go build, instead of a plaingo build. It is the default for new entrypoint modules that target an engine fromdaggerGoFlooron (v1.0.0-beta.26, not yet released). Older targets keepgo build, and settingdaggerGofor them is refused.versions.tomlpins dagger/go at the commit Dagger's built-in Go SDK pins, which the engine image build requires to match.prebuildmember, so an engine that knows it can build modules before their first call, in parallel, instead of one after another. Older engines ignore it.Targeting the release in flight, and image handling
targetVersionaccepts releases up to the one after the default target, the release in flight (v1.0.0-beta.26, after the v1.0.0-beta.25 default from feat(go): target v1.0.0-beta.25 #99, merged into this branch); the bound is derived, so it moves with the default; a unified-clients scope still needs that release'sdagger.io/daggerpublished, or replaced for development.daggerGostarts at v1.0.0-beta.26. v1.0.0-beta.25 shipped without reading an entrypoint's dependencies, sodaggerGoFloormoves to beta.26.prebuildmember is given, declared withDirectory.withPlatform, so an engine image can ship a module's binary for another platform..platforms.get(…), as a client reads any dagger/go collection entry.TargetChecks.daggerGoEngineCheckgenerates and runs such a module; it isn't a CI check, because only an engine with Freshdagger check -lof dagger/dagger in under 5 s: per-package Go builds, a pre-warmed engine cache, and faster module loading and check planning dagger#15080 can load the module, so it is run by hand until a release carries that change.FunctionCachePolicy's membersNEVER,PER_SESSIONandDEFAULT, and no longerNever,PerSessionandDefault; an entrypoint that targets beta.26 or later writes the new names, and earlier targets keep the old ones.runtimeImage(platform:)member that its calls start from, so the engine reads the image instead of parsing the entrypoint's text.golang:1.27-alpine@sha256:…); before, the tag came from whichever tag of the same image the engine had resolved first.dagger-module.tomlasinclude(include = []when there are none), as well as returning them from the entrypoint'ssources. An engine that readsincludeloads them without runningsources; a released engine ignores it and runssourcesas before.node(id)request; earlier targets generate the same code as before.generated-imports.txtlists the external packages a new module's generated code imports, for pre-warming them; an e2e check fails when the generator's output differs.golang:1.27-alpine, and the version-bump helpers keep every field ofversions.toml.Existing modules change once when regenerated: the entrypoint gains the
runtimeImagemember, its image references take the shorter form, and the manifest gainsinclude.Release order
daggerGoneeds an engine that reads an entrypoint's dependencies. This go-sdk is released after that engine release, withdaggerGoFloorset to it.Tests
go127Check: a Go 1.27 module generates andctxstays a context parameter. It fails on main.contextcan't be compiled.go 1.27default and for images by digest.go 1.27and the rest byte-identical to main, and a newgo 1.27module generates and runs.