diff options
author | Ben Sima <ben@bsima.me> | 2023-08-17 21:21:07 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2023-08-17 22:44:04 -0400 |
commit | aac50fb4a0eea25a057bb2d7ebe80961c542a2a5 (patch) | |
tree | b6e6a26cd7dec9937003aa33ec6f0875be2ee99d /Biz/Bild.hs | |
parent | cc6aac612e36da3c9b9b4e47fc16ed512a79f2d9 (diff) |
Nixify C build
This is working with libsodium as an example. Its unfortunate that we need the
extra ':arg -lsodium' but how else can I get the name of the library for
linking? Is that something in the nix attr metadata? Anyway, an optimization for
another day.
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r-- | Biz/Bild.hs | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs index 81947ed..2db5ccc 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -423,7 +423,6 @@ analyze hmap ns = case Map.lookup ns hmap of user <- Env.getEnv "USER" /> Text.pack host <- HostName.getHostName /> Text.pack Log.info ["bild", "analyze", str path] - let runw cmd args = Process.readProcess cmd args "" /> Text.pack /> Text.words contentLines <- withFile absPath ReadMode <| \h -> IO.hSetEncoding h IO.utf8_bom @@ -466,20 +465,6 @@ analyze hmap ns = case Map.lookup ns hmap of Namespace.Sh -> pure Nothing Namespace.C -> Meta.detectAll "//" contentLines |> \Meta.Parsed {..} -> do - nixCFlags <- - Env.getEnv "NIX_CFLAGS_COMPILE" - /> Text.pack - /> Text.words - langdepFlags <- - null pdep - ?. ( runw "pkg-config" ("--cflags" : Set.toList pdep), - pure [] - ) - sysdepFlags <- - null psys - ?. ( runw "pkg-config" ("--libs" : Set.toList psys), - pure [] - ) Target { langdeps = pdep, sysdeps = psys, @@ -487,18 +472,11 @@ analyze hmap ns = case Map.lookup ns hmap of compiler = Gcc, builder = Local user host, out = pout, - packageSet = "", -- none, or maybe I should make cPackages? - compilerFlags = - concat - [ [o, dir, str absPath] - ++ langdepFlags - ++ sysdepFlags - ++ nixCFlags - ++ (map Text.pack <| Set.toList parg) - | let outable = pout /= Meta.None, - o <- outable ?: (["-o"], []), - dir <- outable ?: ([Text.pack <| root </> outToPath pout], []) - ], + packageSet = "cPackages", + compilerFlags = case pout of + Meta.Bin o -> + ["-o", o, path] <> Set.toList parg |> map Text.pack + _ -> panic "can only bild C exes, not libs", outPath = outToPath pout, srcs = Set.singleton absPath, .. @@ -756,7 +734,7 @@ build andTest loud analysis = >> nixBuild loud target Gcc -> Log.info ["bild", label, "gcc", nschunk namespace] - >> proc loud namespace (toNixFlag compiler) compilerFlags + >> nixBuild loud target where label = case out of Meta.Bin _ -> "bin" @@ -977,4 +955,5 @@ selectBuilder = \case Namespace _ Namespace.Hs -> "haskell" Namespace _ Namespace.Py -> "python" Namespace _ Namespace.Rs -> "base" + Namespace _ Namespace.C -> "c" Namespace _ ext -> panic <| "no builder for " <> show ext |