From 0dfc1b508d5e5b361978ef9783cb63775176c305 Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Sat, 23 Sep 2023 20:24:37 +0800 Subject: rust: Use make's jobserver when building packages This allows cargo to use make's jobserver when building packages, by marking the cargo command as recursive (with the + prefix[1]) and setting MAKEFLAGS. This also: * Give cargo/x.py the build directory instead of having to change the current directory (and opening subshells) * Set PKG_BUILD_PARALLEL/HOST_BUILD_PARALLEL for Rust packages to enable the use of make's jobserver [1]: https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html Signed-off-by: Jeffery To --- lang/rust/rust-host-build.mk | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'lang/rust/rust-host-build.mk') diff --git a/lang/rust/rust-host-build.mk b/lang/rust/rust-host-build.mk index 38ce963e0..e56292937 100644 --- a/lang/rust/rust-host-build.mk +++ b/lang/rust/rust-host-build.mk @@ -17,29 +17,27 @@ include $(RUST_INCLUDE_DIR)/rust-values.mk CARGO_HOST_VARS= \ $(CARGO_HOST_CONFIG_VARS) \ - CC=$(HOSTCC_NOCACHE) + CC=$(HOSTCC_NOCACHE) \ + MAKEFLAGS="$(HOST_JOBS)" # $(1) path to the package (optional) # $(2) additional arguments to cargo (optional) define Host/Compile/Cargo - ( \ - cd $(HOST_BUILD_DIR) ; \ - $(CARGO_HOST_VARS) \ - cargo install -v \ - --profile $(CARGO_HOST_PROFILE) \ - $(if $(RUST_HOST_FEATURES),--features "$(RUST_HOST_FEATURES)") \ - --root $(HOST_INSTALL_DIR) \ - --path "$(if $(strip $(1)),$(strip $(1)),.)" $(2) ; \ - ) + +$(CARGO_HOST_VARS) \ + cargo install -v \ + --profile $(CARGO_HOST_PROFILE) \ + $(if $(RUST_HOST_FEATURES),--features "$(RUST_HOST_FEATURES)") \ + --root $(HOST_INSTALL_DIR) \ + --path "$(HOST_BUILD_DIR)/$(if $(strip $(1)),$(strip $(1)))" \ + $(if $(filter --jobserver%,$(HOST_JOBS)),,-j1) \ + $(2) endef define Host/Uninstall/Cargo - ( \ - cd $(HOST_BUILD_DIR) ; \ - $(CARGO_HOST_VARS) \ - cargo uninstall -v \ - --root $(HOST_INSTALL_DIR) || true ; \ - ) + +$(CARGO_HOST_VARS) \ + cargo uninstall -v \ + --root $(HOST_INSTALL_DIR) \ + || true endef define RustBinHostBuild -- cgit v1.2.3