Workarounds for cross compiling to Windows?

Ryan Schmidt ryandesign at macports.org
Fri Jul 10 08:41:24 UTC 2020



On Jul 10, 2020, at 01:59, Ces VLC wrote:

> I know that MacPorts doesn't support building packages for other OSs, but anyway there are some features that even if they are not officially supported, do work because of the way it's designed (for example, installing MacPorts in your home directory with no root privileges needed).

Installing MacPorts to alternate prefixes with or without root privileges is officially supported, though not recommended for normal use since you won't be able to receive our precompiled archives.


> I build apps for both MacOS and Windows from the same Mac (so I cross compile to Windows, using mingw-w64). And, because apps usually depend on libraries, I build such dependencies both for MacOS and for Windows.
> 
> Until now, I used my own build scripts when cross-compiling to Windows, but I'm wondering if I could use MacPorts in some way for making this task more comfortable.
> 
> I know there are things that wouldn't apply (like patches, which are Mac-specific). In fact, MacPorts is very Mac-specific in itself.

Ports should ideally segregate Mac-specific instructions and patches into a "platform darwin" block, but many many ports don't do that and almost nobody tries to use MacPorts in any way on other platforms, though there has been a little interest from a couple people recently in using it in a very minimal way on Linux.

Even though our ports collection is intended for use on macOS, MacPorts base should compile and run on other operating systems. We used to generate the PortIndex files on a Linux server and we also had a buildbot task that verified that every MacPorts base commit built successfully on Linux. But near the end of 2016 we moved to new servers and phased out those Linux parts so it's possible that some Linux incompatibilities have crept into base since then.


> But I'm wondering if there's some way of tricking the system so that I could write for example a custom portfile for the packages I need, with this portfile modified for cross compiling to windows.
> 
> Do you think this would be feasible? Or do you recommend to keep using my scripts? Or perhaps you know of any package manager designed for cross compiling?

It's certainly feasible to make your own private ports collection for your own purposes. I for example have a collection of ports that manage the configuration of all the ports used to drive the buildbot system. There are a few common things I do in each port so I make a new portgroup that I include in each of my ports that does those things.

So it might be doable to define a new cross-compile-for-Windows portgroup that you could include into each of your custom ports, and the portgroup could take care of setting the compiler variables and flags properly, for example.

The software you want to build will probably also have dependencies on programs that get run at build time, and those would need to be compiled normally for macOS so that they can run on your Mac.

You might be able to set up your custom portgroup to install all your Windows software to a different location, like /opt/windows (maybe setting up a new variable like $wprefix with that value so that you can use it in your portfiles) while leaving $prefix to be the compiled-for-Mac prefix for build dependencies.

Or perhaps Wine figures into your build process, in case you need to run compiled-for-Windows programs on your Mac as part of the build.



More information about the macports-users mailing list