From 95df71e6ce9ec3887f7e88accda7c9b29c538d86 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 25 Jul 2022 10:25:51 -0400 Subject: Add basic support for building C code --- Biz/Bild.hs | 79 +++++++++++++++++++++++++++++++++++++++--------------- Biz/Bild.nix | 1 + Biz/Bild/Example.c | 6 +++++ Biz/Namespace.hs | 6 +++-- 4 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 Biz/Bild/Example.c diff --git a/Biz/Bild.hs b/Biz/Bild.hs index d1d3d78..58bf8e6 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -202,6 +202,7 @@ type Out = String data Compiler = Copy + | Gcc | GhcLib | GhcExe | Guile @@ -230,20 +231,29 @@ data Target = Target -- | We can't build everything yet... isBuildableNs :: Namespace -> Bool -isBuildableNs (Namespace _ Namespace.Hs) = True -isBuildableNs (Namespace _ Namespace.Lisp) = True -isBuildableNs (Namespace _ Namespace.Scm) = True -isBuildableNs (Namespace _ Namespace.Rs) = True -isBuildableNs ns - | ns `elem` nixTargets = True - | otherwise = False +isBuildableNs = \case + (Namespace _ Namespace.C) -> True + (Namespace _ Namespace.Css) -> False + (Namespace _ Namespace.Hs) -> True + (Namespace _ Namespace.Json) -> False + (Namespace _ Namespace.Keys) -> False + (Namespace _ Namespace.Lisp) -> True + (Namespace _ Namespace.Md) -> False + (Namespace _ Namespace.None) -> False + (Namespace _ Namespace.Py) -> False + (Namespace _ Namespace.Sh) -> False + (Namespace _ Namespace.Scm) -> True + (Namespace _ Namespace.Rs) -> True + (Namespace path Namespace.Nix) + | path `elem` nixTargets -> True + | otherwise -> False where nixTargets = - [ Namespace ["Biz", "Pie"] Namespace.Nix, - Namespace ["Biz", "Que"] Namespace.Nix, - Namespace ["Biz", "Cloud"] Namespace.Nix, - Namespace ["Biz", "Dev"] Namespace.Nix, - Namespace ["Biz", "Dragons", "Analysis"] Namespace.Nix + [ ["Biz", "Pie"], + ["Biz", "Que"], + ["Biz", "Cloud"], + ["Biz", "Dev"], + ["Biz", "Dragons", "Analysis"] ] -- | Emulate the *nix hierarchy in the cabdir. @@ -318,7 +328,39 @@ analyze path = do Just Text.pack host <- Text.pack "@localhost", + .. + } case ext of + -- basically we don't support building these + Namespace.Css -> pure nada + Namespace.Json -> pure nada + Namespace.Keys -> pure nada + Namespace.Md -> pure nada + Namespace.None -> pure nada + Namespace.Py -> pure nada + Namespace.Sh -> pure nada + Namespace.C -> do + pure + Target + { langdeps = Set.empty, + sysdeps = Set.empty, + compiler = Gcc, + out = + contentLines + /> Text.unpack + /> Regex.match (metaOut "//") + |> catMaybes + |> head, + builder = user <> "@localhost", + .. + } Namespace.Hs -> do langdeps <- detectImports namespace contentLines let out = @@ -404,16 +446,6 @@ analyze path = do builder = user <> "@localhost", .. } - _ -> - pure - Target - { langdeps = Set.empty, - sysdeps = Set.empty, - compiler = Copy, - out = Nothing, - builder = user <> "@localhost", - .. - } ghcPkgFindModule :: Set String -> String -> IO (Set String) ghcPkgFindModule acc m = do @@ -463,6 +495,9 @@ build :: Bool -> Bool -> Target -> IO Exit.ExitCode build andTest loud target@Target {..} = do root <- Env.getEnv "BIZ_ROOT" case compiler of + Gcc -> do + Log.info ["bild", "dev", "gcc", nschunk namespace] + proc loud namespace "gcc" ["-o", root bindir Maybe.fromJust out, path] GhcExe -> do Log.info ["bild", "dev", "ghc-exe", nschunk namespace] exitcode <- diff --git a/Biz/Bild.nix b/Biz/Bild.nix index 547ccb9..e7aaf7f 100644 --- a/Biz/Bild.nix +++ b/Biz/Bild.nix @@ -116,6 +116,7 @@ rec { name = "bizdev"; # this should just be dev tools buildInputs = with nixpkgs.pkgs; [ + gcc bild ctags figlet diff --git a/Biz/Bild/Example.c b/Biz/Bild/Example.c new file mode 100644 index 0000000..06e6ed8 --- /dev/null +++ b/Biz/Bild/Example.c @@ -0,0 +1,6 @@ +// : out helloworld.exe +void +main() +{ + printf("Biz/Bild/Example.c: Hello world!\n"); +} diff --git a/Biz/Namespace.hs b/Biz/Namespace.hs index 0fd861f..6fb40f7 100644 --- a/Biz/Namespace.hs +++ b/Biz/Namespace.hs @@ -24,7 +24,8 @@ import qualified Data.List.Split as List import qualified Text.Regex.Applicative as Regex data Ext - = Css + = C + | Css | Hs | Json | Keys @@ -89,7 +90,8 @@ rePath = Regex.many (name <* Regex.string "/" <|> name) reExt :: Regex.RE Char Ext reExt = - Css <$ Regex.string "css" + C <$ Regex.string "c" + <|> Css <$ Regex.string "css" <|> Hs <$ Regex.string "hs" <|> Json <$ Regex.string "json" <|> Keys <$ Regex.string "pub" -- cgit v1.2.3