Yes, in principle the present question is a duplicate of this one, but that's been asked and answered 12 years ago. The answer might have changed in the meanwhile. And indeed the material I linked to is not that old, so things have definitely changed as far as cross-compilation in general goes; whether that means a different answer exists today for the present question is another thing, and that's why I'm asking.
I have my Linux system where I develop Haskell code , and I came up with a Haskell program that I want to port to Windows. All I can do on the latter is literally copy an executable and run it; I can't install anything on it.
It's a terminal-based program, where I use a bit of System.Console.ANSI
for coloring text, clearning the screen, and so on. There I read "platform-independent", so I'm optimistic about porting it to Windows (but regardless, I'm interested in cross-compiling also just a hello world little example).
I manage my Haskell environment with GHCup. I use Cabal, not Stack.
I've skimmed through this page on cross compilation, and what makes me think the answer might be no, or at least not that straightforwardly are the following.
This one, which is the only place in the page where Windows is mentioned:
- Cross-building a normal compiler: Build on one platform a compiler that runs on, and targets another. Examples:
- TakeoffGW is a distribution of Unix tools for Windows, built by cross-compiling on a Linux machine. They would like to be able to build and distribute GHC this way. It might be useful for us to be able to cross-compile a Windows GHC from Linux too.
- build a 64-bit GHC on OS X, by cross-compiling using the 32-bit version.
- We could port to Win64 (#1884 (closed)) by cross-compiling using a 32-bit Windows GHC.
- Other porting tasks might be easier, given a suitable cross-compilation toolchain.
and this one, that only mentions Linux,
More targets work in various directions. Some notable ones:
- x86_64-linux -> aarch64-linux (64-bit LE -> 64-bit LE)
- x86_64-linux -> armv7a-linux (64-bit LE -> 32-bit LE)
- x86_64-linux -> m68k-linux (64-bit LE -> 32-bit BE)
- i386-linux -> powerpc64-linux (32-bit LE -> 64-bit BE)
Have I misunderstood that page, or is it outdated? Can I compile a Haskell program on Linux to make it run on Windows?