Repository navigation
(BugFix) bindings: don't overwrite an existing go.mod - #88
Merged
asteurer merged 1 commit intoNov 16, 2026
Merged
Conversation
Signed-off-by: Jeremy Fleitz <jeremy@cosmonic.com>
asteurer
approved these changes
Nov 16, 2026
Contributor
Author
Contributor
|
Happily! I'll cut a release right now. Thanks for pinging me. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
componentize-go bindingswithout--pkg-name(standalone bindings) writes thego.mod that wit-bindgen-go generates, replacing whatever was there:
This means:
It can downgrade
go.bytecodealliance.org/pkg. (ran into this with an existing go project):A project pinned pkg v0.4.1 to get the
cabi_reallocGC fix, but regenerated bindings with componentize-go0.4.3, which rewrote go.mod to
v0.4.0.go mod tidykept it, and thecomponent kept trapping on multi-MiB values:
The project's go.mod had
0.4.1before the bindings step, and the downgrade happened behind the scenes.It only showed up when we checked which pkg version was linked into the
.wasm.godirective, otherrequirelines,replaceandtooldirectives, and comments on every run.Change
When a go.mod already exists in the output directory, keep it and change only what the generated code depends on:
go.bytecodealliance.org/pkgis missing or lower than the version the bindings were generated for (wit_bindgen_go::remote_pkg_version()), raise it to that version. A newer requirement is never lowered.wit_component), because the standalone bindings import their own packages through that path.bindingsprints one line saying what (suppressed by--quiet).vprefix stripped, using the existingsemverdependency, so Go pseudo-versions such asv0.2.4-0.20260911130647-2495ff7eca86sort belowv0.4.1as Go orders them.--pkg-namehint now reads "make sure your 'go.mod' file requires at least: …", so it no longer suggests replacing a newer pin.examples/sdk/pkgandexamples/sdk/componentnow requirego.bytecodealliance.org/pkgv0.4.1 instead of v0.4.0, so the one example that commits a pkg requirement starts from the version with thecabi_reallocGC fix.Testing
cmd_bindings.rs: raising a requirement in arequire (...)block and in a single-linerequire, raising from a pseudo-version, never lowering a newer version, leaving an equal version alone, adding a missing requirement while keepingtoollines, ignoringreplacedirectives and module paths that only share a prefix, and setting the module path.cargo test --lib: 15 passed.cargo test -p tests: 7 passed, includingfixture_memory_pressure.cargo clippyandcargo fmt --checkare clean.module example.com/worker,go 1.27.1and atoolline. The result hasmodule wit_component, pkg v0.4.1, and thegoandtoollines preserved, and the component builds and linkspkg@v0.4.1. A go.mod pinning v0.5.0 was left untouched.Signed-off-by: Jeremy Fleitz jeremy@cosmonic.com