From a6856775ad86d8f33d5d724a3843fb16e5a3551d Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 9 Apr 2024 20:16:24 -0400 Subject: Fix --cpus and --jobs This patch fixes two problems: 1. Apparently the docopt spec wasn't written correctly, I needed to add a metavar (like N for number) to the spec so that docopt would correctly parse the command line args. Without this, I had just been using the default 6 and 10 that I hardcoded. 2. I never added the --max-jobs and --cores flags to NixBuild, so anytime I built a nix target, i.e. any of my NixOS images, it would use all of the available cores. I think this is part of why I struggled so much to build webkitgtk: I *thought* I was limiting the resources to prevent an OOM crash, but I wasn't. With this fix, I can comfortably limit resources for a build, so I can continue working while building something in the background. --- Biz/Bild.hs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'Biz') diff --git a/Biz/Bild.hs b/Biz/Bild.hs index 7bce4e9..2ec0c7f 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -241,14 +241,16 @@ move args = build isTest isLoud jobs (cpus nproc) targets cpus :: Int -> Int cpus nproc = - Cli.getArgWithDefault args (str <| (nproc - 4) `div` jobs) (Cli.longOption "cpus") + Cli.longOption "cpus" + |> Cli.getArgWithDefault args (str <| (nproc - 4) `div` jobs) |> readMaybe |> \case Nothing -> panic "could not read --cpus argument" Just n -> n jobs :: Int jobs = - Cli.getArgWithDefault args "6" (Cli.longOption "jobs") + Cli.longOption "jobs" + |> Cli.getArgWithDefault args "6" |> readMaybe |> \case Nothing -> panic "could not read --jobs argument" @@ -313,15 +315,16 @@ bild Usage: bild test bild [options] ... + bild --help Options: - --test, -t Run tests on a target after building - --loud, -l Show all output from compiler - --plan, -p Print the build plan as JSON, don't build - --time N Set timeout to N minutes, 0 means never timeout [default: 10] - --jobs, -j Number of jobs to build at once [default: 6] - --cpus, -c Number of cpu cores to use per job [default: (nproc-4)/jobs] - --help, -h Print this info + --test, -t Run tests on a target after building + --loud, -l Show all output from compiler + --plan, -p Print the build plan as JSON, don't build + --time N Set timeout to N minutes, 0 means never timeout [default: 10] + --jobs N, -j N Build up to N jobs at once [default: 6] + --cpus N, -c N Allocate up to N cpu cores per job (default: (nproc-4)/jobs) + --help, -h Print this info |] exitSummary :: [Exit.ExitCode] -> IO () @@ -919,7 +922,13 @@ build andTest loud jobs cpus analysis = pure (Exit.ExitSuccess, mempty) NixBuild -> do Log.info ["bild", "nix", user <> "@" <> host, nschunk namespace] - proc loud namespace (toNixFlag compiler) compilerFlags + proc loud namespace (toNixFlag compiler) + <| compilerFlags + ++ [ "--max-jobs", + Text.pack <| str jobs, + "--cores", + Text.pack <| str cpus + ] Copy -> do Log.warn ["bild", "copy", "not implemented yet", nschunk namespace] pure (Exit.ExitSuccess, mempty) -- cgit v1.2.3