Skip to content

Instantly share code, notes, and snippets.

@DavidEGrayson
Last active November 27, 2018 02:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidEGrayson/d5ca447cca1ea23d5adca2f353dbb67a to your computer and use it in GitHub Desktop.
Save DavidEGrayson/d5ca447cca1ea23d5adca2f353dbb67a to your computer and use it in GitHub Desktop.

Building a mingw-w64 GCC cross-compiler with nixcrpkgs: instructions for Terry, October 2018

  1. Install Nix, the functional package manager. You'll need Linux (but macOS might work too).
  2. Make sure you have at least 4 GB of free space available for /tmp and a few GB of free space available for /nix.
  3. To get my recipes, run: git clone https://github.com/DavidEGrayson/nixcrpkgs && cd nixcrpkgs && git checkout 4f7b11d That commit is the current tip of the dev/david/2019 branch.
  4. To build a i686-w64-mingw32 C/C++ cross-compiling toolchain and a hello world program, run: nix-build -A win32.hello
  5. To build Qt and its examples, run: nix-build -A win32.qt.examples
  6. To just build the toolchain itself, run: nix-build -A win32.gcc
  7. To start a shell where you can easily use the toolchain, run: nix-shell -A win32.hello

Whenever you run a nix-build or nix-shell command that requires the compiler, it will be built if it has not been built before. You can edit the patches, shell scripts, and other parts of nixcrpkgs and Nix will automatically know what parts of the compiler need to be rebuilt the next time you run one of those commands. Build results are cached, so it is quick and easy to switch between different versions of the compiler built this way.

After running nix-build, there is a symbolic link named result in the current directory that points to the thing you built. So run commands like find result/ to inspect its contents and try it out.

I think building GCC and then building Qt takes a total of about 2 hours on my computer.

Commit 4f7b11d of my repository uses GCC 7.3.0 and the proposed patch from GCC bug 58732 comment #20.

If you want to experiment with patching GCC, you need to edit the list of patches in mingw-w64/gcc/default.nix and/or edit the files they are referring to in the same directory.

If you want to use a different version of GCC, edit the src url in mingw-w64/gcc/default.nix, then modify the sha256 field on the line below slightly (e.g. reduce one of the numbers to a lower number). Then when you get an error about a hash mismatch from nix-build, copy the correct hash into the sha256 field. (There are smoother ways to do this but I find this to be pretty fast.) I couldn't get snapshot versions to build this way, but I was able to get GCC 8.2.0 to build earlier.

@markmeson
Copy link

Hello!
I tried using nix-build -A win32.qt.examples and I ran into this error:

graphite-isl-ast-to-gimple.c:98:7: error 'isl_id_free' was not declared in this scope

Any idea why this happens?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment