Home

Awesome

GHC whole program compiler project

The project consists of GHC wpc-plugin and the corresponding External STG IR and tooling.

The wpc-plugin is a compiler plugin for GHC 9.6 or newer. It exports the STG IR (.modpak) for the compiled modules and linker metadata (.ghc_stgapp) at application link time.

<img height="350" src="https://user-images.githubusercontent.com/877489/114280753-0d311300-9a3b-11eb-8d50-facad35f0e9a.png"/>

Presentation video

Readings

External STG tools (Ext-STG)

Why?

Build

external stg tooling

stack install

wpc-plugin

  1. Install zip-cmd, a simple CLI for the zip package
    cabal install zip-cmd
    
  2. Compile the wpc-plugin The wpc-plugin has a speparate stack.yaml because it uses the plugin API of GHC 9.6.1.
    cd wpc-plugin
    stack build
    
  3. Find the built libwpc-plugin.[so|dylib|dll]
    ln -s `find . -type f -name 'libwpc-plugin.so' -o -name 'libwpc-plugin.dylib' -o -name 'libwpc-plugin.dll' | head -1`
    

Usage

It is required to use GHC 9.6.1.

cabal

Add the following lines to your project's cabal.project:

package *
  ghc-options:
    -fplugin-trustworthy
    -fplugin-library=PATH_TO/libwpc-plugin.so;wpc-plugin-unit;WPC.Plugin;[]

stack

Add the following lines to your project's stack.yaml:

apply-ghc-options: everything
ghc-options:
  "$everything":
      -fplugin-trustworthy
      -fplugin-library=PATH_TO/libwpc-plugin.so;wpc-plugin-unit;WPC.Plugin;[]

TODO

Ext-STG IR

UnZip with Zstd support

The .modpak and .fullpak files use Zstd compression method that was introduced in the Zip 6.3.8 standard in 2020.
The GHC-WPC tooling can handle Zstd zip files out of the box.
But if you'd like to unpack the .modpak and .fullpak files manually then you'll need an unzip version with Zstd support.
https://github.com/csabahruska/unzip-zstd