David Given
David Given

Reputation: 13713

Make gprbuild default to parallel builds?

How do I make gprbuild default to doing parallel builds? It's not 1990 any more, and I have all these spare cores and don't want to have to keep adding -j0 onto the command line.

From my understanding of the docs, this should work:

package Builder is
    for Default_Switches("Builder") use ("-j0");
end Builder;

...but it doesn't; it's just ignored. I've seen mentions on the interwebs that Default_Switches("Ada") should work, but all that does is pass the --jobs option to GNAT, which is of course wrong.

Upvotes: 3

Views: 569

Answers (1)

Simon Wright
Simon Wright

Reputation: 25501

I don’t see anywhere in the sources of gprbuild where the number of jobs can be controlled except by -j.

However, the documentation suggests that you gan get the effect you want using an “aggregate project”. I wrapped one of my project files in an aggregate like so:

aggregate project Gnat_Util_Aggregate is
   for Project_Files use ("gnat_util.gpr");
   package Builder is
      for Switches (others) use ("-j0");
   end Builder;
end Gnat_Util_Aggregate;

The times for the plain project build on this 13” Macbook Pro were

   70.17 real        66.33 user         2.85 sys

and for the aggregate project build

   35.46 real       119.05 user         4.80 sys

(I have no idea what the “user” values mean! but I checked the “real” values and they match my wristwatch.)

I’ve reported the error on the GPRBuild documentation link above (it says for Switches (other), should be others) to AdaCore.

UPDATE: following David’s justified complaint, and on a hunch, I tried this package Builder trick in my plain project and it worked. I still don’t see where this happens in the sources.

For info, the undocumented switch -dm reports the maximum number of simultaneous compilations (in both gnatmake and gprbuild).

Upvotes: 6

Related Questions