crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.32k stars 1.61k forks source link

Build with Mingw-w64 #6170

Open ghost opened 6 years ago

ghost commented 6 years ago

Crystal is in the process of supporting Visual Studio. However Mingw-w64 should be supported as well.

http://mingw-w64.org

sam0x17 commented 6 years ago

I'm all for this because I like the idea of being able to build windows binaries without windows, but not to the detriment / timeliness of the current windows development being done. That said, maybe this will make windows CI easier? or no?

straight-shoota commented 6 years ago

Of course, Mingw64 should be supported. It doesn't feel like a pressing issue to me, though.

I don't no much about the practical differences between MSVC and Mingw64 in regards to Crystal supporting it. But, as I alread said in https://github.com/crystal-lang/crystal/issues/5430#issuecomment-395958620, the current effort should focus on porting the stdlib to Win32 API. That needs to be done anyway and still requires a lot of work. Supporting an alternate tool chain doesn't gain anything until that is at least somewhat matured.

this will make windows CI easier?

Windows CI needs to run on windows anyway, so there is no point in cross compiling from a different platform.

faustinoaq commented 5 years ago

Windows CI needs to run on windows anyway, so there is no point in cross compiling from a different platform.

Azure CI looks very interesting. It supports Windows, Linux and Mac and is free fpr Open Source Projects: https://azure.microsoft.com/en-us/blog/announcing-azure-pipelines-with-unlimited-ci-cd-minutes-for-open-source/ @bcardiff @RX14 :eyes:

straight-shoota commented 5 years ago

travis-ci has also announced windows support: https://blog.travis-ci.com/2018-10-11-windows-early-release

That should be fairly easy to integrate into the CI setup

mominshaikhdevs commented 1 year ago

Since Crystal is maturing support towards MSVC and Win32 APIs directly instead of mingw-w64 (https://github.com/crystal-lang/crystal/issues/26#issuecomment-999358790), Is this still relevant?

straight-shoota commented 1 year ago

Technically yes. Mingw-w64 is a different target than msvc and supporting it is still a goal I think. Although it's not actively driven at the moment due to low importance. So I guess we could also close this issue because it's not directly actionable, with the option to re-open once there's activity towards supporting this platform. I expect it shouldn't be much work, but also probably not many people care about it due to native Win32 support and the overall decline of Mingw due to WSL.

mominshaikhdevs commented 1 year ago

Exactly. The Crystal team can always re-open the issue if there is enough demand for it.

ghost commented 1 year ago

Mingw-w64 is a different target than msvc and supporting it is still a goal I think.

correct. which is the reason language like Rust offer a MSVC and GNU build for Windows, the latter being MinGW-w64.

So I guess we could also close this issue because it's not directly actionable

how is it not actionable? wouldn't adding support for it be an action?

re-open once there's activity towards supporting this platform

please dont do that. you have over 1000 issues open, no harm in leaving this open. closing by a maintainer sends a strong signal that this is essentially WONTFIX, regardless of any reason given.

not many people care about it due to native Win32 support and the overall decline of Mingw due to WSL.

both of these items are false. Native Win32 support is only marginally useful, as developing with that environment requires an install of Visual Studio, which is at least 100 times the install size of MSYS2 and similar options. secondly, WSL has no impact on MinGW/MSYS2, because WSL is a Linux emulator, so you take a huge performance hit using that option, whereas MSYS2 offers native Windows output.

straight-shoota commented 1 year ago

how is it not actionable? wouldn't adding support for it be an action?

Actionable means to have a clear path what's necessary to achieve this, or at least the intention to discuss that and determine a path.

you have over 1000 issues open, no harm in leaving this open. closing by a maintainer sends a strong signal that this is essentially WONTFIX, regardless of any reason given.

Yes, we'd like to reduce that number. There's not much value in having lots of stale issues. We know that Mingw is not supported and that support for it would be welcome. But no need to keep an issue around that does nothing. There are dozens if not hundreds of somewhat reasonably relevant platforms which Crystal does not currently support. It doesn't make sense to keep open issues just to remind of that.

both of these items are false. Native Win32 support is only marginally useful, as developing with that environment requires an install of Visual Studio, which is at least 100 times the install size of MSYS2 and similar options. secondly, WSL has no impact on MinGW/MSYS2, because WSL is a Linux emulator, so you take a huge performance hit using that option, whereas MSYS2 offers native Windows output.

Sorry, I have a hard time making any sense of "Native Win32 support is only marginally useful". This has been one of the most requested features since almost the beginning of Crystal (#26). And even though we're not yet fully there, it's already used by many people. I fail to see any marginality of the most popular desktop operating system's native environment.

I also beg to differ that "WSL has no impact on MinGW/MSYS2". MSYS2 is a tool for using Unix programs on Windows. I used that myself back in the day. But I've long moved to WSL because it's a much more complete Unix environment with an actual Linux kernel interface that offers a lot more possibilities. Sure, WSL is not a replacement for all use cases of MSYS2. But for me, it is a much better one. And I'm pretty sure for many others as well.

ghost commented 1 year ago

Yes, we'd like to reduce that number. There's not much value in having lots of stale issues. We know that Mingw is not supported and that support for it would be welcome. But no need to keep an issue around that does nothing. There are dozens if not hundreds of somewhat reasonably relevant platforms which Crystal does not currently support. It doesn't make sense to keep open issues just to remind of that.

I get the desire to want to close issues, but closing them doesn't fix anything, it just makes you feel better. they should be closed when they are actually fixed, or when they decision is made that they will never be fixed.

Sorry, I have a hard time making any sense of "Native Win32 support is only marginally useful". This has been one of the most requested features since almost the beginning of Crystal (#26).

sorry I was just using your language. a better comment would be "MSVC support is only marginally useful". Windows developers use MSVC when its the only option. Ideally MSYS2 support would also exist, as it has several benefits over MSVC.

I also beg to differ that "WSL has no impact on MinGW/MSYS2". MSYS2 is a tool for using Unix programs on Windows.

MSYS2 is able to produce native Windows programs:

https://packages.msys2.org/base/mingw-w64-gcc

Sure, WSL is not a replacement for all use cases of MSYS2.

its not a replacement at all. WSL "programs" are linux programs that work on Windows via an emulator. MSYS2 produces native Windows programs that rely on the Windows API. the two couldn't be more different.

straight-shoota commented 1 year ago

I get the desire to want to close issues, but closing them doesn't fix anything, it just makes you feel better. they should be closed when they are actually fixed, or when they decision is made that they will never be fixed.

Keeping it open also does nothing towards getting it resolved. Closing issues with no forseeable activity helps to keep the amount of currently relevant issues manageable. And I think it's more honest to close the issue to make clear that it's not an active goal. The Core Team won't pursue Mingw support, so perhaps it might be more accurate to describe this as "wontfix". Although it's not a hard one. We're accepting contributions from the community. But until someone picks that up and starts actively working on it, this issue is just a zombie.

HertzDevil commented 6 months ago

To be clear, there are a few different toolchains possible on Windows:

Toolchain Compiler Triple Flags Additional runtimes
Microsoft Visual C++ cl.exe x86_64-pc-windows-msvc windows msvc win32 VCRedist, UCRT
MinGW-w64 (native) gcc.exe x86_64-w64-windows-gnu windows gnu win32 VCRedist, (UCRT or MSVCRT)
MinGW-w64 (MSYS) gcc.exe x86_64-w64-windows-gnu windows gnu unix msys-2.0.dll
Cygwin gcc.exe x86_64-unknown-cygwin
x86_64-pc-windows-cygnus
windows gnu unix cygwin1.dll

MSYS is the "MSYS" environment of MSYS2, as indicated by $MSYSTEM; native is any other MSYS2 environment (e.g. UCRT64), or a stand-alone installation like WinLibs. Clang and LLVM are unmaintained and extremely outdated on Cygwin's repository, so we will forget about that for the moment.

While the majority of our MSVC toolchain work is completed, some deserves extra attention regarding what happens if other Windows toolchains are going to be supported, such as the meaning of "default shell". There is also the issue that MinGW-w64's license will always be more permissive than MSVC's, and that could be a deal breaker for some people. So I think now is a good time to revisit those alternative toolchains.

ysbaddaden commented 6 months ago

I see little value in supporting Cygwin or MSYS-2.0 since we support the official Windows API: there shouldn't be any portability issues of crystal code.

I can see value in MinGW-w64 as an alternative to MSVC, especially if we could link an EXE from linux or macos (though I'm not sure about the runtime in that case).

beta-ziliani commented 6 months ago

I see little value in supporting Cygwin or MSYS-2.0 since we support the official Windows API: there shouldn't be any portability issues of crystal code.

+1

especially if we could link an EXE from linux or macos

What? 😮

straight-shoota commented 6 months ago

especially if we could link an EXE from linux or macos

What? 😮

Sure. Linking against msys we wouldn't need any Windows system libraries, so it should be entirely feasible to cross-link executables.

beta-ziliani commented 6 months ago

Ah, right, thanks for clarifying 🙇

HertzDevil commented 6 months ago

You can cross-link Windows executables straight from non-Windows systems using x86_64-w64-mingw32-gcc, as long as all the third-party dependencies are also cross-linked. MinGW-w64 maintains its own import libraries for the Win32 API (which are always dynamically linked), and that's why you don't need anything from a Visual Studio installation for this to work.

x86_64-w64-windows-gnu is not merely about switching the compiler, by the way; the build environment should also answer questions like whether programs like sh.exe or make.exe or pkg-config.exe are expected to exist at build time, which makes a difference for things like library version detection. There is a reason why RubyInstaller comes with the MSYS2 UCRT64 environment or requires you to bring your own.


Anyway, here is a worked example of using MinGW-w64 stand-alone on Windows:

We can supposedly symlink src/lib_c/x86_64-windows-msvc/ to src/lib_c/x86_64-windows-gnu/, but Crystal needs to know whether it is inside an MSYS2 environment or not, because an MSYS / Cygwin port would have used that same directory.

crysbot commented 1 month ago

This issue has been mentioned on Crystal Forum. There might be relevant details there:

https://forum.crystal-lang.org/t/the-easiest-way-to-prepare-a-ready-to-use-windows-executable-on-linux/7040/2