unlvsur unlvsur via llvm-dev
2021-Apr-12 20:26 UTC
[llvm-dev] How to build host cross-toolchain from another operating system?
I want to build llvm + clang + lld + compiler-rt on Linux to build a windows host toolchain for example. In GNU toolchain, it is 2 step. 1. Build a target cross toolchain Binutils : --target=x86_64-w64-mingw32 (multilib) MinGW-w64-crt header files: --target=x86_64-w64-mingw32, --host=x86_64-w64-mingw32 GCC, gcc part: --target=x86_64-w64-mingw32 (multilib) MinGW-w64-crt: --target=x86_64-w64-mingw32, --host=x86_64-w64-mingw32 GCC libgcc and libstdc++: --target=x86_64-w64-mingw32 Done 1. Use this target x86_64-w64-mingw32 cross toolchain to build a new host toolchain Binutils : --target=x86_64-w64-mingw32 (multilib) –host= x86_64-w64-mingw32 –disable-gdb GCC: --target=x86_64-w64-mingw32 (multilib) –host= x86_64-w64-mingw32 Then copy the CRT build from the first target cross toolchain in this host toolchain. Then we can use this new host toolchain and use it to build programs. However, I try the same thing with llvm, I could not do it. cmake will do stupid checks to prevent me to just do the 2nd part. I could not even use clang –target=x86_64-windows-gnu -fuse-ld=lld to build a host GCC since it fails to build gmp, only GCC could build that. I think this is extremely important as a cross compiler. You want to bootstrap another toolchain from this platform to a new platform to make the new platform self host. However, I guess it is very hard for LLVM, since it requires python and all kinds of other dependencies which the target cross toolchain does not provide. The largest issue is clearly cmake, which prevents cross compilation. I do not know what is the solution here. Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210412/fa4184eb/attachment.html>
Jonathan Smith via llvm-dev
2021-Apr-13 17:27 UTC
[llvm-dev] How to build host cross-toolchain from another operating system?
This is very do-able. I often cross-compile a Windows version of the toolchain from a Linux build machine, but I admittedly don't use MinGW in the process -- I use MSVC and Windows SDK headers and libraries I've copied to the Linux machine. LLVM includes a WinMsvc.cmake toolchain script to help facilitate this, and I make extensive use of it in my own toolchain-automating project (https://github.com/jvstech/llvm-toolchain) because it's so much easier [for me] than trying to build with MinGW. The only thing I don't build is Compiler-RT -- not because it can't be done, but because the MSVC and Windows SDK provide the equivalent functionality already. It does require a bit more configuration than what I perform in my project, but I've done it before. If you'd like to stick with MinGW, another project I recommend is https://github.com/mstorsjo/llvm-mingw -- which I have used in the past, as well. Additionally, there is https://github.com/martell/mingw-w64-clang which is similar, but hasn't been updated in a while. Regardless, I've also used this project as a reference for how to do manually what you're trying to accomplish. Bottom line: yes, it can be a pain, but it can be and has been done before. - Jon On Tue, Apr 13, 2021 at 12:54 PM unlvsur unlvsur via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > I want to build llvm + clang + lld + compiler-rt on Linux to build a windows host toolchain for example. > > > > > > In GNU toolchain, it is 2 step. > > > > Build a target cross toolchain > > Binutils : --target=x86_64-w64-mingw32 (multilib) > > MinGW-w64-crt header files: --target=x86_64-w64-mingw32, --host=x86_64-w64-mingw32 > > GCC, gcc part: --target=x86_64-w64-mingw32 (multilib) > > MinGW-w64-crt: --target=x86_64-w64-mingw32, --host=x86_64-w64-mingw32 > > GCC libgcc and libstdc++: --target=x86_64-w64-mingw32 > > Done > > Use this target x86_64-w64-mingw32 cross toolchain to build a new host toolchain > > Binutils : --target=x86_64-w64-mingw32 (multilib) –host= x86_64-w64-mingw32 –disable-gdb > > GCC: --target=x86_64-w64-mingw32 (multilib) –host= x86_64-w64-mingw32 > > > > Then copy the CRT build from the first target cross toolchain in this host toolchain. > > Then we can use this new host toolchain and use it to build programs. > > > > However, I try the same thing with llvm, I could not do it. cmake will do stupid checks to prevent me to just do the 2nd part. > > I could not even use clang –target=x86_64-windows-gnu -fuse-ld=lld to build a host GCC since it fails to build gmp, only GCC could build that. > > > > > > > > I think this is extremely important as a cross compiler. You want to bootstrap another toolchain from this platform to a new platform to make the new platform self host. > > However, I guess it is very hard for LLVM, since it requires python and all kinds of other dependencies which the target cross toolchain does not provide. > > > > The largest issue is clearly cmake, which prevents cross compilation. > > > > I do not know what is the solution here. > > > > > > Sent from Mail for Windows 10 > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev