Skip to content

feat(go): discover external compilation inputs from workspaces - #64

Merged
grouville merged 8 commits into
go-mod-include-engine-formfrom
feat/workspace-compilation-inputs
Oct 14, 2026
Merged

grouville merged 8 commits into
go-mod-include-engine-formfrom
feat/workspace-compilation-inputs

Conversation

@grouville

@grouville grouville commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

This builds on #63 and keeps Yves' automatic Go file discovery.

Workspace compilation requires Dagger beta.17 or later: the SDK uses currentModule.sourceSubpath for calls between sibling modules. Its minimum-version check now runs beta.17. The existing beta.16 entrypoint and beta.12 runtime checks stay in place.

The confusion came from mixing two things:

  1. Which files the Go compiler needs.
  2. When Dagger can reuse a function result.

For a module that compiles with files outside its own directory, every exported constructor and function must take a required ws *dagger.Workspace.

Concretely:

  • When the SDK generates the module, it reports an error if an exported constructor or function is missing that required argument.
  • When another module calls it, that module passes its workspace: goClient.New(ws).Build(ws).
  • For a direct CLI call, the CLI supplies the workspace automatically.

The workspace is passed before Dagger checks the function cache. With a fresh local workspace session, the call runs again, so the SDK can read the current inputs. It follows Go imports, local replace targets and go:embed, then imports the external files the compiler needs.

Having ws only on the constructor is not enough. The constructor could return the same object, and another function without ws could still return an old cached result. Each affected function needs the workspace too, even if its Go body does not use it.

Rerunning the function does not mean rebuilding everything. Go compilation still caches by file content:

  • A required file changed: build with its new contents.
  • Required files stayed the same: reuse the previous build.
  • An unrelated file changed: the existing build can still be reused.

So, under this workspace contract, we do not need the engine's resource hook to invalidate these calls. Module authors filter the files their own pipelines need; the Go SDK handles compiler inputs. Collection lookups carry the workspace in their receiver and keep their key-only API.

The same explanation and a small Go example are in the SDK help and caching guide.

Self-contained modules still work without ws: TestGenerateFreshEmbeddedModuleWithoutLocalSDK generates and executes Echo(value string) without it. The external-input fixture separately verifies that omitting the required workspace is rejected.

Checked on the unmodified beta.17 engine and an engine rebuilt from the standalone resource revert: changing an external embedded file changes the result in a fresh session, without regeneration. The timestamp check confirms that fresh workspace calls rerun the function. Discovery, entrypoint and module-codegen tests also pass. The CLI port exposed a missing import alias for private dependency-client fields; this PR fixes their generated serialization and tests regeneration with an aliased private field.

The integration checks and module ports also caught issues in starter generation, imports, and private dependency clients. This PR fixes them and adds regressions, including a sibling call that sees a changed external embed without regeneration. Compiler helpers can be upgraded while preserving author edits, and their generated Go files carry the generated-code header. Embed discovery also propagates file-read errors.

The engine rollback (dagger#14661) and module ports (dagger#14664) are separate PRs. This PR targets Yves' go-mod-include-engine-form branch and does not publish a tag.

Rediscover imported packages, local replacements and embedded files for
workspace-dependent entrypoint calls. Require a workspace on affected
constructors and functions so a cached result cannot skip discovery.

Adapt the local package scanner from Yves Brissaud’s PR #63.

Co-authored-by: Yves Brissaud <[email protected]>
Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the feat/workspace-compilation-inputs branch from 7541bd4 to 0122ad6 Compare October 13, 2026 22:45
@grouville
grouville changed the base branch from main to go-mod-include-engine-form October 13, 2026 22:45
@grouville
grouville merged commit b64b413 into go-mod-include-engine-form Oct 14, 2026
9 checks passed
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