skeeto / w64devkit

Portable C and C++ Development Kit for x64 (and x86) Windows
The Unlicense
2.99k stars 210 forks source link

Cmake and LLVM #116

Open FinnT730 opened 6 months ago

FinnT730 commented 6 months ago

So I wanted to ask, how difficult is it to add both cmake and LLVM to this, for personal use? Like I don't need anything official, but I just want to know how I can add new things to this. Do I just edit the docker file?

skeeto commented 6 months ago

It should be about as difficult as cross-compiling normally would be. I expect CMake is easy, particularly because it doesn't have any difficult dependencies, but LLVM could be tricky. Yes, you just edit Dockerfile. For example, for CMake:

  1. Add build dependencies to the apt-get line. You probably don't want to bother bootstrapping CMake, and Debian's CMake will do fine, so install it at this point.

  2. Add a curl download URL, alongside the rest, to obtain the source.

  3. (optional) Add the source checksum to SHA256SUMS to validate you got the correct source. Note that the curl command uses --insecure, so HTTPS won't cover transport. You can remove --insecure. It just makes the download step more reliable because it works even it someone's certs are broken (which they sometimes are), and SHA256SUMS makes TLS redundant.

  4. Add a tar line to unpack it, alongside the rest. Sources are all unpacked at once to minimize Docker layering.

  5. Just before "Pack up a release" add a new "paragraph" to build CMake, which starts with WORKDIR to the build directory. Add a RUN command that configures it, probably something like this:

cmake /cmake-$CMAKE_VERSION \ -DCMAKE_INSTALL_PREFIX=/bootstrap \ -DCMAKE_SYSTEM_NAME=Windows \ -DCMAKE_C_COMPILER=$ARCH-gcc \ -DCMAKE_CXX_COMPILER=$ARCH-g++

Then "make -j$(nproc)" and "make install". Use the libiconv build as a guide since it's similar. Advanced note: If I were doing this myself, I might move the prefix deeper in /bootstrap, then place command aliases in /bootstrap/bin/, just as I do with cppcheck. Don't worry about this right now, though. (I presume the CMake installation is "portable" in that it can find its data files relative to its binary.)

Docker caches each step, so if it doesn't work, make a change to address it, and Docker will pick right back up at the failed command. It's a benefit in addition to a hermetic cross-compile environment. If you're really stuck, pay attention to the cache image ID (hint: disable BuildKit because it makes debugging so much harder), and exec a container with bash on that image to have a look around, and even try building manually. It's a kind of interactive debug environment.

LLVM will be similar, but it's complicated, with unfriendly dependencies, so there will surely be complications. For example, I know it requires Python, but CPython doesn't support cross compilation to Windows. I don't know how much that matters, but you may need to also download a MSVC-built CPython from somewhere. Good luck!

Peter0x44 commented 6 months ago

You can look at #71 for a reference on how to add cmake. LLVM is surely harder, but if you don't want to build it, maybe just adding llvm-mingw to your PATH should be okay. Just be wary it has aliases for gcc and cc too, I think.

FinnT730 commented 6 months ago

thank you both for your answers! I will see what I can make of it XD If is it something good, maybe I will share it with you all :P

PNBRQK commented 6 months ago

By the way anything involving Python has trouble on older Windows versions (<=win7) due to Python's discontinuation of support.

Peter0x44 commented 6 months ago

https://releases.llvm.org/3.7.0/tools/clang/docs/ReleaseNotes.html#id13

This release is listed as the last release of clang that supported windows XP. Probably that will cause you some trouble too (if you care about windows XP - not that likely)