Skip to content

all: use Cgo bindings in go1.28 - #566

Closed
TotallyGamerJet wants to merge 2 commits into
ebitengine:mainfrom
TotallyGamerJet:cgo-bindings-go1.28
Closed

TotallyGamerJet wants to merge 2 commits into
ebitengine:mainfrom
TotallyGamerJet:cgo-bindings-go1.28

Conversation

@TotallyGamerJet

Copy link
Copy Markdown
Collaborator

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

TotallyGamerJet and others added 2 commits November 12, 2026 08:13
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>
@TotallyGamerJet

Copy link
Copy Markdown
Collaborator Author

Superseded by #574

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