rust: Use make's jobserver when building packages
authorJeffery To <jeffery.to@gmail.com>
Sat, 23 Sep 2023 12:24:37 +0000 (20:24 +0800)
committerJeffery To <jeffery.to@gmail.com>
Thu, 12 Oct 2023 06:02:35 +0000 (14:02 +0800)
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 <jeffery.to@gmail.com>
(cherry picked from commit 0dfc1b508d5e5b361978ef9783cb63775176c305)
[omit changes to arp-whisper and procs]
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
admin/bottom/Makefile
lang/maturin/Makefile
lang/rust/Makefile
lang/rust/rust-host-build.mk
lang/rust/rust-package.mk
net/aardvark-dns/Makefile
net/netavark/Makefile
utils/ripgrep/Makefile

index bdd049a29a3ed82c661a47e49f4fd9f14e2ae147..556b11b23d4f392f15681f1b05a4426b1c4153d1 100644 (file)
@@ -17,6 +17,7 @@ PKG_LICENSE:=MIT
 PKG_LICENSE_FILES:=LICENSE
 
 PKG_BUILD_DEPENDS:=rust/host
+PKG_BUILD_PARALLEL:=1
 
 include $(INCLUDE_DIR)/package.mk
 include ../../lang/rust/rust-package.mk
index e1c7ca50f22b7dd679d5f5a9ea7391c7eb34d307..220e31fbadbd5a9f0de4d3449b64fe5d95437ae6 100644 (file)
@@ -17,6 +17,7 @@ PKG_LICENSE:=Apache-2.0 MIT
 PKG_LICENSE_FILES:=license-apache license-mit
 
 HOST_BUILD_DEPENDS:=rust/host
+HOST_BUILD_PARALLEL:=1
 PKG_HOST_ONLY:=1
 
 include $(INCLUDE_DIR)/host-build.mk
index 8f99f4144bf3bb9565ab860f0345518bd0aebcdf..d0a9ef48d5f0ce80d1d71755290fcceaf230fa34 100644 (file)
@@ -80,13 +80,12 @@ define Host/Uninstall
 endef
 
 define Host/Compile
-       ( \
-               cd $(HOST_BUILD_DIR) ; \
-               CARGO_HOME=$(CARGO_HOME) \
-               OPENWRT_RUSTC_BOOTSTRAP_CACHE=$(DL_DIR)/rustc \
-               $(PYTHON) x.py --config ./config.toml dist build-manifest cargo llvm-tools \
-                       rustc rust-std rust-src ; \
-       )
+       CARGO_HOME=$(CARGO_HOME) \
+       OPENWRT_RUSTC_BOOTSTRAP_CACHE=$(DL_DIR)/rustc \
+       $(PYTHON) $(HOST_BUILD_DIR)/x.py \
+               --build-dir $(HOST_BUILD_DIR)/build \
+               --config $(HOST_BUILD_DIR)/config.toml \
+               dist build-manifest cargo llvm-tools rustc rust-std rust-src
 endef
 
 define Host/Install
index 38ce963e0fd327885925ebafe028190eeb0237b2..e5629293760b57ed0ee2ec5d58b12575aeeca646 100644 (file)
@@ -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
index 6deb859fb62309b4224709a684e44573a70f4aa6..24341d7063f20cc5fda33b858eadb7a7bb49d170 100644 (file)
@@ -17,21 +17,20 @@ include $(RUST_INCLUDE_DIR)/rust-values.mk
 
 CARGO_PKG_VARS= \
        $(CARGO_PKG_CONFIG_VARS) \
-       CC=$(HOSTCC_NOCACHE)
+       CC=$(HOSTCC_NOCACHE) \
+       MAKEFLAGS="$(PKG_JOBS)"
 
 # $(1) path to the package (optional)
 # $(2) additional arguments to cargo (optional)
 define Build/Compile/Cargo
-       ( \
-               cd $(PKG_BUILD_DIR) ; \
-               $(CARGO_PKG_VARS) \
-               cargo install -v \
-                       --profile $(CARGO_PKG_PROFILE) \
-                       $(if $(strip $(RUST_PKG_FEATURES)),--features "$(strip $(RUST_PKG_FEATURES))") \
-                       --root $(PKG_INSTALL_DIR) \
-                       --path "$(if $(strip $(1)),$(strip $(1)),.)" \
-                       $(2) ; \
-       )
+       +$(CARGO_PKG_VARS) \
+       cargo install -v \
+               --profile $(CARGO_PKG_PROFILE) \
+               $(if $(strip $(RUST_PKG_FEATURES)),--features "$(strip $(RUST_PKG_FEATURES))") \
+               --root $(PKG_INSTALL_DIR) \
+               --path "$(PKG_BUILD_DIR)/$(if $(strip $(1)),$(strip $(1)))" \
+               $(if $(filter --jobserver%,$(PKG_JOBS)),,-j1) \
+               $(2)
 endef
 
 define RustBinPackage
index 16e1b1d1452d1e755bf8a04cd6ec008d1cc6bde8..5730370f34c0547637df706c155f62f26196fe61 100644 (file)
@@ -13,6 +13,7 @@ PKG_LICENSE:=Apache-2.0
 PKG_LICENSE_FILES:=LICENSE
 
 PKG_BUILD_DEPENDS:=rust/host
+PKG_BUILD_PARALLEL:=1
 
 include $(INCLUDE_DIR)/package.mk
 include ../../lang/rust/rust-package.mk
index 369d013c0c062257b8588c6334c379eb2ea75282..874ddf06ecd6320d6e9e0cf512d517277c56826f 100644 (file)
@@ -15,6 +15,7 @@ PKG_LICENSE_FILES:=LICENSE
 PKG_BUILD_DEPENDS:= \
        rust/host \
        protobuf/host
+PKG_BUILD_PARALLEL:=1
 
 include $(INCLUDE_DIR)/package.mk
 include ../../lang/rust/rust-package.mk
index 56658540f99f2fe6f2eab9add65dd44c39c2003b..bad9f95e2492b7f538dab2225b0a9be0e2dfaac5 100644 (file)
@@ -17,6 +17,7 @@ PKG_LICENSE:=MIT Unlicense
 PKG_LICENSE_FILES:=LICENSE-MIT UNLICENSE
 
 PKG_BUILD_DEPENDS:=rust/host
+PKG_BUILD_PARALLEL:=1
 
 RUST_PKG_FEATURES:=pcre2