HolyBlackCat / quasi-msys2

Cross-compile C/C++ from Linux to Windows using MSYS2 packages
zlib License
97 stars 6 forks source link
c clang cpp cross-compilation gcc package-manager

quasi-msys2

A Linux-to-Windows cross-compilation environment. Imitates MSYS2 (which is Windows-only) on Linux.

Features:

Here's how it works:

Usage

Rust

I try to support Rust for completeness, but the support is experimental.

You don't need any extra MSYS2 packages (other than make install _gcc for the libraries). Install rustup on the host and run rustup target add $CARGO_BUILD_TARGET inside env/shell.sh to install the standard library for the target platform.

Then you can use:

Package manager usage

Run make help to get the full list of commands it supports.

Here are some common ones:

Known issues

Backing up the installation

The whole installation directory can be moved around, it doesn't contain any absolute paths.

But you don't need to copy everything if you're making a backup, assuming all files came from the package manager. You only need a clean copy of the repository, and following files:

To restore such backup to a working state, run make apply-delta in it.

Not-so-frequently asked questions

How do I run commands non-interactively?

env/shell.sh works best for interactive use.

If you want to run commands non-interactively (as in from shell scripts), do this:

bash -c 'source env/all.src && my_command'

If you don't want certain components of the environment, you can study all.src and run desired components manually. (E.g. if you don't want binfmt_misc.)

How do I use different MSYS2 environments?

The environment can be changed using echo DesiredEnvName >msystem.txt, preferably in a clean repository. If you want multiple environments, you need multiple copies of Quasi-MSYS2.

All environments should work, more or less. (Except for MSYS, which I'm not particulary interested in, since Cygwin doesn't seem to work with Wine. Also CLANGARM64 wasn't tested at all.)

On CLANG64 and CLANG32, when using the native Clang, it's strongly recommended to install the same native Clang version as the one used by MSYS2 (at least the same major version, different minor versions seem to be compatible?). On those, installing or updating MSYS2 Clang requires a shell restart for the native Clang to work correctly.

How do I add a desktop entry for the quasi-msys2 shell?

Use make -f env/integration.mk. To undo, invoke it again with the uninstall flag.

Using LD instead of LLD when compiling with the native Clang.

I started having problems with the native LD after some MSYS2 update (it produces broken executables), so we default to LLD.

Last tested on LD 2.34, a more recent version might work.

LD shipped by MSYS2 (was LD 2.37 last time I checked) works under Wine. If binfmt_misc is enabled, you can switch to it using -fuse-ld=$MSYSTEM_PREFIX/bin/ld.exe.

You can try the native LD using -fuse-ld=ld. (Or remove -fuse-ld=lld from WIN_CLANG_FLAGS variable.)

My build system is confused because the compiled C/C++ binaries are suffixed with .exe.

Use source env/duplicate_exe_outputs.src. Then $CC and $CXX will output two identical binaries, foo.exe and foo. The lack of the extension doesn't stop them from being transparently invoked with Wine.

Installation structure