Skip to content

Commit ecdd48f

Browse files
Attempt to update packaging (#54)
This pull request updates the `pkg-darwin` recipe. This pull request also attempts to provide a better way to provision a Haskell package environment, but ends up documenting the current lack of success with GHC [package environments][package-env] instead. [package-env]: https://ghc.gitlab.haskell.org/ghc/doc/users_guide/packages.html#package-environments
2 parents fa3e1ce + 4e5c5bd commit ecdd48f

File tree

7 files changed

+112
-42
lines changed

7 files changed

+112
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ dist-newstyle/
1010
*.sublime-workspace
1111
node_modules
1212
/build
13+
/haskell/vendor/

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "HyperHaskell",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"main": "src/main.js",
55
"devDependencies": {
66
"electron": "^31.4.0"

app/src/interpreter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ exports.init = () => {
137137
})
138138
ghc.on('exit', (code, signal) => {
139139
// FIXME: Report a more useful error here.
140-
// Unfortunatley, we can't read `stderr` once the process is dead.
140+
// Unfortuntaley, we can't read `stderr` once the process is dead.
141141
// Perhaps cache it in some way?
142+
// Idea: The interpreter executable can print the error to
143+
// the pipeFD descriptor, as opposed to stdout
142144
error = code ? code.toString() : '0';
143145
console.log('Interpreter stopped (Exit code ' + error + ')')
144146
if (spawning) { doReady(error) }

docs/misc.md

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
Misc
2-
=====
3-
4-
This documentation collects useful miscellanea.
5-
6-
Testing POST requests
7-
---------------------
2+
====
83

9-
The `curl` utility is able to send POST requests and receive a response. Example:
10-
11-
$ curl --data "query=Prelude" http://localhost:8024/setImports
12-
{"status":"ok"}
13-
$ curl --data "query=3*4::Int" http://localhost:8024/eval
14-
{"status":"ok","value":"12"}
15-
16-
Note that `curl` will not, by default, add a newline to the end of the received request; this may screw up the terminal. However, the option `-w '\n'` will add said newline. To make it a default, use the `~/.curlrc` file [[StackOverflow]][12849584].
17-
18-
echo '-w "\n"' >> ~/.curlrc
19-
20-
[12849584]: http://stackoverflow.com/questions/12849584/automatically-add-newline-at-end-of-curl-response-body
4+
This document records snippets of information that are useful for developing HyperHaskell.
215

6+
Haskell
7+
=======
228

239
How does GHCi evaluate expressions on the prompt?
2410
-------------------------------------------------
@@ -72,17 +58,6 @@ Fortunately, a Google search reveals that the relevant code is actually containe
7258
In other words, GHC tries to typecheck the expression at the prompt in different contexts, and uses the first plan that works.
7359

7460

75-
How to create an .icns file on OS X?
76-
------------------------------------
77-
78-
Application icons on OS X are stored in `.icns` files. There is a command line utility called `iconutil` that is supposed to be able to create such files, but unfortunately, it only creates garbled icons for me. No idea why. Online converters seem to work fine.
79-
80-
How to remove color profiles from images on OS X?
81-
-------------------------------------------------
82-
83-
sips -d profile --deleteColorManagementProperties *filename*
84-
85-
8661
Haskell path information
8762
------------------------
8863

@@ -122,8 +97,10 @@ For my setup, a minimal environment is given by
12297
HOME=/Users/hgz \
12398
stack exec -- hyper-haskell-server
12499

100+
JavaScript
101+
==========
125102

126-
Node.js -- External Processes
103+
Node.js External Processes
127104
-----------------------------
128105

129106
We can run external processes and read their `stdout`. Example:
@@ -135,4 +112,76 @@ We can run external processes and read their `stdout`. Example:
135112
env : newEnv(),
136113
}).stdout.trim()
137114

138-
Note that most UNIX utilities will traditionally emit a newline at the end of the output, and we use `trim()` to get rid of it.
115+
Note that most UNIX utilities will traditionally emit a newline at the end of the output, and we use `trim()` to get rid of it.
116+
117+
118+
Cabal and GHC package environments
119+
----------------------------------
120+
121+
A working installation of the HyperHaskell interpreter backend consists of two things:
122+
123+
1. The interpreter executable `hyper-haskell-server`, linked against a compilation A of the `hyper` package.
124+
2. A package database that contains this compilation A of the `hyper` package. This database needs to be in scope when running the interpreter excutable.
125+
126+
How to provision these?
127+
128+
As of December 2024, it seemed like GHC [package environments][package-env] might be useful to provision the above setup, but unfortunately, this does not work.
129+
130+
The following command will install the package `hyper` into the package environment `PKG_ENV`:
131+
132+
```
133+
cabal install --lib hyper --package-env ${PKG_ENV}
134+
```
135+
136+
The following command will install `hyper-haskell-server` into the directory `DIR` while referring to packages from the package environment `PKG_ENV`:
137+
138+
```
139+
cabal install hyper-haskell-server --package-env ${PKG_ENV} --installdir=${DIR}
140+
```
141+
142+
By using the same package environment `PKG_ENV`, we make sure that both the interpreter exectuable and the package environment refer to the same compilation of the `hyper` package.
143+
144+
Unfortunately, the two commands above do not produce a working setup: `cabal install --lib` does [not install dependencies][cabal-issue-6263], and the GHC API as used by `hyper-haskell-server` is unable to handle that; I get error messages of the form
145+
146+
```
147+
cannot satisfy -package-id hypr-xtr-0.2.0.1-71ddd09d:
148+
hypr-xtr-0.2.0.1-71ddd09d is unusable due to missing dependencies:
149+
[…]
150+
```
151+
152+
(The "missing dependency" appears to be present in the package database, and `ghci` is able to handle the situation, but the use of the GHC API by `hyper-haskell-server` is not.)
153+
154+
To summarize, as of December 2024, I can't get GHC package environments to yield a working installation of the HyperHaskell interpreter backend.
155+
156+
[package-env]: https://ghc.gitlab.haskell.org/ghc/doc/users_guide/packages.html#package-environments
157+
[cabal-issue-6263]: https://github.com/haskell/cabal/issues/6263
158+
159+
160+
Tools
161+
=====
162+
163+
Testing POST requests
164+
---------------------
165+
166+
The `curl` utility is able to send POST requests and receive a response. Example:
167+
168+
$ curl --data "query=Prelude" http://localhost:8024/setImports
169+
{"status":"ok"}
170+
$ curl --data "query=3*4::Int" http://localhost:8024/eval
171+
{"status":"ok","value":"12"}
172+
173+
Note that `curl` will not, by default, add a newline to the end of the received request; this may screw up the terminal. However, the option `-w '\n'` will add said newline. To make it a default, use the `~/.curlrc` file [[StackOverflow]][12849584].
174+
175+
echo '-w "\n"' >> ~/.curlrc
176+
177+
[12849584]: http://stackoverflow.com/questions/12849584/automatically-add-newline-at-end-of-curl-response-body
178+
179+
How to create an .icns file on OS X?
180+
------------------------------------
181+
182+
Application icons on OS X are stored in `.icns` files. There is a command line utility called `iconutil` that is supposed to be able to create such files, but unfortunately, it only creates garbled icons for me. No idea why. Online converters seem to work fine.
183+
184+
How to remove color profiles from images on OS X?
185+
-------------------------------------------------
186+
187+
sips -d profile --deleteColorManagementProperties *filename*

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
pkgs.pkg-config
4242
pkgs.zlib
4343

44+
pkgs.nodejs_22
4445
pkgs.electron
4546
] ++ lib.optionals pkgs.stdenv.isDarwin ([
4647
pkgs.darwin.apple_sdk.frameworks.Cocoa

haskell/hyper-haskell-server/src/HyperHaskell/Interpreter.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE GADTSyntax #-}
33
{-# LANGUAGE ExistentialQuantification #-}
44
{-# LANGUAGE RankNTypes #-}
5+
{-# LANGUAGE ScopedTypeVariables #-}
56

67
module HyperHaskell.Interpreter
78
( -- * Interpreter session
@@ -299,6 +300,11 @@ newInterpreter writeReady = do
299300
putMVar evalThreadId =<< myThreadId
300301
-- NOTE: The failure branch of `catch` will `mask` asynchronous exceptions.
301302
let go = forever $ handler `catch` (\UserInterrupt -> pure ())
302-
void $ Hint.runInterpreter $ liftIO writeReady >> go
303+
(e :: Either Hint.InterpreterError ()) <- Hint.runInterpreter $ do
304+
liftIO writeReady
305+
go
306+
case e of
307+
Left e' -> print e'
308+
Right _ -> pure ()
303309

304310
pure (Hint run cancel, interpreterLoop)

justfile

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
ELECTRON := "electron"
22

3-
STACK := "stack --stack-yaml=haskell/stack.yaml --install-ghc"
4-
53
VERSION := "0.2.3.0"
64

75
######################################################################
@@ -22,14 +20,27 @@ build:
2220
######################################################################
2321
# Release targets
2422

25-
DIR_DARWIN := "build/HyperHaskell-darwin-x64"
26-
DIR_WIN32 := "build\\HyperHaskell-win32-x64"
23+
APP_NAME := "HyperHaskell"
24+
25+
DIR_DARWIN := "build/" + APP_NAME + "-darwin-arm64"
26+
DIR_WIN32 := "build\\" + APP_NAME + "-win32-x64"
2727

28+
# You need to call
29+
#
30+
# npm install --save-dev @electron/packager
31+
# npm install electron --save-dev
32+
#
33+
# before the following recipe has a chance of working
2834
pkg-darwin:
29-
mkdir -p build && electron-packager app \
30-
--out=build/ --overwrite \
31-
--platform=darwin --icon=resources/icons/icon.icns \
32-
--extend-info=resources/macOS-Info.plist \
35+
mkdir -p build \
36+
&& npx @electron/packager \
37+
app \
38+
--out=build \
39+
--overwrite \
40+
--platform=darwin \
41+
--arch=arm64 \
42+
--icon=resources/icons/icon.icns \
43+
--extend-info=resources/macOS-Info.plist \
3344
&& rm {{DIR_DARWIN}}/LICENSE \
3445
&& cp resources/LICENSE.electron.txt {{DIR_DARWIN}}/LICENSE.electron.txt \
3546
&& rm {{DIR_DARWIN}}/version

0 commit comments

Comments
 (0)