From ed9548957db92f112ab1d7105da235e12d5ea3a8 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 14 Nov 2025 13:31:44 -0500 Subject: Add bounded parallel target builds - Add mapConcurrentlyBounded using QSemN for bounded parallelism - Refactor build function to extract buildTarget worker - Build up to --jobs targets concurrently - Preserves all existing functionality - Output will be interleaved (will fix with LineManager next) Related tasks: - t-1a0OVBs: mapConcurrentlyBounded helper - t-1a16ame: refactor build function - t-1a1DdSB: replace forM with concurrent map --- Omni/Bild.hs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'Omni/Bild.hs') diff --git a/Omni/Bild.hs b/Omni/Bild.hs index dbae550..414049b 100755 --- a/Omni/Bild.hs +++ b/Omni/Bild.hs @@ -119,6 +119,8 @@ module Omni.Bild where import Alpha hiding (sym, (<.>)) import qualified Conduit import qualified Control.Concurrent.Async as Async +import qualified Control.Concurrent.QSemN as QSemN +import qualified Control.Exception as Exception import qualified Data.Aeson as Aeson import qualified Data.ByteString as ByteString import qualified Data.ByteString.Char8 as Char8 @@ -154,6 +156,15 @@ import qualified System.Process as Process import qualified System.Timeout as Timeout import qualified Text.Regex.Applicative as Regex +mapConcurrentlyBounded :: Int -> (a -> IO b) -> [a] -> IO [b] +mapConcurrentlyBounded n f xs = do + sem <- QSemN.newQSemN n + Async.forConcurrently xs <| \x -> + Exception.bracket_ + (QSemN.waitQSemN sem 1) + (QSemN.signalQSemN sem 1) + (f x) + main :: IO () main = Cli.Plan help move test_ pure |> Cli.main where @@ -940,10 +951,15 @@ test loud Target {..} = >> pure (Exit.ExitFailure 1, mempty) build :: Bool -> Bool -> Int -> Int -> Analysis -> IO [Exit.ExitCode] -build andTest loud jobs cpus analysis = - Env.getEnv "CODEROOT" +> \root -> - forM (Map.elems analysis) <| \target@Target {..} -> - fst Target -> IO (Exit.ExitCode, ByteString) + buildTarget root target@Target {..} = + case compiler of CPython -> case out of Just _ -> Log.info ["bild", "nix", "python", nschunk namespace] @@ -997,9 +1013,9 @@ build andTest loud jobs cpus analysis = Rustc -> Log.info ["bild", "dev", "rust", nschunk namespace] >> nixBuild loud jobs cpus target - Sbcl -> do + Sbcl -> Log.info ["bild", "dev", "lisp", nschunk namespace] - proc loud namespace (toNixFlag compiler) compilerFlags + >> proc loud namespace (toNixFlag compiler) compilerFlags data Proc = Proc { loud :: Bool, -- cgit v1.2.3