From b8cdef27e76d37f8857e0f93e427eb9119ffb153 Mon Sep 17 00:00:00 2001
From: Ben Sima <ben@bsima.me>
Date: Thu, 3 Aug 2023 22:39:27 -0400
Subject: Add packageSet argument

---
 Biz/Bild.hs  | 10 +++++++++-
 Biz/Ide/repl |  5 +++--
 2 files changed, 12 insertions(+), 3 deletions(-)

(limited to 'Biz')

diff --git a/Biz/Bild.hs b/Biz/Bild.hs
index 5c28964..a538f98 100644
--- a/Biz/Bild.hs
+++ b/Biz/Bild.hs
@@ -245,6 +245,8 @@ data Target = Target
     namespace :: Namespace,
     -- | Absolute path to file
     path :: FilePath,
+    -- | Name of the packageset in Bild.nix to pull langdeps from
+    packageSet :: Text,
     -- | Language-specific dependencies, required during compilation
     langdeps :: Set Meta.Dep,
     -- | Local source files on which this target depends
@@ -424,6 +426,7 @@ analyze hmap ns = case Map.lookup ns hmap of
                 compiler = Gcc,
                 builder = Local user,
                 out = pout,
+                packageSet = "", -- none, or maybe I should make cPackages?
                 compilerFlags =
                   concat
                     [ [o, dir, str absPath]
@@ -450,6 +453,7 @@ analyze hmap ns = case Map.lookup ns hmap of
                   { builder = Local user,
                     wrapper = Nothing,
                     compiler = Ghc,
+                    packageSet = "ghcWith",
                     compilerFlags =
                       [ "-Werror",
                         "-i$src",
@@ -484,6 +488,7 @@ analyze hmap ns = case Map.lookup ns hmap of
                   { sysdeps = Set.empty,
                     wrapper = Nothing,
                     compiler = Sbcl,
+                    packageSet = "sbclWith",
                     compilerFlags =
                       map
                         Text.pack
@@ -517,6 +522,7 @@ analyze hmap ns = case Map.lookup ns hmap of
                 out = Meta.None,
                 outPath = outToPath Meta.None,
                 srcs = Set.singleton absPath,
+                packageSet = "",
                 ..
               }
               |> Just
@@ -527,6 +533,7 @@ analyze hmap ns = case Map.lookup ns hmap of
               { langdeps = pdep,
                 sysdeps = psys,
                 compiler = Guile,
+                packageSet = "guilePackages",
                 compilerFlags =
                   [ "compile",
                     "--r7rs",
@@ -562,6 +569,7 @@ analyze hmap ns = case Map.lookup ns hmap of
           Meta.detectOut (Meta.out "//") contentLines |> \out ->
             Target
               { langdeps = Set.empty,
+                packageSet = "rustPackages",
                 wrapper = Nothing,
                 sysdeps = Set.empty,
                 compiler = Rustc,
@@ -835,7 +843,7 @@ nixBuild loud Target {..} =
           args =
             [ argstr "srcs" <| unwords <| map str <| (root </> path) : Set.toList srcs,
               argstr "root" <| str root,
-              argstr "packageSet" "ghcWith",
+              argstr "packageSet" packageSet,
               (argstr "langDeps" <| unwords <| map str <| Set.toList langdeps) <|> mempty,
               argstr "name" <| str <| outname out,
               argstr "main" <| str path,
diff --git a/Biz/Ide/repl b/Biz/Ide/repl
index 3ed9fa1..0d0a08d 100755
--- a/Biz/Ide/repl
+++ b/Biz/Ide/repl
@@ -29,6 +29,7 @@ fi
   langdeps=$(jq --raw-output '.[].langdeps | join(" ")' <<< $json)
   sysdeps=$(jq --raw-output '.[].sysdeps | join(" ")' <<< $json)
   exts=$(jq --raw-output '.[].namespace.ext' <<< $json | sort | uniq)
+  packageSet=$(jp --raw-output '.[].packageSet' <<< $json)
   BILD="(import ${BIZ_ROOT:?}/Biz/Bild.nix {})"
   for lib in ${sysdeps[@]}; do
     flags+=(--packages "$BILD.private.nixpkgs.${lib}")
@@ -43,7 +44,7 @@ fi
       if [ -z ${var+PORT} ]; then
         echo "warn:  repl:  ghci does not support binding to a port"
       fi
-      flags+=(--packages "$BILD.private.ghcWith (h: with h; [$langdeps])")
+      flags+=(--packages "$BILD.private.$packageSet (h: with h; [$langdeps])")
       command=${CMD:-"ghci -i${BIZ_ROOT:?} -ghci-script ${BIZ_ROOT:?}/.ghci ${targets[@]}"}
       ;;
     Scm)
@@ -54,7 +55,7 @@ fi
       command=${CMD:-"guile -L ${BIZ_ROOT:?} -C ${BIZ_ROOT:?}/_/int --r7rs --listen=${PORT:-37146}"}
       ;;
     Lisp)
-      flags+=(--packages "$BILD.private.sbclWith (p: with p; [asdf swank $langdeps])")
+      flags+=(--packages "$BILD.private.$packageSet (p: with p; [asdf swank $langdeps])")
       command=${CMD:-"sbcl --eval '(require :asdf)' --eval '(require :swank)' --eval '(swank:create-server :port ${PORT:-4005})' --load $targets"}
       ;;
     Rs)
-- 
cgit v1.2.3