refactor: own the CGO-free switch and guard the surface in core (#345) - #347
Merged
antoinetoussaint-byte merged 3 commits intoAug 23, 2026
Conversation
Confine the cgo/no-cgo build switch to core and enforce the CGO-free surface as a contract: - Add code/codeserver.New: a build-tag-split constructor. The default build installs the tree-sitter analyzer; -tags codefly_nosemantic returns a CGO-free DefaultCodeServer. Consumers get one call and no build tags of their own. codefly_nosemantic is the canonical tag. - Add scripts/check_cgo_free.sh (make check-cgo-free + CI step) that builds every package CGO-free except a documented cgo allowlist, so cgo creep fails in core at the introducing PR. - Document the CGO surface, ownership boundary, tag semantics, and allowlist in docs/cgo.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- The cgo surface table said no non-test package imports code/semantic; code/codeserver now does on the default build. Clarify it stays out of the CGO-free build via the codefly_nosemantic tag. - Fix "code/code/semantic" typo in the guard's failure message. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The build-tag-aware constructor lives in code/codeserver because the import cycle (code/semantic imports code) forbids it in package code, so a consumer browsing package code's constructors/options never finds it and reinvents the cgo/no-cgo split — the exact duplication this issue removes. Signpost the packaged constructor at WithSemanticAnalyzer, the manual mechanism a reinventor reaches for. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Closes #345.
Summary
codefly_nosemanticbuild tag; this is the core-side generalization it revealed.code/codeserver.New(root)is the single entry point — the default build installs the tree-sitter analyzer (code/semantic),-tags codefly_nosemanticreturns a CGO-freeDefaultCodeServer.codefly_nosemanticis standardized as the canonical, cross-repo tag. The switch lives in a newcode/codeserverpackage becausecode/semanticimportscode, so the switch cannot sit incodewithout an import cycle.scripts/check_cgo_free.sh(make check-cgo-free+ a CI step ingo.yml) builds every package withCGO_ENABLED=0 -tags codefly_nosemanticexcept a documented allowlist (code/semantictoday). A new dependency that drags cgo into the CGO-free surface now fails in core at the introducing PR, with a clear message — instead of at a downstream companion publish weeks later.code/semantic, so an accidentalCGO_ENABLED=0build of the full server fails at link time rather than silently dropping semantics. Dropping semantics is only ever explicit, via the tag.Investigation findings (full cgo inventory, ownership-boundary decision, tag semantics, and the allowlist) are documented in
docs/cgo.md. The entire cgo surface is confirmed to be the singlecode/semanticpackage — no sqlite or other cgo dependencies.The out-of-process option (serving tree-sitter from a separate cgo agent) was evaluated and deferred — it contradicts the in-process source path and adds an IPC hop; noted as a revisit-if-the-gateway-moves item in
docs/cgo.md.Test plan
go test ./code/codeserver/— new test asserts the default build wires the analyzer (real tree-sitter semantic index over a Python source tree, no mocks).go test -tags codefly_nosemantic ./code/codeserver/— analyzer test is correctly gated out; package still compiles CGO-free.make check-cgo-freepasses; verified it fails (with thebuild constraints exclude all Go fileserror) whencode/semanticis removed from the allowlist.go build ./...(default) andgo vet ./code/codeserver/clean;gofmtclean.