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>
PKG_LICENSE_FILES:=LICENSE
PKG_BUILD_DEPENDS:=rust/host
+PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
include ../../lang/rust/rust-package.mk
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
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
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
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
PKG_LICENSE_FILES:=LICENSE
PKG_BUILD_DEPENDS:=rust/host
+PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
include ../../lang/rust/rust-package.mk
PKG_BUILD_DEPENDS:= \
rust/host \
protobuf/host
+PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
include ../../lang/rust/rust-package.mk
PKG_LICENSE_FILES:=LICENSE-MIT UNLICENSE
PKG_BUILD_DEPENDS:=rust/host
+PKG_BUILD_PARALLEL:=1
RUST_PKG_FEATURES:=pcre2