Repository navigation
Design question: how should Hybrid hook into an existing go.mod project? (toolexec vs go:generate vs make-step) #3
Replies: 1 comment
|
Closing the loop: design B landed (the What shipped, in examples/gomod-integration/: an ordinary module with a two-line go.mod wiring, one hand-written app.go, a calc.hy that becomes a checked-in gofmt-canonical calc.hy.go, and calc_test.go. Plain The tools: If you try the 10-minute recipe against a real module and anything fights you, that is exactly the feedback this thread wants. The README has the section: "existing go.mod project (10 minutes)". |
Uh oh!
There was an error while loading. Please reload this page.
The problem: Hybrid's pitch is add checked
.hyfiles beside your.gofiles, keep everything else. Todayhyb buildassembles its own Go workspace (modulehybrid.program, the runtime bindings copied in, the staticlib atlib/) — that's fine for a standalone program, but the bar for adoption is tighter, and Discussion #1 stated it well:The question: how should
hybintegrate with an EXISTING Go module? Three candidate designs — critique them, or propose a fourth:Design A —
go build -toolexecwrapper.hybbecomes a toolchain wrapper: the developer runs ordinarygo build ./..., and the tool registershybso.hyfiles are compiled (checked + transpiled to Go) as part of the standard build. Pros: zero new commands,go test/go vetkeep working, the Go toolchain drives everything. Cons:-toolexecinterposes on the compiler binary, not on arbitrary file types — so it likely requires ago:generatecompanion for the.hy→.gostep anyway; version-fragility of the-toolexeccontract is a known Go ecosystem pain.Design B —
go:generatestep.//go:generate hyb generate ./...in one Go file;.hyfiles transpile to checked-in.gofiles, then the normal build proceeds untouched. Pros: simplest possible machinery, emitted Go is reviewable/diffable (the "delete the .hy file, get plain Go" property is literal), works with every CI system ever. Cons: generated files can go stale if someone edits.hywithout regenerating (mitigable:hyb generate --checkCI mode); two-step mental model.Design C — make-step / taskfile convention. The repo root gets one conventional target (
make hybrid/hyb sync) that checks.hyfiles are transpiled and up to date beforego build. Pros: explicit, no Go-toolchain tricks, trivially scriptable. Cons: yet another build-system cultural artifact — exactly the "parallel build process" the bar says kills the pitch; Go developers who don't use make are out.Constraints we hold ourselves to (from the same thread): no separate module system; deleting a
.hyfile yields plain Go; emitted Go must be plain, readable, andgofmt-clean;go testmust cover Hybrid-checked code as ordinary Go tests; the checker must still run fail-closed (an untranspiled/stale.hymust FAIL the build, never silently skip).Our current leaning: B as the MVP path (deterministic, diffable, boring), with
--checkmode making staleness a CI error, and A revisited when/if Go grows a first-party hook for non-.gosources. But this is exactly the kind of decision that should be argued about in public before it lands — so: what would make YOU trust the integration? What does your repo's build actually look like, and which of these three survives contact with it?All reactions