]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
make.sh: Add some commands to build Rust packages
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 Jan 2022 15:11:15 +0000 (15:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Feb 2022 13:50:32 +0000 (13:50 +0000)
This is a small set of commands that will be needed to build Rust
packages.

The idea is to have a couple of macros which do not have to rewritten,
but can be customised across the lfs files.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/rootfiles/common/aarch64/rust
config/rootfiles/common/armv6l/rust
config/rootfiles/common/x86_64/rust
lfs/Config
lfs/rust

index c26d4591ba0ffd813f30e397f4173108ffcc7cc9..f51308f7a673830d9f8e3c1b85001f16a07e2a7a 100644 (file)
@@ -64,6 +64,7 @@
 #usr/lib/rustlib/rust-installer-version
 #usr/lib/rustlib/uninstall.sh
 #usr/libexec/cargo-credential-1password
+#usr/share/cargo/registry
 #usr/share/doc/cargo
 #usr/share/doc/cargo/LICENSE-APACHE
 #usr/share/doc/cargo/LICENSE-MIT
index ffe8318ab7f8d2e479c8862109e73390586fe512..7b374d94d8807423aa5f27cd5da791eb942812c7 100644 (file)
@@ -59,6 +59,7 @@
 #usr/lib/rustlib/rust-installer-version
 #usr/lib/rustlib/uninstall.sh
 #usr/libexec/cargo-credential-1password
+#usr/share/cargo/registry
 #usr/share/doc/cargo
 #usr/share/doc/cargo/LICENSE-APACHE
 #usr/share/doc/cargo/LICENSE-MIT
index 6f4c7fd45415fcdeb2feaaa6116ea0557971c243..5b5080e00991cba60cf6c10c5040412b5d49c2b1 100644 (file)
@@ -62,6 +62,7 @@
 #usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-ca628c5eca5e5caf.rlib
 #usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-5c4d6c9d7595f844.rlib
 #usr/libexec/cargo-credential-1password
+#usr/share/cargo/registry
 #usr/share/doc/cargo
 #usr/share/doc/cargo/LICENSE-APACHE
 #usr/share/doc/cargo/LICENSE-MIT
index 76a07b088f6a34dfd69686e76e33288b309da409..d7a59c5a656a3475b1c6fb984656dd21bf7e8001 100644 (file)
 unexport BUILD_ARCH BUILD_PLATFORM BUILDTARGET CROSSTARGET TOOLCHAIN TOOLS_DIR
 unexport XZ_OPT
 
+# Basic Variables
+EMPTY :=
+COMMA := ,
+SPACE := $(EMPTY) $(EMPTY)
+define NEWLINE
+
+
+endef
+
+# Basic Functions
+join-with      = $(subst $(SPACE),$(1),$(strip $(2)))
+
 PARALLELISM = $(shell echo $$( \
        if [ -n "$(MAX_PARALLELISM)" ] && [ $(MAX_PARALLELISM) -lt 1 ]; then \
                echo 1 ; \
@@ -140,7 +152,71 @@ ifeq "$(BUILD_ARCH)" "aarch64"
 endif
 
 # Rust
-export CARGOPATH = $(HOME)/.cargo
+CARGO_PATH     = $(DIR_APP)/.cargo
+CARGO_REGISTRY = /usr/share/cargo/registry
+
+CRATE_NAME = $(patsubst rust-%,%,$(firstword $(MAKEFILE_LIST)))
+CRATE_VER  = $(VER)
+CRATE_PATH = $(CARGO_REGISTRY)/$(CRATE_NAME)-$(CRATE_VER)
+
+define CARGO_CONFIG
+[build]
+rustflags = [$(call join-with,$(COMMA)$(SPACE),$(foreach flag,$(RUSTFLAGS),"$(flag)"))]
+
+[env]
+CFLAGS = "$(CFLAGS)"
+CXXFLAGS = "$(CXXFLAGS)"
+LDFLAGS = "$(LDFLAGS)"
+
+[term]
+verbose = true
+
+[source]
+
+[source.local-registry]
+directory = "$(CARGO_REGISTRY)"
+
+[source.crates-io]
+registry = "https://crates.io"
+replace-with = "local-registry"
+endef
+export CARGO_CONFIG
+
+CARGO = \
+       CARGOPATH=$(CARGO_PATH) \
+       cargo
+
+define CARGO_PREPARE
+       mkdir -p $(CARGO_PATH) && \
+       echo "$${CARGO_CONFIG}" > $(CARGO_PATH)/config && \
+       rm -f Cargo.lock
+endef
+
+CARGO_BUILD = \
+       $(CARGO) \
+       build \
+       $(MAKETUNING) \
+       --release
+
+# Checks whether this crate has a right taregt
+CARGO_TARGET_CHECK = cargo metadata --format-version 1 | \
+       jq -e ".packages[].targets[].kind | any(. == \"$(1)\")" | grep -q "true"
+
+define CARGO_INSTALL
+       mkdir -pv "$(CRATE_PATH)" && \
+       if $(call CARGO_TARGET_CHECK,lib); then \
+               awk \
+                       '/^\\\[((.+\\\.)?((dev|build)-)?dependencies|features)/{f=1;next} /^\\\[/{f=0}; !f' \
+                       < Cargo.toml > Cargo.toml.deps && \
+               $(CARGO) package -l | grep -wEv "Cargo.(lock|toml.orig)" \
+                       | xargs -d "\n" cp --parents -a -t $(CRATE_PATH) && \
+               install -v -m 644 Cargo.toml.deps $(CRATE_PATH)/Cargo.toml && \
+               echo "{\"files\":{},\"package\":\"\"}" > $(CRATE_PATH)/.cargo-checksum.json; \
+       fi && \
+       if $(call CARGO_TARGET_CHECK,bin); then \
+               $(CARGO) install --no-track --path .; \
+       fi
+endef
 
 ###############################################################################
 # Common Macro Definitions
@@ -183,7 +259,7 @@ define POSTBUILD
        @echo "Updating linker cache..."
        @type -p ldconfig >/dev/null && ldconfig || :
        @echo "Install done; saving file list to $(TARGET) ..."
-       @rm -rf $(GOPATH) $(CARGOPATH)
+       @rm -rf $(GOPATH)
        @$(FIND_FILES) > $(DIR_SRC)/lsalrnew
        @diff $(DIR_SRC)/lsalr $(DIR_SRC)/lsalrnew | grep '^> ' | sed 's/^> //' > $(TARGET)_diff
        @cp -f $(DIR_SRC)/lsalrnew $(DIR_SRC)/lsalr
index 7ff84379ba009f62cc4fc0698b076147e7156b83..2fbc3254ee3494cbe87a4f65f77a1405e9c7ed9c 100644 (file)
--- a/lfs/rust
+++ b/lfs/rust
@@ -90,5 +90,8 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
        # Remove LLVM tools
        rm -vf /usr/lib/rustlib/$(RUST_BOOTSTRAP)/bin/rust-ll{d,vm-dwp}
 
+       # Create local registry
+       mkdir -pv $(CARGO_REGISTRY)
+
        @rm -rf $(DIR_APP)
        @$(POSTBUILD)