From 55186758bcdaef892e9406acf83bb46eb284caa7 Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Sat, 10 Feb 2024 12:57:49 +0100 Subject: [PATCH] Add missing files for Rust --- rust/Config.in | 15 ++++++++++++++ rust/files/cargo-config | 8 -------- rust/rust-host-build.mk | 44 +++++++++++++++++++++++------------------ rust/rust-package.mk | 30 +++++++++++----------------- 4 files changed, 52 insertions(+), 45 deletions(-) create mode 100644 rust/Config.in delete mode 100644 rust/files/cargo-config diff --git a/rust/Config.in b/rust/Config.in new file mode 100644 index 000000000..62051af13 --- /dev/null +++ b/rust/Config.in @@ -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 diff --git a/rust/files/cargo-config b/rust/files/cargo-config deleted file mode 100644 index 2ed512931..000000000 --- a/rust/files/cargo-config +++ /dev/null @@ -1,8 +0,0 @@ -[target.@RUSTC_TARGET_ARCH@] -linker = "@TARGET_CC_NOCACHE@" -rustflags = ["-Ctarget-feature=-crt-static", "-Clink-args=@RUSTC_LDFLAGS@"] - -[profile.stripped] -inherits = "release" -opt-level = "s" -strip = true diff --git a/rust/rust-host-build.mk b/rust/rust-host-build.mk index 39cf1f23c..e56292937 100644 --- a/rust/rust-host-build.mk +++ b/rust/rust-host-build.mk @@ -2,36 +2,42 @@ # # Copyright (C) 2023 Luca Barbato and Donald Hoskins +# Variables (all optional) to be set in package Makefiles: +# +# RUST_HOST_FEATURES - list of options, default empty +# +# Space or comma separated list of features to activate +# +# e.g. RUST_HOST_FEATURES:=enable-foo,with-bar + ifeq ($(origin RUST_INCLUDE_DIR),undefined) RUST_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST))) endif include $(RUST_INCLUDE_DIR)/rust-values.mk +CARGO_HOST_VARS= \ + $(CARGO_HOST_CONFIG_VARS) \ + 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) ; \ - export PATH="$(CARGO_HOME)/bin:$(PATH)" ; \ - CARGO_HOME=$(CARGO_HOME) \ - CC=$(HOSTCC_NOCACHE) \ - cargo install -v \ - --profile stripped \ - $(if $(RUST_PKG_FEATURES),--features "$(RUST_PKG_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) ; \ - export PATH="$(CARGO_HOME)/bin:$(PATH)" ; \ - CARGO_HOME=$(CARGO_HOME) \ - CC=$(HOSTCC_NOCACHE) \ - cargo uninstall -v \ - --root $(HOST_INSTALL_DIR) || true ; \ - ) + +$(CARGO_HOST_VARS) \ + cargo uninstall -v \ + --root $(HOST_INSTALL_DIR) \ + || true endef define RustBinHostBuild diff --git a/rust/rust-package.mk b/rust/rust-package.mk index 955b37c29..24341d706 100644 --- a/rust/rust-package.mk +++ b/rust/rust-package.mk @@ -15,28 +15,22 @@ ifeq ($(origin RUST_INCLUDE_DIR),undefined) endif include $(RUST_INCLUDE_DIR)/rust-values.mk -# Support only a subset for now. -RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mipsel||mips64||mips64el||mipsel||powerpc64||riscv64||x86_64) +CARGO_PKG_VARS= \ + $(CARGO_PKG_CONFIG_VARS) \ + 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) ; \ - export PATH="$(CARGO_HOME)/bin:$(PATH)" ; \ - CARGO_HOME=$(CARGO_HOME) \ - TARGET_CFLAGS="$(TARGET_CFLAGS) $(RUST_CFLAGS)" \ - TARGET_CC=$(TARGET_CC_NOCACHE) \ - CC=$(HOSTCC_NOCACHE) \ - $(CARGO_VARS) \ - cargo install -v \ - --profile stripped \ - --target $(RUSTC_TARGET_ARCH) \ - $(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