Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions cargo-pgrx/src/command/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,23 @@ pub(crate) struct Init {
jobserver: OnceLock<jobslot::Client>,
}

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"),
)
.set(jobslot::Client::new(self.resolved_jobs()).expect("failed to create jobserver"))
.unwrap();

let mut versions = HashMap::new();
Expand Down Expand Up @@ -497,6 +500,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())
Expand Down Expand Up @@ -541,6 +546,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())
Expand Down
Loading