summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2022-10-25 21:41:34 -0400
committerBen Sima <ben@bsima.me>2022-10-26 08:37:05 -0400
commite5fa903ab1a7a4dd86b799ad209e5b1713382025 (patch)
tree958bd0522b601d45c27fa2ac1bf1fb8484f4ebd6
parentdbac7bc52f36be86ee63acee357a693ce3d1689f (diff)
Support building with SDL
As a byproduct this also (sorta) generalizes how I pass flags to the C compiler using pkg-config, instead of using the guile-config. Now the 'lib' metadata will be added with 'pkg-config --libs', and the 'sys' metadata will be added with 'pkg-config --cflags'. I'm not *really* sure what the difference is, but if it works it works.
-rw-r--r--Biz/Bild.hs89
-rw-r--r--Biz/Bild.nix1
2 files changed, 58 insertions, 32 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs
index a5495f7..35932b5 100644
--- a/Biz/Bild.hs
+++ b/Biz/Bild.hs
@@ -211,6 +211,8 @@ exitSummary exits =
type Dep = String
+type Arg = String
+
data Out = Lib String | Bin String | None
deriving (Show, Eq)
@@ -388,32 +390,50 @@ analyze hmap ns = case Map.lookup ns hmap of
Namespace.Sh -> pure Nothing
Namespace.C -> do
let out = detectOut (metaOut "//" <|> metaLib "//") contentLines
- let sysdeps = detectSysdeps (metaSys "//") contentLines
- ("guile_3_0" `elem` sysdeps)
- ?. ( pure mempty,
- Process.readProcess "guile-config" ["compile"] ""
- /> String.words
- /> (++ ["-shared", "-fPIC"])
- /> map Text.pack
- )
- +> \guileFlags ->
- Target
- { langdeps = Set.empty, -- c has no lang deps...?
- wrapper = Nothing,
- compiler = Gcc,
- builder = Local <| user,
- compilerFlags =
- concat
- [ [o, dir, Text.pack absPath] ++ guileFlags
- | let outable = out /= None,
- o <- outable ?: (["-o"], []),
- dir <- outable ?: ([Text.pack <| root </> outToPath out], [])
- ],
- outPath = outToPath out,
- ..
- }
- |> Just
- |> pure
+ let args = detectMeta (metaArg "//") contentLines
+ let langdeps = detectMeta (metaDep "//") contentLines
+ langdepFlags <-
+ if null langdeps
+ then pure []
+ else
+ Process.readProcess
+ "pkg-config"
+ ("--cflags" : Set.toList langdeps)
+ ""
+ /> Text.pack
+ /> Text.words
+
+ let sysdeps = detectMeta (metaSys "//") contentLines
+ sysdepFlags <-
+ if null sysdeps
+ then pure []
+ else
+ Process.readProcess
+ "pkg-config"
+ ("--libs" : Set.toList sysdeps)
+ ""
+ /> Text.pack
+ /> Text.words
+ Target
+ { langdeps = Set.empty, -- c has no lang deps...?
+ wrapper = Nothing,
+ compiler = Gcc,
+ builder = Local <| user,
+ compilerFlags =
+ concat
+ [ [o, dir, Text.pack absPath]
+ ++ langdepFlags
+ ++ sysdepFlags
+ ++ (map Text.pack <| Set.toList args)
+ | let outable = out /= None,
+ o <- outable ?: (["-o"], []),
+ dir <- outable ?: ([Text.pack <| root </> outToPath out], [])
+ ],
+ outPath = outToPath out,
+ ..
+ }
+ |> Just
+ |> pure
Namespace.Hs -> do
langdeps <- detectHaskellImports contentLines
let out = detectOut (metaOut "--") contentLines
@@ -445,7 +465,7 @@ analyze hmap ns = case Map.lookup ns hmap of
],
[]
),
- sysdeps = detectSysdeps (metaSys "--") contentLines,
+ sysdeps = detectMeta (metaSys "--") contentLines,
outPath = outToPath out,
..
}
@@ -581,7 +601,7 @@ analyze hmap ns = case Map.lookup ns hmap of
|> catMaybes
|> head
|> fromMaybe None
- detectSysdeps m cl =
+ detectMeta m cl =
cl
/> Text.unpack
/> Regex.match m
@@ -737,10 +757,10 @@ logs ns src =
nschunk :: Namespace -> Text
nschunk = Namespace.toPath .> Text.pack
-metaDep :: Regex.RE Char Dep
-metaDep =
- Regex.string "-- : dep "
- *> Regex.many (Regex.psym Char.isAlpha)
+metaDep :: [Char] -> Regex.RE Char Dep
+metaDep comment =
+ Regex.string (comment ++ " : dep ")
+ *> Regex.many (Regex.psym (not <. Char.isSpace))
metaSys :: [Char] -> Regex.RE Char Dep
metaSys comment =
@@ -759,6 +779,11 @@ metaLib comment =
*> Regex.many (Regex.psym (/= ' '))
/> Lib
+metaArg :: [Char] -> Regex.RE Char Arg
+metaArg comment =
+ Regex.string (comment ++ " : arg ")
+ *> Regex.many Regex.anySym
+
haskellImports :: Regex.RE Char String
haskellImports =
Regex.string "import"
diff --git a/Biz/Bild.nix b/Biz/Bild.nix
index b6946c9..ae3201c 100644
--- a/Biz/Bild.nix
+++ b/Biz/Bild.nix
@@ -42,6 +42,7 @@ rec {
bildRuntimeDeps = with nixpkgs; [
pkg-config
guile_3_0
+ SDL
private.ghcPackageSetBild
rustc
gcc