blob: 7101addce95268f3b9e67edded4d64d9ccb61a6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/usr/bin/env bash
###
### a simple complement to bild which only deals with launching repls
###
### > repl <target..>
###
### Starts a repl/shell for one or more targets. (Currently, all targets must
### have the same extension for this to work.)
###
### Repls started with this script should bind to `localhost:$PORT`.
help() {
sed -rn 's/^### ?//;T;p' "$0"
}
if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then
help
exit 1
fi
##
set -e
targets=${@:?}
json=$(bild --json ${targets[@]})
langdeps=$(jq --raw-output '.langdeps | join(" ")' <<< $json)
sysdeps=$(jq --raw-output '.sysdeps | join(" ")' <<< $json)
exts=$(jq --raw-output '.namespace.ext' <<< $json | sort | uniq)
flags=()
for lib in ${sysdeps[@]}; do
flags+=(--packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.nixpkgs.${lib}")
done
case $exts in
Hs)
if [ -z ${var+PORT} ]; then
echo "warn: repl: ghci does not support binding to a port"
fi
nix-shell \
"${flags[@]}" \
--packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.ghcWith (h: with h; [$langdeps])" \
--command "ghci -i$BIZ_ROOT -ghci-script $BIZ_ROOT/.ghci ${targets[@]}"
;;
Scm)
for lib in ${langdeps[@]}; do
flags+=(--packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.nixpkgs.guile-${lib}")
done
nix-shell \
"${flags[@]}" \
--packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.nixpkgs.guile_3_0" \
--command "guile -L $BIZ_ROOT -C $BIZ_ROOT/_/int --r7rs --listen=${PORT:-37146}"
;;
Lisp)
nix-shell \
"${flags[@]}" \
--packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.sbclWith (p: with p; [asdf swank $langdeps])" \
--command "sbcl --eval '(require :asdf)' --eval '(require :swank)' --eval '(swank:create-server :port ${PORT:-4005})' --load $targets"
;;
Rs)
nix-shell \
"${flags[@]}" \
--packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.nixpkgs.rustc"
;;
*)
echo "unsupported targets: ${targets[@]}"
exit 1
;;
esac
##
|