Repository navigation
Replies: 3 comments 7 replies
|
Is there a reason you need your own fakecgo package? |
What's this? |
|
@TotallyGamerJet Good question. goffi doesn't depend on purego - it's a standalone zero-dependency FFI library with its own ecosystem:
So we don't need purego's fakecgo for ourselves. The problem is on the user side - when someone wants to use both purego and goffi (or libraries built on them) in the same project. For example, an ebitengine game that also uses gogpu/wgpu for compute shaders, or any project mixing purego-based and goffi-based bindings. @zhhc99 reported this in go-webgpu/goffi#22 - could you describe your use case here? What are you building that needs both purego and goffi? We've shipped a workaround in v0.4.2 ( @hajimehoshi Sorry about the garbled character - that was a Unicode escaping issue from the GitHub GraphQL API when creating this discussion. I'll fix the body. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
When two independent libraries both include
internal/fakecgo(to enableruntime.cgocallwithCGO_ENABLED=0), the Go linker fails with:This affects any project that depends on both purego and another pure-Go FFI library (in our case, goffi). See go-webgpu/goffi#22 for the original report.
Root cause
Both packages define the same global linker symbols (
_cgo_init,_cgo_thread_start,_cgo_notify_runtime_init_done,_cgo_bindm,_cgo_pthread_key_created) via//go:linkname. These names are dictated by the Go runtime - they're read by exact name duringrt0_gostartup. The Go linker has nodupokfor data symbols and no weak symbol mechanism, so identical definitions from two packages cause a fatal error.Both implementations are pure-Go reimplementations of
src/runtime/cgo/- neither is a copy of the other.Current workaround
In goffi v0.4.2 we added a build tag
nofakecgoso users can disable our copy:This works but requires users to know about it.
Proposal: standalone fakecgo module
The clean solution would be to extract fakecgo into a standalone public Go module under a neutral organization - not owned by purego, goffi, or any single project. Both libraries would then
import _ "github.com/<neutral-org>/fakecgo", and the Go build system would deduplicate it automatically. No linker conflict, no build tags needed.Benefits:
We're happy to contribute to the effort - whether that's code, testing, or CI. Would the purego maintainers be open to discussing this?
@TotallyGamerJet @hajimehoshi — would love to hear your thoughts on this. We ran into this conflict in production (go-webgpu/goffi#22) and have a build-tag workaround for now, but a shared module would be a cleaner long-term solution for the ecosystem.
All reactions