News for hackers. Stuff that matters.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by echoangle on Thursday November 28, 2024 @05:45PM (#42269104)
As someone who doesn’t know a lot about go: why is CGo-free a feature? In what situations is CGo (which is basically just calling C libs from go, right?) bad?
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by danenania on Thursday November 28, 2024 @06:09PM (#42269281)
It makes cross-compiling a lot more difficult. Instead of being able to build on whatever OS/architecture you use and produce binaries for any other OS/architecture you want to target with a single command (one of Go's superpowers), you need a complex build pipeline.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by wild_egg on Thursday November 28, 2024 @08:37PM (#42270047)
I've been using zig's toolchain in CGo projects for a couple years now and cross compilation _just works_. Maybe there are libraries it doesn't handle well but so far all of my use cases have been covered perfectly.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by AYBABTME on Thursday November 28, 2024 @08:50PM (#42270108)
Example? Curious, can Zig can be used to simplify CGO dependency management in general, or only for Zig programs?
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by rockorager on Thursday November 28, 2024 @10:39PM (#42270590)
It could definitely work for that. You have to think of zig in this context as a build system which can download and compile C/C++ codebases.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by wffurr on Thursday November 28, 2024 @09:17PM (#42270230)
Zig is a C compiler. Much like D, you can use it to cross compile any C code.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by kristoff_it on Friday November 29, 2024 @12:34AM (#42271117)
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by karel-3d on Friday November 29, 2024 @04:01AM (#42272324)
I have personally hit some roadblock before that I cannot really remember anymore, so I just gave up and used debian docker image.

(Which needed to be old enough that it had old glibc, so someone with 10 year old OS doesn't complain. Linux.)

zig gets around that by using musl, right? or does it use old libc?

Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by karel-3d on Friday November 29, 2024 @03:57AM (#42272304)
Note that modernc/cznic stuff is not really actual go but C trans-compiled to Go, the trans-compiler having specific quirks for every platform,.

So it's not technically possible to compile to all platforms that Go runs on, only the platforms that the trans-compiler supports. And the resulting Go code is not that readable.

https://gitlab.com/cznic/libtcl9.0/-/blob/master/libtcl9_0_l...

https://pkg.go.dev/modernc.org/ccgo/v3

But it still improves cross-compiling, and results in a libc independent static binary, which is nice. And the work done on the trans-compiling is great.

Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by cedws on Thursday November 28, 2024 @05:55PM (#42269175)
FFI is an additional headache. Instead of having a single hermetic build process that just works, with FFI you now have to deal with shared libraries which may or may not be present, and may or may not support all the architectures or operating systems you want to target. FFI is why so many Python projects blow up when you run pip install. Then it takes sometimes hours to untangle that horror show.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by cle on Thursday November 28, 2024 @06:28PM (#42269383)
This is using purego which is still using FFI, it is dynamically linking the C libs so you still have the same shared library issues. You don’t have to setup a C compiler toolchain though which is nice.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by Onavo on Friday November 29, 2024 @12:18AM (#42271048)
Why don't they just compile to C to Go like modern c does for SQLite?
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by masklinn on Friday November 29, 2024 @01:09AM (#42271294)
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by Onavo on Friday November 29, 2024 @12:34PM (#42275445)
I mean why don't they do it for the source library too? There are very few operations in C that can't be done in Go (mostly inline assembly and some pointer manipulation) under a standard userland assumption.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by wokwokwok on Thursday November 28, 2024 @06:39PM (#42269458)
It’s not a technical thing.

It’s not bad.

It’s a misguided community thing.

Cgo is the correct choice for many domains (ui, gamedev, systems stuff) where you can’t use a network boundary as your “interacts with other languages”.

The language is opinionated; it’s not good at playing with others. It’s good at other things (network services, etc)… but you can and it’s not bad.

…it’s just hard, and people don’t like hard things.

Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by AYBABTME on Thursday November 28, 2024 @08:50PM (#42270111)
It can be slower than pure Go options in some scenarios.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by wokwokwok on Thursday November 28, 2024 @10:29PM (#42270554)
Purego is ffi and is slower than cgo.

That library (like this) claim “no cgo” when they use ffi is just ridiculous.

This one is particularly egregious in even supporting cgo!

Pure go my ass. You’re invoking c functions. It’s not pure go.

The distinction is in the tool chain; cgo is a better, first party solution.

Purego is an unstable (it is, read the repo!) workaround for people who a) don’t like the word “cgo” or b) dont like having a c tool chain.

…but realistically you have to interop with c code in many domains.

Sure, a pure world is great, but that’s not always possible.

People who don’t like cgo and choose purego are doing it for, mostly, optics (cgo is bad! This isn’t cgo… it’s ffi… totally different) and appear to fail to appreciate the technical distinction more complicated than they imagine, and they are still using c.

Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by paride5745 on Friday November 29, 2024 @03:04AM (#42271926)
Cgo in server projects makes using Alpine as a base a headache honestly.

If I can I always pick pure Go solutions just for this reason.

Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by tedunangst on Thursday November 28, 2024 @07:43PM (#42269773)
By eliminating cgo, they cut the supported platform list in half.
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by int_19h on Thursday November 28, 2024 @11:34PM (#42270833)
FFI mess is the price Go pays for having its own bespoke green threads (goroutines).
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by kunley on Friday November 29, 2024 @01:40AM (#42271473)
Being CGo-free is very desirable when you can't/don't want/don't bother to link C library deps for some reason. On example when you don't want to do that is cross-compiling for another architecture and not really being able to control what runtime libraries are installed on the target.

So, it simplifies build pipelines, at the cost of being a bit slower in the runtime.

This is also nice to read about the topic: https://dave.cheney.net/2016/01/18/cgo-is-not-go

Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by tc4v on Friday November 29, 2024 @02:01AM (#42271572)
Re:Tk9.0: CGo-free, cross platform GUI toolkit for Go by binarin on Friday November 29, 2024 @02:10AM (#42271616)
CGo compilation can be insanely slow.