aboutsummaryrefslogtreecommitdiff
path: root/lang/rust/rust-package.mk
diff options
context:
space:
mode:
authorTianling Shen <cnsztl@immortalwrt.org>2023-03-19 14:07:48 +0800
committerTianling Shen <cnsztl@gmail.com>2023-03-24 02:08:47 +0800
commite7016bb4bc20f3711840134440be178bf8d0f72d (patch)
tree90787e7a4fa06e3c5764eab366f260e8d8f6ff10 /lang/rust/rust-package.mk
parent473bc722ea3f5d3171c7e08abd6818603be291fc (diff)
rust: refactor build helper
Added new RustBinPackage, RustBinHostBuild wrapper. Added new RUST_PKG_FEATURES flag. Moved CARGO_HOME to STAGING_DIR_HOSTPKG. Overrode default Build/Compile and Host/Compile to Cargo build. Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
Diffstat (limited to 'lang/rust/rust-package.mk')
-rw-r--r--lang/rust/rust-package.mk54
1 files changed, 38 insertions, 16 deletions
diff --git a/lang/rust/rust-package.mk b/lang/rust/rust-package.mk
index 54c2aa89a..4e39009cc 100644
--- a/lang/rust/rust-package.mk
+++ b/lang/rust/rust-package.mk
@@ -2,27 +2,49 @@
#
# Copyright (C) 2023 Luca Barbato and Donald Hoskins
-rust_mk_path:=$(dir $(lastword $(MAKEFILE_LIST)))
-include $(rust_mk_path)rust-host.mk
+# Variables (all optional) to be set in package Makefiles:
+#
+# RUST_PKG_FEATURES - list of options, default empty
+#
+# Space or comma separated list of features to activate
+#
+# e.g. RUST_PKG_FEATURES:=enable-foo,with-bar
-# $(1) path to the package
-# $(2) additional arguments to cargo
-define Host/Compile/Cargo
- ( \
- cd $(HOST_BUILD_DIR) ; \
- export PATH="$(CARGO_HOME)/bin:$(PATH)" ; \
- CARGO_HOME=$(CARGO_HOME) CC=$(HOSTCC) \
- cargo install -v --profile stripped --root $(HOST_INSTALL_DIR) --path "$(if $(strip $(1)),$(strip $(1)),.)" $(2) ; \
- )
-endef
+ifeq ($(origin RUST_INCLUDE_DIR),undefined)
+ RUST_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
+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||x86_64)
-# $(1) path to the package
-# $(2) additional arguments to cargo
+# $(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=cc \
- cargo install -v --profile stripped --target $(RUSTC_TARGET_ARCH) --root $(PKG_INSTALL_DIR) --path "$(if $(strip $(1)),$(strip $(1)),.)" $(2) ; \
+ CARGO_HOME=$(CARGO_HOME) \
+ TARGET_CFLAGS="$(TARGET_CFLAGS) $(RUST_CFLAGS)" \
+ TARGET_CC=$(TARGET_CC_NOCACHE) \
+ CC=$(HOSTCC) \
+ 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) ; \
)
endef
+
+define RustBinPackage
+ ifndef Package/$(1)/install
+ define Package/$(1)/install
+ $$(INSTALL_DIR) $$(1)/usr/bin/
+ $$(INSTALL_BIN) $$(PKG_INSTALL_DIR)/bin/* $$(1)/usr/bin/
+ endef
+ endif
+endef
+
+Build/Compile=$(call Build/Compile/Cargo)