# Introducing ghc-toolchain to GHC

DevFeed: [Introducing ghc-toolchain to GHC](<https://devfeed.tech/articles/introducing-ghc-toolchain-to-ghc-27912.md>)

Original publisher: [Read original article](<http://alt-romes.github.io/posts/2023-10-02-ghc-toolchain.html>)

Published: 2023-10-02T00:00:00Z

Content type: tutorial

Language: en

Sources: [Romes' Musings](<https://devfeed.tech/sources/romes-musings.md>)

Topics: [toolchain](<https://devfeed.tech/topics/toolchain.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Haskell](<https://devfeed.tech/topics/haskell.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>)

Tags: [ci](<https://devfeed.tech/tags/ci.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [toolchain](<https://devfeed.tech/tags/toolchain.md>), [x86](<https://devfeed.tech/tags/x86.md>)

## AI overview

The article introduces ghc-toolchain, a new Haskell-based approach for configuring GHC compilation toolchains. It is intended to replace the existing ./configure logic, make toolchains configurable after GHC installation, improve maintainability and testing, and support GHC's longer-term goal of runtime retargeting for cross-compilation.

## Source excerpt

Contents 1 Compiler Toolchains 2 The runtime-retargetable future of GHC 3 Introducing ghc-toolchain 4 Migration to ghc-toolchain 5 Future work 6 Conclusion GHC, like most high-level language compilers, depends upon a set of tools like assemblers, linkers, and archivers for the production of machine code. Collectively these tools are known as a toolchain and capture a great deal of platform-dependent knowledge. Traditionally, developers generate a ./configure script using the venerable autoconf tool, then users execute this script when they install a GHC binary distribution. The ./configure script determines the location of programs (such as the C compiler) and which options GHC will need to pass them. While this autoconf-centric model of toolchain configuration has served GHC well, it has two key issues: For cross-compiling to a different platform, it would be highly valuable to users if GHC would become a runtime-retargetable compiler (like rustc and go). That is, the user should be able to download a single GHC binary distribution and use it to compile not only for their local machine, but also any other targets that GHC supports. The ten-thousand-line sh file that is GHC's ./configure script has historically been challenging to maintain and test. Modifications to the ./configure script are among the most risky changes routinely made to the compiler, because it is easy to introduce a bug on some specific toolchain configuration, and infeasible to test all possible configurations in CI. To address these issues, we are introducing ghc-toolchain, a new way to configure the toolchain for GHC, which will eventually replace the existing toolchain configuration logic in the ./configure script. Its main goal is to allow new compilation toolchains to be configured for GHC at any point in time, notably after the compiler has been installed. For example, calling ghc-toolchain --triple=x86_64-w64-mingw32 will configure a compilation toolchain on the host machine capable of pr