From 03b46613eb1848006bfba963287c4e605d61c7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20No=C3=ABl?= Date: Fri, 15 May 2026 13:47:21 -0700 Subject: [PATCH 1/2] cargo-pgrx: build Postgres in parallel during `cargo pgrx init` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `cargo pgrx init` already accepts `-j`/`--jobs` and uses it to size a `jobslot::Client`, which makes the jobserver auth available to child `make` processes via `MAKEFLAGS`. However, the `make world-bin` and `make install-world-bin` invocations were never given `-j` on their argv, so GNU make ignored the jobserver and ran serially — making `cargo pgrx init` slower than it needed to be on multi-core hosts. This pulls the existing job-count resolution into an `Init::resolved_jobs()` helper, reuses it to seed the jobserver, and passes `-jN` to both `make` invocations so GNU make actually parallelizes. With no `--jobs` flag, the default is `std::thread::available_parallelism()`, matching the previous jobserver-only behavior in spirit but now applied in practice. --- cargo-pgrx/src/command/init.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/cargo-pgrx/src/command/init.rs b/cargo-pgrx/src/command/init.rs index be4b6d2f78..e588db8cbd 100644 --- a/cargo-pgrx/src/command/init.rs +++ b/cargo-pgrx/src/command/init.rs @@ -88,19 +88,25 @@ pub(crate) struct Init { jobserver: OnceLock, } +impl Init { + /// Resolve the make job count: explicit `--jobs`, else the host's + /// available parallelism, else 1. Used to size the jobserver and to + /// pass `-jN` to `make` (without `-jN`, GNU make ignores the jobserver + /// auth in MAKEFLAGS and stays serial). + fn resolved_jobs(&self) -> usize { + self.jobs + .or_else(|| std::thread::available_parallelism().map(NonZeroUsize::get).ok()) + .unwrap_or(1) + } +} + impl CommandExecute for Init { #[tracing::instrument(level = "error", skip(self))] fn execute(self) -> eyre::Result<()> { self.jobserver .set( - jobslot::Client::new( - self.jobs - .or_else(|| { - std::thread::available_parallelism().map(NonZeroUsize::get).ok() - }) - .unwrap_or(1), - ) - .expect("failed to create jobserver"), + jobslot::Client::new(self.resolved_jobs()) + .expect("failed to create jobserver"), ) .unwrap(); @@ -497,6 +503,8 @@ fn make_postgres(pg_config: &PgConfig, pgdir: &Path, init: &Init) -> eyre::Resul let mut command = std::process::Command::new("make"); command + .arg("-j") + .arg(init.resolved_jobs().to_string()) .arg("world-bin") .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped()) @@ -541,6 +549,8 @@ fn make_install_postgres(version: &PgConfig, pgdir: &Path, init: &Init) -> eyre: let mut command = std::process::Command::new("make"); command + .arg("-j") + .arg(init.resolved_jobs().to_string()) .arg("install-world-bin") .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped()) From 5564934e9282e79354a4e0a67fef4bf7b451e389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20No=C3=ABl?= Date: Fri, 15 May 2026 13:59:28 -0700 Subject: [PATCH 2/2] cargo fmt --- cargo-pgrx/src/command/init.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cargo-pgrx/src/command/init.rs b/cargo-pgrx/src/command/init.rs index e588db8cbd..cfd1c20e05 100644 --- a/cargo-pgrx/src/command/init.rs +++ b/cargo-pgrx/src/command/init.rs @@ -104,10 +104,7 @@ impl CommandExecute for Init { #[tracing::instrument(level = "error", skip(self))] fn execute(self) -> eyre::Result<()> { self.jobserver - .set( - jobslot::Client::new(self.resolved_jobs()) - .expect("failed to create jobserver"), - ) + .set(jobslot::Client::new(self.resolved_jobs()).expect("failed to create jobserver")) .unwrap(); let mut versions = HashMap::new();