ghc-stdin: Compile source code from the standard input

[ bsd3, development, library ] [ Propose Tags ] [ Report a vulnerability ]

A frontend plugin for GHC to compile source code from the standard input.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.1.1, 0.2.0.0
Change log Changelog.md
Dependencies base (>=4.11.0.0 && <5), bytestring, ghc (>=8.4.1), ghc-paths, process, safe, temporary [details]
License BSD-3-Clause
Copyright 2022 Alexey Radkov
Author Alexey Radkov <alexey.radkov@gmail.com>
Maintainer Alexey Radkov <alexey.radkov@gmail.com>
Category Development
Home page http://github.com/lyokha/ghc-stdin
Bug tracker https://github.com/lyokha/ghc-stdin/issues
Source repo head: git clone https://github.com/lyokha/ghc-stdin
Uploaded by lyokha at 2022-08-07T07:19:52Z
Distributions NixOS:0.2.0.0
Downloads 267 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-08-07 [all 1 reports]

Readme for ghc-stdin-0.2.0.0

[back to package description]

GHC frontend plugin GhcStdin

Build Status Hackage

In GHC, it is not possible to read source code from the standard input.

$ echo 'module Main where main = putStrLn "Ok"' | ghc -o simple_ok
ghc-9.2.3: no input files
Usage: For basic information, try the `--help' option.

This plugin makes this possible.

$ echo 'module Main where main = putStrLn "Ok"' | ghc --frontend GhcStdin -ffrontend-opt="-o simple_ok"
[1 of 1] Compiling Main             ( ghc-stdin-d8c31cf0ed893d79/ghc-stdin260612-0.hs, ghc-stdin-d8c31cf0ed893d79/ghc-stdin260612-0.o )
Linking simple_ok ...
$ ./simple_ok
Ok

Notice that GHC flags are passed via -ffrontend-opt in a single string.

Another use case is collecting exported FFI C functions from a module and putting them in a new shared library.

$ export NGX_MODULE_PATH=/var/lib/nginx/x86_64-linux-ghc-9.2.3
$ echo 'module NgxHealthcheck where import NgxExport.Healthcheck ()' | ghc --frontend GhcStdin -ffrontend-opt="-Wall -O2 -dynamic -shared -fPIC -lHSrts_thr-ghc$(ghc --numeric-version) -L$NGX_MODULE_PATH -lngx_healthcheck_plugin -o ngx_healthcheck.so" 
[1 of 1] Compiling NgxHealthcheck   ( ghc-stdin-74de48274545714b/ghc-stdin266454-0.hs, ghc-stdin-74de48274545714b/ghc-stdin266454-0.o )
Linking ngx_healthcheck.so ...

(this is a real-world example taken from nginx-healthcheck-plugin).

Internally, the plugin creates a temporary directory with a temporary source file inside it with the contents read from the standard input. Then it spawns another GHC process to compile this file with the options passed in -ffrontend-opt.