5 ms·
If you cross-compile (which everybody using macOS to developer for Linux servers does), it's annoying to introduce SQLite to your project, because immediately t
by tptacek 4y ago
If you cross-compile (which everybody using macOS to developer for Linux servers does), it's annoying to introduce SQLite to your project, because immediately the conventional `GOOS= GOARCH= go build` trick stops working. But, in case it's helpful, it's also really easy to set up a full cross-compiling environment, either with Zig or with Filippo's musl-cross:
https://words.filippo.io/easy-windows-and-linux-cross-compilers-for-macos/ https://words.filippo.io/easy-windows-and-linux-cross-compil...
I debated doing the pure-Go SQLite thing, but musl-cross worked just fine for me, and kept things simpler.
- cynix 4y agoIs there something like this for cross-compiling to FreeBSD?
- zX41ZdbW 4y agoYou can check how ClickHouse is cross-compiled for FreeBSD. 1. https://github.com/ClickHouse/sysroot/ https://github.com/ClickHouse/sysroot/ 2. https://github.com/ClickHouse/ClickHouse/blob/master/cmake/freebsd/toolchain-x86_64.cmake https://github.com/ClickHouse/ClickHouse/blob/master/cmake/f... and the `CMAKE_TOOLCHAIN_FILE` variable.
- psanford 4y agoCross compiling with zig is so easy. For example I use sqlite in Go projects on arm. The incantation is just: export GOARCH=arm64 export CC=zig cc -target aarch64-linux-musl export CXX=zig cc -target aarch64-linux-musl
- pjmlp 4y agoCross compilation is always easy when there are no dependencies to the target platform SDKs. When it goes beyond basic libc stuff, then it is when the fun starts.
- 10000truths 4y agoIt seems fairly straightforward - copy over the SDK header files and libraries to the project and then add these envs to the build: CC="/path/to/cross/compiler" CGO_CFLAGS=—I/path/to/sdk/header/files/include" CGO_LDFLAGS="-L/path/to/sdk/obj/files/lib” I suppose with .so files, you might have to specify "-Wl,-rpath" if the SDK libraries don’t reside under /usr/lib or /usr/local/lib on the target system. But I haven’t actually tried any of this yet, so I could be wrong. Are there any gotchas that I’m missing?
- pjmlp 4y agoNow do the same as Windows UWP SDK, or iOS SDK. You're missing all the tooling and OS specific steps required to produce a proper package.
- shepherdjerred 4y agoFor macOS: https://github.com/tpoechtrager/osxcross https://github.com/tpoechtrager/osxcross
- pjmlp 4y agoDoesn't seem to do IO Kit, DriverKit, Metal, Instruments Plugins, UI frameworks, XPC, and plenty of other stuff dependent on Objective-C/Swift.
- shepherdjerred 4y agoI believe it would work for all of that, given that it links to the same libraries an app made with Xcode would. That repository won't compile Swift, but it does compile objective C. Either way, you don't need to be able to compile Swift/Obj C to link to a library that was written in Swift/Obj C.
- pjmlp 4y agoNot really, unless you're talking about specific Go developers, and even there, that is what the CI/CD pipeline is for. No one should touch servers directly, unless for down tracking stuff or remote development, in which case, they also don't need to cross compile.
- DangitBobby 4y agoPretty sure lots of people still touch servers directly, and will continue to until servers are no longer a thing.
- cerved 4y agoI mostly touch servers remotely
- pjmlp 4y agoSure, but then DevOps aren't doing their jobs. No devs on production servers unless for tracking down issues, or servers configured for remote development. Which in both cases, don't require cross compilation to start with.
- datadeft 4y agoThere are less and less touching servers directly happening. Not only DevOps but the current raise of k8s and serverless deployments making it less relevant. There is also the security aspect of it. The downside is that people (especially the ones who are just joining the workforce) are less efficient with the command line and more dependant on GUI. For example some of the junior devs do not know git cli anymore and rely on the VSCode plugin to interact with git. This becomes an issue when there is a bug in the plugin and you should use the CLI.
- pjmlp 4y agoThat is easy to sort out, like every git problem, clone the repo and start again. I know SCM tooling since the RCS days, and couldn't be bothered to master git implementation details to fix broken repos. Unfortunely we are stuck with git for the time being.
- stevan 4y agoThe following post [0] describes how to build static binaries even with cgo enabled: GOOS= GOARCH= CGO_ENABLED=1 go build \ -tags osusergo,netgo,sqlite_omit_load_extension \ -ldflags="-extldflags=-static" [0]: https://www.arp242.net/static-go.html https://www.arp242.net/static-go.html
- deleted 4y ago[deleted]
- seanp2k2 4y agoAs someone who has had to develop desktop software (ugh) with true cross-platform support for MacOS, Linux, and Windows (thanks Animation and VFX industry) using golang, I can assure everyone that it is not “really easy” to make things like Qt compile for different OSes on different OSes. IIRC trying to build for M1 Mac on AMD64 Windows was the worst.
- seanp2k2 4y agoAs someone who has had to develop desktop software (ugh) with true cross-platform support for MacOS, Linux, and Windows (thanks Animation and VFX industry) using golang, I can assure everyone that it is not “really easy” to make things like Qt cross-compile with golang. IIRC building for Mac on Windows was the worst.