rust: Add option to use sccache

Using sccache makes recompilation of rustc and Rust packages faster.

This also makes the rust package visible in menuconfig, in order for the
sccache options to be accessible.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
(cherry picked from commit b4ec017398)
This commit is contained in:
Jeffery To 2023-09-25 10:00:58 +08:00
parent 236da17e6a
commit 74b970fbce
No known key found for this signature in database
GPG Key ID: C616D9E719E868E4
3 changed files with 31 additions and 1 deletions

15
lang/rust/Config.in Normal file
View File

@ -0,0 +1,15 @@
menu "Configuration options (for developers)"
config RUST_SCCACHE
bool "Use sccache"
help
Shared compilation cache; see https://github.com/mozilla/sccache
config RUST_SCCACHE_DIR
string "Set sccache directory" if RUST_SCCACHE
default ""
help
Store sccache in this directory.
If not set, uses './.sccache'
endmenu

View File

@ -30,7 +30,6 @@ define Package/rust
TITLE:=Rust Programming Language Compiler TITLE:=Rust Programming Language Compiler
URL:=https://www.rust-lang.org/ URL:=https://www.rust-lang.org/
DEPENDS:=$(RUST_ARCH_DEPENDS) DEPENDS:=$(RUST_ARCH_DEPENDS)
BUILDONLY:=1
endef endef
define Package/rust/description define Package/rust/description
@ -39,6 +38,10 @@ define Package/rust/description
guarantee memory safety by using a borrow checker to validate references. guarantee memory safety by using a borrow checker to validate references.
endef endef
define Package/rust/config
source "$(SOURCE)/Config.in"
endef
# Rust-lang has an uninstall script # Rust-lang has an uninstall script
RUST_UNINSTALL:=$(STAGING_DIR)/host/lib/rustlib/uninstall.sh RUST_UNINSTALL:=$(STAGING_DIR)/host/lib/rustlib/uninstall.sh
@ -80,6 +83,7 @@ define Host/Uninstall
endef endef
define Host/Compile define Host/Compile
$(RUST_SCCACHE_VARS) \
CARGO_HOME=$(CARGO_HOME) \ CARGO_HOME=$(CARGO_HOME) \
OPENWRT_RUSTC_BOOTSTRAP_CACHE=$(DL_DIR)/rustc \ OPENWRT_RUSTC_BOOTSTRAP_CACHE=$(DL_DIR)/rustc \
$(PYTHON) $(HOST_BUILD_DIR)/x.py \ $(PYTHON) $(HOST_BUILD_DIR)/x.py \

View File

@ -62,12 +62,23 @@ endif
# Support only a subset for now. # Support only a subset for now.
RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mipsel||mips64||mips64el||mipsel||powerpc64||riscv64||x86_64) RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mipsel||mips64||mips64el||mipsel||powerpc64||riscv64||x86_64)
ifneq ($(CONFIG_RUST_SCCACHE),)
RUST_SCCACHE_DIR:=$(if $(call qstrip,$(CONFIG_RUST_SCCACHE_DIR)),$(call qstrip,$(CONFIG_RUST_SCCACHE_DIR)),$(TOPDIR)/.sccache)
RUST_SCCACHE_VARS:= \
CARGO_INCREMENTAL=0 \
RUSTC_WRAPPER=sccache \
SCCACHE_DIR=$(RUST_SCCACHE_DIR)
endif
CARGO_HOST_CONFIG_VARS= \ CARGO_HOST_CONFIG_VARS= \
$(RUST_SCCACHE_VARS) \
CARGO_HOME=$(CARGO_HOME) CARGO_HOME=$(CARGO_HOME)
CARGO_HOST_PROFILE:=release CARGO_HOST_PROFILE:=release
CARGO_PKG_CONFIG_VARS= \ CARGO_PKG_CONFIG_VARS= \
$(RUST_SCCACHE_VARS) \
CARGO_BUILD_TARGET=$(RUSTC_TARGET_ARCH) \ CARGO_BUILD_TARGET=$(RUSTC_TARGET_ARCH) \
CARGO_HOME=$(CARGO_HOME) \ CARGO_HOME=$(CARGO_HOME) \
CARGO_PROFILE_RELEASE_OPT_LEVEL=s \ CARGO_PROFILE_RELEASE_OPT_LEVEL=s \