|Posted by H. S. Teoh|
in reply to Jacob Carlborg
Posted in reply to Jacob Carlborg
On Thu, Apr 08, 2021 at 10:23:27AM +0200, Jacob Carlborg via Digitalmars-d-announce wrote:
> On 2021-04-07 17:27, Guillaume Piolat wrote:
> > Dumb question maybe but: in what use cases should this be used?
> I don't know, ask H. S. Teoh :D.
> I know some people have asked for it. I did it mostly because I knew how to do it and do it properly. I general I don't see the point to cross-compile (unless it's required, like mobile an embedded), because it seems like people want to use cross-compiling because they don't have the target system. But eventually you need to test the result and then you do need the target system to be able to run it.
That's the main reason for me, anyway, can't speak for others. And yes,
ideally you'd want to own the target system as well so that you can test
it, but sometimes you just want to share a personal project with someone
running on say MacOS, and it doesn't seem to make sense to buy a Mac
just to be able to share that one program. So cross-compiling would
be a much better solution.
> But perhaps if you target Windows you can then use Wine to run the executable. Seem to be something similar for macOS . But if you can run the result using Wine you should be able to run the compiler using Wine as well. Perhaps it's less of a hassle to cross-compile, I don't know.
IME, test results from Wine are not reliable. It's a good first pass to make sure you didn't do anything obviously broken, but just because something runs well in Wine does not guarantee it will run well on an actual Windows box.
But still, even then I'd rather cross-compile, because then I can just do everything on a single development machine instead of having to install and maintain multiple development toolchains across different machines. Otherwise it's just a lot of unnecessary hassle having to sync source code between different development environments and switch between computers just to build a set of release binaries, say. On a single development environment with cross-compilation, I can just setup the build script to build all binaries for all platforms at once, without any of these hassles.
> If you're targeting Linux on non-native architectures you can use qemu. Seems pretty easy if you have a statically linked binary and use qemu user emulation.
For testing, yeah I'd do that. For builds, I'd rather centralize everything on a single development environment.
> There's also free public CI services that target macOS, no need to cross-compile and it can run the code as well.
That's good to know. Still, I'd rather keep things independent of a network connection in case I ever find myself in a place without one.
> I did have a use case at my previous job. The production systems were running Linux but all developers were using macOS. We created a custom tool for the developers, which then needed to target macOS. It was a GUI application so Docker wasn't an option. We only had access to Linux CI runners so I used cross-compiling. It couldn't test the result, but at least it could build it and publish it. That's when I setup the first incarnation of this project . In this new incarnation, I've fixed the main problem of the first incarnation: reproducibility.
>  https://www.darlinghq.org
>  https://github.com/jacob-carlborg/docker-ldc-darwin
Thanks for this, it is very helpful.
Change is inevitable, except from a vending machine.