Re:Purego – A library for calling C functions from Go withou...
by throwaway894345 on Sunday February 12, 2023 @12:10PM
(#34764534)
You can already do this with CGo. The difference between CGo and purego is that CGo requires you have a C toolchain installed while purego seems to allow you to call a function that has already been compiled apart from the Go build system. In either case, you can call the Go library from Python, but the tough bits are translating Go objects into Python objects (and vice versa) as well as making sure object lifetimes are correctly managed (I think this is mostly "copy data rather than passing pointers across the language boundary").
[ Parent
| on HN ]
Re:Purego – A library for calling C functions from Go withou...
by pknerd on Sunday February 12, 2023 @12:13PM
(#34764580)
I know about CGo and have used it. The post title, "A library for calling C functions from Go without Cgo", made me curious how do I achieve something similar with PureGo without using CGO
Re:Purego – A library for calling C functions from Go withou...
by totallygamerjet on Sunday February 12, 2023 @12:26PM
(#34764709)
I’m one of the main contributors. I’ve looked into it bc I wanted to know if I could build iOS apps without Cgo. ATM, it is not possible. The reason is because when you run go build creating a shared object it runs the go cgo tool. That tool although written entirely in Go doesn’t know about purego and so will go ahead and import runtime/cgo which requires a C toolchain. Now it could be possible to circumvent that with using a custom Go build toolchain but the goal of purego was to be seemless to use in a project. Just use it and then go build like any other dependency.