Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lyokha/ghc-stdin
A frontend plugin for GHC to compile source code from the standard input
https://github.com/lyokha/ghc-stdin
frontend ghc haskell plugin
Last synced: 26 days ago
JSON representation
A frontend plugin for GHC to compile source code from the standard input
- Host: GitHub
- URL: https://github.com/lyokha/ghc-stdin
- Owner: lyokha
- License: bsd-3-clause
- Created: 2022-08-03T15:55:38.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-29T20:29:07.000Z (11 months ago)
- Last Synced: 2024-09-30T09:04:02.045Z (about 1 month ago)
- Topics: frontend, ghc, haskell, plugin
- Language: Haskell
- Homepage:
- Size: 15.6 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
GHC frontend plugin GhcStdin
============================[![Build Status](https://github.com/lyokha/ghc-stdin/workflows/CI/badge.svg)](https://github.com/lyokha/ghc-stdin/actions?query=workflow%3ACI)
[![Hackage](https://img.shields.io/hackage/v/ghc-stdin.svg?label=hackage%20%7C%20ghc-stdin&logo=haskell&logoColor=%239580D1)](https://hackage.haskell.org/package/ghc-stdin)In GHC, it is not possible to read source code from the standard input.
```ShellSession
$ 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.
```ShellSession
$ 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.```ShellSession
$ export NGX_MODULE_PATH=/var/lib/nginx/x86_64-linux-ghc-$(ghc --numeric-version)
$ echo 'module NgxHealthcheck where import NgxExport.Healthcheck ()' | ghc --frontend GhcStdin -ffrontend-opt="-Wall -O2 -dynamic -shared -fPIC -flink-rts -threaded -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](https://github.com/lyokha/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*.