From 6107f8178e26ada67e5d5ec60501e24528b3db56 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 3 Oct 2023 22:22:45 -0400 Subject: Add rundeps feature to bild This allows me to specify runtime dependencies, not just system or language deps. --- Biz/Bild.hs | 20 +++++++++++++++----- Biz/Bild.nix | 13 ++++++++++++- Biz/Bild/Builder.nix | 8 +++++++- Biz/Bild/Meta.hs | 18 ++++++++++++++---- Biz/Ide/repl | 8 +++++++- Biz/Lint.hs | 20 +++++++++----------- 6 files changed, 64 insertions(+), 23 deletions(-) diff --git a/Biz/Bild.hs b/Biz/Bild.hs index c1dfefd..d8cdc6f 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -324,7 +324,9 @@ data Target = Target -- | Flags and arguments passed to 'Compiler' when building compilerFlags :: [Text], -- | Wrapper script (if necessary) - wrapper :: Maybe Text + wrapper :: Maybe Text, + -- | Runtime dependences + rundeps :: Set Meta.Run } deriving (Show, Generic, Aeson.ToJSON) @@ -490,6 +492,7 @@ analyze hmap ns = case Map.lookup ns hmap of out = pout, packageSet = "python.packages", mainModule = Namespace.toModule namespace, + rundeps = prun, .. } |> Just @@ -513,14 +516,15 @@ analyze hmap ns = case Map.lookup ns hmap of outPath = outToPath pout, -- implement detectCImports, then I can fill this out srcs = Set.empty, + rundeps = prun, .. } |> Just |> pure Namespace.Hs -> contentLines - |> Meta.detectOut (Meta.out "--") - |> \out -> + |> Meta.detectAll "--" + |> \Meta.Parsed {..} -> detectHaskellImports hmap contentLines +> \(langdeps, srcs) -> Target { builder = "haskell", @@ -539,7 +543,7 @@ analyze hmap ns = case Map.lookup ns hmap of "--make", "$CODEROOT" quapath ] - ++ case out of + ++ case pout of Meta.Bin o -> [ "-main-is", Namespace.toHaskellModule namespace, @@ -549,7 +553,9 @@ analyze hmap ns = case Map.lookup ns hmap of _ -> [] |> map Text.pack, sysdeps = Meta.detect (Meta.sys "--") contentLines, - outPath = outToPath out, + outPath = outToPath pout, + rundeps = prun, + out = pout, .. } |> Just @@ -579,6 +585,7 @@ analyze hmap ns = case Map.lookup ns hmap of outPath = outToPath out, -- add local src imports to detectLispImports, then i can fill this out srcs = Set.empty, + rundeps = Set.empty, .. } Namespace.Nix -> @@ -602,6 +609,7 @@ analyze hmap ns = case Map.lookup ns hmap of packageSet = "", mainModule = Namespace.toModule namespace, builder = "base", + rundeps = Set.empty, .. } |> Just @@ -644,6 +652,7 @@ analyze hmap ns = case Map.lookup ns hmap of |> Text.pack |> Just ), + rundeps = prun, .. } |> Just @@ -674,6 +683,7 @@ analyze hmap ns = case Map.lookup ns hmap of outPath = outToPath pout, -- implement detectRustImports srcs = Set.empty, + rundeps = prun, .. } |> Just diff --git a/Biz/Bild.nix b/Biz/Bild.nix index c7c3207..1e4bcf8 100644 --- a/Biz/Bild.nix +++ b/Biz/Bild.nix @@ -46,7 +46,18 @@ in nixpkgs // { bild = rec { c.packages = lib.attrsets.getAttrs (import ./Bild/Deps/C.nix) nixpkgs.pkgs; # expose some packages for inclusion in os/image builds - pkgs = with nixpkgs.pkgs; { inherit git; }; + pkgs = with nixpkgs.pkgs; { + inherit + black + deadnix + git + hlint + indent + ormolu + ruff + shellcheck + ; + }; # this is needed to do builds without calling out to nix, remove this when I # switch to all-nix builds diff --git a/Biz/Bild/Builder.nix b/Biz/Bild/Builder.nix index 2ed3dd1..959d176 100644 --- a/Biz/Bild/Builder.nix +++ b/Biz/Bild/Builder.nix @@ -51,6 +51,12 @@ let else lib.attrsets.attrVals target.sysdeps pkgs; + rundeps_ = + if isEmpty target.rundeps then + [] + else + lib.attrsets.attrVals target.rundeps bild.pkgs; + CODEROOT = "."; builders = { @@ -73,7 +79,7 @@ let installPhase = '' install -D ${name} $out/bin/${name} wrapProgram $out/bin/${name} \ - --prefix PATH : ${lib.makeBinPath sysdeps_} + --prefix PATH : ${lib.makeBinPath rundeps_} ''; }; diff --git a/Biz/Bild/Meta.hs b/Biz/Bild/Meta.hs index 5549cb3..ad5fdd6 100644 --- a/Biz/Bild/Meta.hs +++ b/Biz/Bild/Meta.hs @@ -14,14 +14,17 @@ import qualified Text.Regex.Applicative as Regex -- | A third-party dependency. This gets mapped to some name in nixpkgs, -- prefixed by package set like @haskellPackages@ or --- @python3Packages@. Currently this prefix is implicit, but it should be added --- here as part of a tuple or something. +-- @python3Packages@. type Dep = String -- | This is a system-level requirement, the string gets mapped to a name in --- nixpkgs at the top level, like @pkgs.thing@. If I add the package set prefix to 'Dep', then this can just become literally @(Sys, "thing")@. +-- nixpkgs at the top level, like @pkgs.thing@. type Sys = String +-- | A run-time dependency. This is some executable that will be placed on +-- @PATH@. This gets selected from @bild.pkgs@, so it must be exported there. +type Run = String + -- | An arbitrary compiler argument that may get added to the compilation -- command. Should be used sparingly, and not all builds will support this. type Arg = String @@ -40,7 +43,8 @@ data Parsed = Parsed { pdep :: Set Dep, parg :: Set Arg, pout :: Out, - psys :: Set Sys + psys :: Set Sys, + prun :: Set Run } detect :: Ord a => Regex.RE Char a -> [Text] -> Set a @@ -69,6 +73,7 @@ detectAll m cl = Parsed {..} pdep = detect_ dep psys = detect_ sys parg = detect_ arg + prun = detect_ run dep :: [Char] -> Regex.RE Char Dep dep comment = @@ -96,3 +101,8 @@ arg :: [Char] -> Regex.RE Char Arg arg comment = Regex.string (comment ++ " : arg ") *> Regex.many Regex.anySym + +run :: [Char] -> Regex.RE Char Run +run comment = + Regex.string (comment ++ " : run ") + *> Regex.many Regex.anySym diff --git a/Biz/Ide/repl b/Biz/Ide/repl index 7230edd..b10f0f0 100755 --- a/Biz/Ide/repl +++ b/Biz/Ide/repl @@ -28,14 +28,20 @@ fi json=$(bild --json ${targets[@]}) langdeps=$(jq --raw-output '.[].langdeps | join(" ")' <<< $json) sysdeps=$(jq --raw-output '.[].sysdeps | join(" ")' <<< $json) + rundeps=$(jq --raw-output '.[].rundeps | join(" ")' <<< $json) exts=$(jq --raw-output '.[].namespace.ext' <<< $json | sort | uniq) packageSet=$(jq --raw-output '.[].packageSet' <<< $json) module=$(jq --raw-output '.[].mainModule' <<< $json) BILD="(import ${CODEROOT:?}/Biz/Bild.nix {})" - for lib in ${sysdeps[@]}; do + for lib in ${sysdeps[@]} + do flags+=(--packages "$BILD.pkgs.${lib}") flags+=(--packages "$BILD.pkgs.pkg-config") done + for lib in ${rundeps[@]} + do + flags+=(--packages "$BILD.pkgs.${lib}") + done case $exts in C) flags+=(--packages "$BILD.pkgs.gcc") diff --git a/Biz/Lint.hs b/Biz/Lint.hs index 62ddba7..13150cc 100644 --- a/Biz/Lint.hs +++ b/Biz/Lint.hs @@ -5,18 +5,16 @@ {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE NoImplicitPrelude #-} --- : out lint --- --- these are actually runtime deps, but bild doesn't (yet) distinguish between --- rundeps and sysdeps: +-- | Global linter. -- --- : sys ormolu --- : sys hlint --- : sys black --- : sys ruff --- : sys deadnix --- : sys shellcheck --- : sys indent +-- : out lint +-- : run ormolu +-- : run hlint +-- : run black +-- : run ruff +-- : run deadnix +-- : run shellcheck +-- : run indent module Biz.Lint (main) where import Alpha -- cgit v1.2.3