mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-27 03:07:43 +02:00
make.sh: Add some commands to build Rust packages
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>
This commit is contained in:
@@ -64,6 +64,7 @@
|
|||||||
#usr/lib/rustlib/rust-installer-version
|
#usr/lib/rustlib/rust-installer-version
|
||||||
#usr/lib/rustlib/uninstall.sh
|
#usr/lib/rustlib/uninstall.sh
|
||||||
#usr/libexec/cargo-credential-1password
|
#usr/libexec/cargo-credential-1password
|
||||||
|
#usr/share/cargo/registry
|
||||||
#usr/share/doc/cargo
|
#usr/share/doc/cargo
|
||||||
#usr/share/doc/cargo/LICENSE-APACHE
|
#usr/share/doc/cargo/LICENSE-APACHE
|
||||||
#usr/share/doc/cargo/LICENSE-MIT
|
#usr/share/doc/cargo/LICENSE-MIT
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
#usr/lib/rustlib/rust-installer-version
|
#usr/lib/rustlib/rust-installer-version
|
||||||
#usr/lib/rustlib/uninstall.sh
|
#usr/lib/rustlib/uninstall.sh
|
||||||
#usr/libexec/cargo-credential-1password
|
#usr/libexec/cargo-credential-1password
|
||||||
|
#usr/share/cargo/registry
|
||||||
#usr/share/doc/cargo
|
#usr/share/doc/cargo
|
||||||
#usr/share/doc/cargo/LICENSE-APACHE
|
#usr/share/doc/cargo/LICENSE-APACHE
|
||||||
#usr/share/doc/cargo/LICENSE-MIT
|
#usr/share/doc/cargo/LICENSE-MIT
|
||||||
|
|||||||
@@ -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/libunicode_width-ca628c5eca5e5caf.rlib
|
||||||
#usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-5c4d6c9d7595f844.rlib
|
#usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-5c4d6c9d7595f844.rlib
|
||||||
#usr/libexec/cargo-credential-1password
|
#usr/libexec/cargo-credential-1password
|
||||||
|
#usr/share/cargo/registry
|
||||||
#usr/share/doc/cargo
|
#usr/share/doc/cargo
|
||||||
#usr/share/doc/cargo/LICENSE-APACHE
|
#usr/share/doc/cargo/LICENSE-APACHE
|
||||||
#usr/share/doc/cargo/LICENSE-MIT
|
#usr/share/doc/cargo/LICENSE-MIT
|
||||||
|
|||||||
80
lfs/Config
80
lfs/Config
@@ -34,6 +34,18 @@
|
|||||||
unexport BUILD_ARCH BUILD_PLATFORM BUILDTARGET CROSSTARGET TOOLCHAIN TOOLS_DIR
|
unexport BUILD_ARCH BUILD_PLATFORM BUILDTARGET CROSSTARGET TOOLCHAIN TOOLS_DIR
|
||||||
unexport XZ_OPT
|
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 $$( \
|
PARALLELISM = $(shell echo $$( \
|
||||||
if [ -n "$(MAX_PARALLELISM)" ] && [ $(MAX_PARALLELISM) -lt 1 ]; then \
|
if [ -n "$(MAX_PARALLELISM)" ] && [ $(MAX_PARALLELISM) -lt 1 ]; then \
|
||||||
echo 1 ; \
|
echo 1 ; \
|
||||||
@@ -140,7 +152,71 @@ ifeq "$(BUILD_ARCH)" "aarch64"
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# Rust
|
# 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
|
# Common Macro Definitions
|
||||||
@@ -183,7 +259,7 @@ define POSTBUILD
|
|||||||
@echo "Updating linker cache..."
|
@echo "Updating linker cache..."
|
||||||
@type -p ldconfig >/dev/null && ldconfig || :
|
@type -p ldconfig >/dev/null && ldconfig || :
|
||||||
@echo "Install done; saving file list to $(TARGET) ..."
|
@echo "Install done; saving file list to $(TARGET) ..."
|
||||||
@rm -rf $(GOPATH) $(CARGOPATH)
|
@rm -rf $(GOPATH)
|
||||||
@$(FIND_FILES) > $(DIR_SRC)/lsalrnew
|
@$(FIND_FILES) > $(DIR_SRC)/lsalrnew
|
||||||
@diff $(DIR_SRC)/lsalr $(DIR_SRC)/lsalrnew | grep '^> ' | sed 's/^> //' > $(TARGET)_diff
|
@diff $(DIR_SRC)/lsalr $(DIR_SRC)/lsalrnew | grep '^> ' | sed 's/^> //' > $(TARGET)_diff
|
||||||
@cp -f $(DIR_SRC)/lsalrnew $(DIR_SRC)/lsalr
|
@cp -f $(DIR_SRC)/lsalrnew $(DIR_SRC)/lsalr
|
||||||
|
|||||||
3
lfs/rust
3
lfs/rust
@@ -90,5 +90,8 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
|
|||||||
# Remove LLVM tools
|
# Remove LLVM tools
|
||||||
rm -vf /usr/lib/rustlib/$(RUST_BOOTSTRAP)/bin/rust-ll{d,vm-dwp}
|
rm -vf /usr/lib/rustlib/$(RUST_BOOTSTRAP)/bin/rust-ll{d,vm-dwp}
|
||||||
|
|
||||||
|
# Create local registry
|
||||||
|
mkdir -pv $(CARGO_REGISTRY)
|
||||||
|
|
||||||
@rm -rf $(DIR_APP)
|
@rm -rf $(DIR_APP)
|
||||||
@$(POSTBUILD)
|
@$(POSTBUILD)
|
||||||
|
|||||||
Reference in New Issue
Block a user