Repository navigation
all: use Cgo bindings in go1.28 - #566
Closed
TotallyGamerJet wants to merge 2 commits into
Closed
TotallyGamerJet wants to merge 2 commits into
TotallyGamerJet wants to merge 2 commits into
Conversation
Go 1.28 can build cgo packages that only bind to existing C libraries without a C compiler (golang/go#81450), and runtime/cgo no longer contains C. On go1.28+: - import runtime/cgo in every mode instead of internal/fakecgo (!cgo) or internal/cgo (cgo). - call dlopen/dlsym/dlerror/dlclose through //cgo:binding declarations in the new internal/cbind package, including on Android. - replace internal/cgo's C syscall15 on Linux architectures without a purego trampoline with a //cgo:funcptr binding. - bind objc's fixed-signature runtime functions instead of registering them with RegisterLibFunc. No build tag says whether bindings were built (the cgo tag is false in the no-toolchain mode), so the binding files set function variables from init and callers fall back to the existing trampolines when they are nil, which happens with an explicit CGO_ENABLED=0. RegisterFunc, SyscallN, NewCallback and objc.Send keep their reflection and assembly paths: their signatures are only known at run time. Builds with Go 1.27 and earlier are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tested against the golang/go#81450 CL stack (CL 856832, patch set 20): cmd/cgo keeps only filepath.Base of a binding's library when it writes the cgo_import_dynamic load directive, so the objc bindings produced an LC_LOAD_DYLIB of "libobjc.A.dylib" and dyld aborted at launch. Bind with "_" and add the full-path load directive by hand until that is fixed. Also note in the README that Go still needs an external linker for cgo on mips/mips64/ppc64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
Superseded by #574 |
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.
What issue is this addressing?
Updates #565
What type of issue is this addressing?
feature
What this PR does | solves
testing out support for the new Go 1.28 Cgo