rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.72k stars 12.5k forks source link

Building Rust software for use in an MSYS2 environment? #102309

Open LunarLambda opened 1 year ago

LunarLambda commented 1 year ago

tl;dr: Is it possible, and if not, how much work would be necessary, to compile Rust programs for MSYS2's emulated POSIX environment (i.e. programs that link against msys-2.0.dll)?

MSYS2 is not merely useful as a build environment for cross-compiling on Windows, but also as a portable development environment and alternative to WSL.

So, it would be quite useful to compile some unix-y Rust tools for that environment. I've gotten some crates like bat, ripgrep, and fd-find to work, by building for x86_64-pc-windows-gnu, and letting MSYS2's automatic command line path conversion do its magic, but some, especially those dealing with file metadata, terminals, or IPC, don't interoperate very well, since they only talk to the Windows APIs, not the 'emulated' POSIX APIs.

For example, currently, exa doesn't build for Windows at all, since it expects some "POSIX-ly" libc extensions.

As my understanding is, at minimum, a custom target would be needed, similar to x86_64-pc-windows-gnu, but with target_family = "unix", and which uses the MSYS2-native GCC toolchain, and links against the MSYS2 runtime libraries.

I don't believe this would require building Rust itself for MSYS2, the regular, windows-native rustc and cargo should be fine there, however, it would require building std et al. for MSYS2.

I haven't experimented with writing my own targets before, so I'd appreciate any advice and directions, as well as hearing if the Rust team is interested in or already looking into supporting MSYS2 as a target "platform".

I understand it's a niche use case, but given MSYS2's value as both a build and development environment on Windows platforms, and its relative portability compared to things like WSL or other forms of virtualization, I believe it could be useful for many people besides myself.

LunarLambda commented 6 months ago

Always fun when you search for something and the only matching result is your own year old GitHub issue 😅

mati865 commented 6 months ago

Somebody is working on it and was able to build ripgrep with it: https://github.com/ookiineko-cygport/rust You can find short progress report at MSYS2 Discord sever.