Skip to content

init: export generated files and install the module in one call#6

Open
eunomie wants to merge 4 commits into
mainfrom
init-auto-export-install
Open

init: export generated files and install the module in one call#6
eunomie wants to merge 4 commits into
mainfrom
init-auto-export-install

Conversation

@eunomie

@eunomie eunomie commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

Make a new SDK module usable from a single init call. Today, creating a module
with e.g. dagger call go-sdk init requires two manual follow-ups before it can
be used:

dagger call go-sdk init   # writes main.* + dagger.json
dagger generate           # generate the module's SDK bindings
dagger install            # register the module in the workspace

This folds generate and install into the single Changeset that init
already returns, so one call leaves a ready-to-run module. The work lives in the
shared polyfill, so every SDK inherits it once bumped (the per-SDK init opts
in with two lines — see the companion go-sdk change).

What changed

  • polyfill — two reusable fork primitives:
    • PolyfillWorkspaceFork.withGeneratedModule(modulePath) generates a module
      that exists only in the fork's staged state (not on the host yet) and
      overlays the generated files. Codegen can't run from inside a Dang module
      function, so it routes through the workspace-module-generate helper,
      extended with a --staged-dir-id mode that loads the staged directory by ID
      and runs GeneratedContextChangeset.
    • PolyfillWorkspaceFork.withInstalledModule(modulePath, name) registers the
      module in the workspace dagger.toml under [modules.<name>], mirroring
      dagger mod install. Re-installing the same name is a no-op.
  • init-template — the SDK init skeleton wires both primitives (generate
    always; self-install skipped for a root-level module at path .).
  • polyfill-e2e — checks for staged generate, install, and install
    idempotency.

No API changes: init keeps its signature.

Verification

  • End-to-end in a scratch hello-dagger-style project: a single
    dagger call <sdk> init --name mybuild -y produced the module +
    dagger.gen.go/go.mod/internal/... + a dagger.toml entry, and
    dagger call mybuild ... worked immediately — no separate generate/install.
  • Full dagger check -m .dagger/modules/polyfill-e2e (11 checks, incl. 3 new)
    passes on engine v1.0.0-beta.3.
  • Helper go test / go vet pass.

Follow-ups

  • Companion go-sdk change wires its init to these primitives.
  • The other SDKs (python / typescript / java) need the same two-line init
    wiring once this polyfill is bumped.

eunomie added 3 commits June 9, 2026 13:03
Add reusable fork primitives so an SDK 'init' can stage a new module,
generate it, and register it in the workspace in a single returned
Changeset:

- PolyfillWorkspaceFork.withGeneratedModule generates a module that only
  exists in the fork's staged 'after' state (it is not on the host yet)
  and overlays the generated files. Codegen cannot run from inside a
  module function, so it routes through the workspace-module-generate
  helper, extended with a --staged-dir-id mode that loads the staged
  directory by ID and runs GeneratedContextChangeset.
- PolyfillWorkspaceFork.withInstalledModule registers the module in the
  workspace dagger.toml under [modules.<name>], mirroring
  'dagger mod install'. Re-installing the same name is a no-op.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Add checks for the new fork primitives: generating a module that only
exists in the fork adds its generated files, installing it records a
[modules.<name>] entry in dagger.toml with a workspace-relative source,
and re-installing the same module is a no-op.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Wire the SDK init skeleton to the new polyfill primitives so a scaffolded
SDK's 'init' leaves a ready-to-run module: it stages the module, generates
it, and installs it into the workspace in one Changeset, with no follow-up
generate or install step.

Signed-off-by: Yves Brissaud <yves@dagger.io>
@eunomie eunomie force-pushed the init-auto-export-install branch from b5ca544 to c6ebcbd Compare June 9, 2026 11:04
The four PolyfillGeneration functions each rebuilt the same golang:1.26-alpine
container (go caches, mount + build the workspace-module-generate helper) and
three repeated the same --cwd/--local flag construction. Extract both into a
shared 'helper' container field and a 'locationFlags' helper, leaving each
function with just its env var and exec.

Signed-off-by: Yves Brissaud <yves@dagger.io>
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