Page MenuHomeFreeBSD

[new port] devel/mingw-w64 - LLVM MingGW cross compilation toolchain for Windows Executables
Needs ReviewPublic

Authored by russ.haley_gmail.com on Apr 20 2020, 5:09 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Martin Storsjo has created a mingw cross compiler toolchain for LLVM based on the clang tools called llvm-mingw. This is a port created by @theron.tarigo_gmail.com that uses the ports tree to assemble a similar toolchain.

llvm-mingw is a drop in replacement for the gcc based mingw32 toolchain. There are some differences in the linker system as noted by Martin Storsjo.

The package uses mingw64 and Clang10

Test Plan

My testing is practical rather than prescriptive.

I am using LLVM-MinGW on FreeBSD to cross compile my winlua.net toolchain (https://winlua.net). WinLua includes lua, luarocks, libressl and the llvm-mingw compiler (on windows). I then package that and use it as a C/C++ toolchain on Windows. I build and test WinLua in both i686-w64-mingw32 and x86_64-w64-mingw32. There is 2 Windows installations at work and I use it at home on Windows. I have recently used WinLua to cross port netpgp to Windows.

While surely not exhaustive, my use case is quite extensive and even produces 3rd line validation that the cross compiling is correct. The use case could be said to validate that the LLVM-Mingw compiler toolchain works on FreeBSD because it produces a working windows compiler and other software.

Diff Detail

Repository
rP FreeBSD ports repository
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

russ.haley_gmail.com retitled this revision from devel/mingw-w64 - Clang LLVM cross compilation toolchian to devel/mingw-w64 - LLVM MingGW cross compilation toolchian for Windows Executables.Apr 20 2020, 5:20 AM
russ.haley_gmail.com edited the summary of this revision. (Show Details)
linimon retitled this revision from devel/mingw-w64 - LLVM MingGW cross compilation toolchian for Windows Executables to [new port] devel/mingw-w64 - LLVM MingGW cross compilation toolchain for Windows Executables.Apr 20 2020, 3:26 PM

Thank you for working on this. You are welcome to claim maintainership if you'd like but that it also is not necessary as I do not wish to abandon this project.

The package uses mingw64 and Clang10

Does this pertain to planned work? The patch still shows

DISTVERSION= 9.0.1

etc.

Thank you for working on this. You are welcome to claim maintainership if you'd like but that it also is not necessary as I do not wish to abandon this project.

The package uses mingw64 and Clang10

Does this pertain to planned work? The patch still shows

DISTVERSION= 9.0.1

etc.

Yes, I'd very much like that. That is very kind of you. I wouldn't have been able to translate from the shell script to make files. I'm maintaining a windows toolchain with this compiler as well: http://winlua.net. I'm inches away from completing an installer and then I'm going to turn my attention to this and Lua 5.4.

As per Clang-9/10: yes. I am using clang 10 with the scripts in Martins git repository, I was waiting for the binary pkg of clang-10 to show up, which it did for me today.

Hello,

I've been messing with this port in my time off.

I have been unable to get mingw-w64-clang-rt90 to build:

/usr/bin/sed -I ''  's,^FLAGS=""$,FLAGS="--sysroot=/usr/local/${TARGET}",'  /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5/wrappers/clang-target-wrapper.sh
/usr/bin/sed -I ''  's,^export PATH=",export PATH="/usr/local/llvm90/bin:,' /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5/wrappers/dlltool-wrapper.sh
/usr/bin/sed -I ''  's,^export PATH=",export PATH="/usr/local/llvm90/bin:,' /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5/wrappers/ld-wrapper.sh
/usr/bin/sed -I ''  's,^export PATH=",export PATH="/usr/local/llvm90/bin:,' /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5/wrappers/objdump-wrapper.sh
===>  Building for mingw-w64-clang-wrapper-llvm90-20200217
cd /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5 &&  /usr/bin/env  WRAPPER_PREFIX=/usr/local/mingw-w64  LLVM_PREFIX=/usr/local/llvm90  TOOLCHAIN_ARCHS="i686 x86_64 armv7 aarch64"  DESTDIR=/usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work  ./install-wrappers.sh "/usr/local"
===>  Staging for mingw-w64-clang-wrapper-llvm90-20200217
===>   mingw-w64-clang-wrapper-llvm90-20200217 depends on package: llvm90>=0 - found
===>   Generating temporary packing list
cp -f -R /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/usr/local/bin/ /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/stage/usr/local/bin
/bin/mkdir -p /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/stage/usr/local/mingw-w64
cp -f -R /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/usr/local/mingw-w64/bin/  /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/stage/usr/local/mingw-w64/bin
====> Compressing man pages (compress-man)
===>  Installing for mingw-w64-clang-wrapper-llvm90-20200217
===>  Checking if mingw-w64-clang-wrapper-llvm90 is already installed
===>  Switching to root credentials for 'install' target
===>   Registering installation for mingw-w64-clang-wrapper-llvm90-20200217 as automatic
[jailbird] Installing mingw-w64-clang-wrapper-llvm90-20200217...
===>  Returning to user credentials
===>   mingw-w64-20200217 depends on package: mingw-w64-clang-wrapper-llvm90>=0 - found
===>   Returning to build of mingw-w64-20200217
===>   mingw-w64-20200217 depends on package: mingw-w64-clang-rt90>=0 - not found
/!\ WARNING /!\

Ports Collection support for your FreeBSD version has ended, and no ports are
guaranteed to build on this system. Please upgrade to a supported release.

===>  License LLVM PD LLVM2 accepted by the user
===>   mingw-w64-clang-rt90-9.0.1 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by mingw-w64-clang-rt90-9.0.1 for building
===>  Extracting for mingw-w64-clang-rt90-9.0.1
=> SHA256 Checksum OK for compiler-rt-9.0.1.src.tar.xz.
===>  Patching for mingw-w64-clang-rt90-9.0.1
===>   mingw-w64-clang-rt90-9.0.1 depends on package: llvm90=9.0.1 - not found
===>   mingw-w64-clang-rt90-9.0.1 depends on package: llvm90=9.0.1 - not found
*** Error code 1

Stop.
make[1]: stopped in /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-rt
*** Error code 1

Stop.
make: stopped in /usr/home/russellh/freebsd/ports/devel/mingw-w64

If I attempt to re-run the port, it doesn't even try to build LLVM90 because the target is already up to date:

russellh@jailbird ~/f/p/d/mingw-w64> make BATCH=yes
===>  Staging for mingw-w64-20200217
===>   mingw-w64-20200217 depends on package: mingw-w64-clang-wrapper-llvm90>=0 - found
===>   mingw-w64-20200217 depends on package: mingw-w64-clang-rt90>=0 - not found
===>   mingw-w64-clang-rt90-9.0.1 depends on package: llvm90=9.0.1 - not found
===>   mingw-w64-clang-rt90-9.0.1 depends on package: llvm90=9.0.1 - not found
*** Error code 1

Stop.
make[1]: stopped in /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-rt
*** Error code 1

Stop.
make: stopped in /usr/home/russellh/freebsd/ports/devel/mingw-w64
russellh@jailbird ~/f/p/d/mingw-w64> clang90 --version
clang version 9.0.1 
Target: x86_64-portbld-freebsd12.0
Thread model: posix
InstalledDir: /usr/local/llvm90/bin

I've done this a few times now and even cleaned and tried different backends (FreeBSD targets, All non-experimental). I'm wondering if LLVM didn't build for the correct architecture? I noted there is no explicit port option for windows binaries (obviously) so I did select all non-experimental backends.

@theron.tarigo_gmail.com, you may know right away what I have done incorrectly? I assume from the language in our email that you were using this port prior to my uploading it. Did you ever install LLVM from a source other than the LLVM90 port? I wonder if LLVM was built with different backend settings and the files have lingered?

Hello,

I've been messing with this port in my time off.

I have been unable to get mingw-w64-clang-rt90 to build:

/usr/bin/sed -I ''  's,^FLAGS=""$,FLAGS="--sysroot=/usr/local/${TARGET}",'  /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5/wrappers/clang-target-wrapper.sh
/usr/bin/sed -I ''  's,^export PATH=",export PATH="/usr/local/llvm90/bin:,' /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5/wrappers/dlltool-wrapper.sh
/usr/bin/sed -I ''  's,^export PATH=",export PATH="/usr/local/llvm90/bin:,' /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5/wrappers/ld-wrapper.sh
/usr/bin/sed -I ''  's,^export PATH=",export PATH="/usr/local/llvm90/bin:,' /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5/wrappers/objdump-wrapper.sh
===>  Building for mingw-w64-clang-wrapper-llvm90-20200217
cd /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/llvm-mingw-39f7bf5 &&  /usr/bin/env  WRAPPER_PREFIX=/usr/local/mingw-w64  LLVM_PREFIX=/usr/local/llvm90  TOOLCHAIN_ARCHS="i686 x86_64 armv7 aarch64"  DESTDIR=/usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work  ./install-wrappers.sh "/usr/local"
===>  Staging for mingw-w64-clang-wrapper-llvm90-20200217
===>   mingw-w64-clang-wrapper-llvm90-20200217 depends on package: llvm90>=0 - found
===>   Generating temporary packing list
cp -f -R /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/usr/local/bin/ /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/stage/usr/local/bin
/bin/mkdir -p /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/stage/usr/local/mingw-w64
cp -f -R /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/usr/local/mingw-w64/bin/  /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-wrapper/work/stage/usr/local/mingw-w64/bin
====> Compressing man pages (compress-man)
===>  Installing for mingw-w64-clang-wrapper-llvm90-20200217
===>  Checking if mingw-w64-clang-wrapper-llvm90 is already installed
===>  Switching to root credentials for 'install' target
===>   Registering installation for mingw-w64-clang-wrapper-llvm90-20200217 as automatic
[jailbird] Installing mingw-w64-clang-wrapper-llvm90-20200217...
===>  Returning to user credentials
===>   mingw-w64-20200217 depends on package: mingw-w64-clang-wrapper-llvm90>=0 - found
===>   Returning to build of mingw-w64-20200217
===>   mingw-w64-20200217 depends on package: mingw-w64-clang-rt90>=0 - not found
/!\ WARNING /!\

Ports Collection support for your FreeBSD version has ended, and no ports are
guaranteed to build on this system. Please upgrade to a supported release.

===>  License LLVM PD LLVM2 accepted by the user
===>   mingw-w64-clang-rt90-9.0.1 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by mingw-w64-clang-rt90-9.0.1 for building
===>  Extracting for mingw-w64-clang-rt90-9.0.1
=> SHA256 Checksum OK for compiler-rt-9.0.1.src.tar.xz.
===>  Patching for mingw-w64-clang-rt90-9.0.1
===>   mingw-w64-clang-rt90-9.0.1 depends on package: llvm90=9.0.1 - not found
===>   mingw-w64-clang-rt90-9.0.1 depends on package: llvm90=9.0.1 - not found
*** Error code 1

Stop.
make[1]: stopped in /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-rt
*** Error code 1

Stop.
make: stopped in /usr/home/russellh/freebsd/ports/devel/mingw-w64

If I attempt to re-run the port, it doesn't even try to build LLVM90 because the target is already up to date:

russellh@jailbird ~/f/p/d/mingw-w64> make BATCH=yes
===>  Staging for mingw-w64-20200217
===>   mingw-w64-20200217 depends on package: mingw-w64-clang-wrapper-llvm90>=0 - found
===>   mingw-w64-20200217 depends on package: mingw-w64-clang-rt90>=0 - not found
===>   mingw-w64-clang-rt90-9.0.1 depends on package: llvm90=9.0.1 - not found
===>   mingw-w64-clang-rt90-9.0.1 depends on package: llvm90=9.0.1 - not found
*** Error code 1

Stop.
make[1]: stopped in /usr/home/russellh/freebsd/ports/devel/mingw-w64-clang-rt
*** Error code 1

Stop.
make: stopped in /usr/home/russellh/freebsd/ports/devel/mingw-w64
russellh@jailbird ~/f/p/d/mingw-w64> clang90 --version
clang version 9.0.1 
Target: x86_64-portbld-freebsd12.0
Thread model: posix
InstalledDir: /usr/local/llvm90/bin

I've done this a few times now and even cleaned and tried different backends (FreeBSD targets, All non-experimental). I'm wondering if LLVM didn't build for the correct architecture? I noted there is no explicit port option for windows binaries (obviously) so I did select all non-experimental backends.

@theron.tarigo_gmail.com, you may know right away what I have done incorrectly? I assume from the language in our email that you were using this port prior to my uploading it. Did you ever install LLVM from a source other than the LLVM90 port? I wonder if LLVM was built with different backend settings and the files have lingered?

Murphy's law dictates that I often find my own answers a few minutes after asking a question. I went back to my original cross compile scripts and found that my "non-ports" version of LLVM10 had been replaced:

russellh@jailbird /s/scripts (master)> /usr/local/bin/i686-w64-mingw32-gcc --version
clang version 9.0.1 
Target: i686-w64-windows-gnu
Thread model: posix
InstalledDir: /usr/local/llvm90/bin

Which means the correct backend did get built and the error I am getting may not be the problem I am having. Or at least, I may have the correct backend. I'm not sure that i686-w64-windows-gnu is correct, I think the triplet is normally i686-w64-mingw32.