From 1a3fa01cd0d0f24007f7c2b26908f053bd575c5d Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Sun, 11 Feb 2024 19:24:14 +0100 Subject: [PATCH] Disable Shadowsocks-Rust on 5.4 for now... --- openmptcprouter-full/Makefile | 4 +- rust/Config.in | 15 +++ rust/Makefile | 64 ++++++----- rust/files/cargo-config | 8 -- .../0001-Update-xz2-and-use-it-static.patch | 14 +-- rust/patches/0002-Bumped-libc-version.patch | 35 ------ rust/patches/0002-rustc-bootstrap-cache.patch | 52 +++++++++ .../0003-bump-libc-deps-to-0.2.146.patch | 100 ++++++++++++++++++ rust/rust-host-build.mk | 44 ++++---- rust/rust-package.mk | 30 +++--- rust/rust-values.mk | 79 +++++++++++--- shadowsocks-rust/Makefile | 13 +-- 12 files changed, 314 insertions(+), 144 deletions(-) create mode 100644 rust/Config.in delete mode 100644 rust/files/cargo-config delete mode 100644 rust/patches/0002-Bumped-libc-version.patch create mode 100644 rust/patches/0002-rustc-bootstrap-cache.patch create mode 100644 rust/patches/0003-bump-libc-deps-to-0.2.146.patch diff --git a/openmptcprouter-full/Makefile b/openmptcprouter-full/Makefile index 6ecfef576..a3aec2279 100644 --- a/openmptcprouter-full/Makefile +++ b/openmptcprouter-full/Makefile @@ -86,9 +86,11 @@ MY_DEPENDS := \ !(LINUX_5_4):mptcpd (TARGET_x86||TARGET_x86_64):kmod-igc !TARGET_mvebu:kmod-mmc-spi kmod-macsec usbutils v2ray-core LINUX_5_4:v2ray-config !LINUX_5_4:v2ray-config-nft syslogd \ (TARGET_x86||TARGET_x86_64):kmod-mlx4-core \ !(TARGET_ips40xx||TARGET_ramips):iptables-mod-ndpi !(TARGET_ips40xx||TARGET_ramips):kmod-ipt-ndpi libip4tc libip6tc \ - xray-core LINUX_5_4:xray-config !LINUX_5_4:xray-config-nft shadowsocks-rust-sslocal shadowsocks-rust-ssservice LINUX_5_4:shadowsocks-rust-config !LINUX_5_4:shadowsocks-rust-config-nft luci-app-shadowsocks-rust (LINUX_5_4&&(TARGET_x86_64||aarch64)):kmod-tcp-bbr2 kmod-ovpn-dco-v2 \ + xray-core LINUX_5_4:xray-config !LINUX_5_4:xray-config-nft (LINUX_5_4&&(TARGET_x86_64||aarch64)):kmod-tcp-bbr2 kmod-ovpn-dco-v2 \ + !LINUX_5_4:shadowsocks-rust-sslocal !LINUX_5_4:shadowsocks-rust-ssservice !LINUX_5_4:shadowsocks-rust-config-nft !LINUX_5_4:luci-app-shadowsocks-rust \ luci-proto-external omr-schedule jq luci-app-ddns +# shadowsocks-rust-sslocal shadowsocks-rust-ssservice LINUX_5_4:shadowsocks-rust-config !LINUX_5_4:shadowsocks-rust-config-nft luci-app-shadowsocks-rust \ # keepalived disabled by default because it's running even with no configuration, would need a default OMR config with some changes # (TARGET_x86||TARGET_x86_64):keepalived (TARGET_x86||TARGET_x86_64):keepalived-sync 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/Makefile b/rust/Makefile index 5e3b91df9..1555d10b7 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -3,26 +3,28 @@ # Copyright (C) 2023 Luca Barbato and Donald Hoskins include $(TOPDIR)/rules.mk -include ./rust-values.mk PKG_NAME:=rust -PKG_VERSION:=1.71.1 + +PKG_VERSION:=1.75.0 + PKG_RELEASE:=1 PKG_SOURCE:=rustc-$(PKG_VERSION)-src.tar.gz PKG_SOURCE_URL:=https://static.rust-lang.org/dist/ -PKG_HASH:=6fa90d50d1d529a75f6cc349784de57d7ec0ba2419b09bde7d335c25bd4e472e -HOST_BUILD_DIR:=$(BUILD_DIR)/host/rust-$(RUSTC_TARGET_ARCH)/rustc-$(PKG_VERSION)-src +PKG_HASH:=5b739f45bc9d341e2d1c570d65d2375591e22c2d23ef5b8a37711a0386abc088 +HOST_BUILD_DIR:=$(BUILD_DIR)/host/rustc-$(PKG_VERSION)-src PKG_MAINTAINER:=Luca Barbato PKG_LICENSE:=Apache-2.0 MIT PKG_LICENSE_FILES:=LICENSE-APACHE LICENSE-MIT -HOST_BUILD_DEPENDS:=python3/host PKG_HOST_ONLY:=1 +PKG_BUILD_FLAGS:=no-mips16 include $(INCLUDE_DIR)/host-build.mk include $(INCLUDE_DIR)/package.mk +include ./rust-values.mk define Package/rust SECTION:=lang @@ -30,7 +32,7 @@ define Package/rust SUBMENU:=Rust TITLE:=Rust Programming Language Compiler URL:=https://www.rust-lang.org/ - DEPENDS:=$(RUST_ARCH_DEPENDS) @LINUX_5_4 + DEPENDS:=$(RUST_ARCH_DEPENDS) @!(LINUX_5_4) endef define Package/rust/description @@ -39,8 +41,12 @@ define Package/rust/description guarantee memory safety by using a borrow checker to validate references. endef +define Package/rust/config + source "$(SOURCE)/Config.in" +endef + # Rust-lang has an uninstall script -RUST_UNINSTALL:=$(CARGO_HOME)/lib/rustlib/uninstall.sh +RUST_UNINSTALL:=$(STAGING_DIR)/host/lib/rustlib/uninstall.sh # Target Flags TARGET_CONFIGURE_ARGS = \ @@ -49,28 +55,29 @@ TARGET_CONFIGURE_ARGS = \ --set=target.$(RUSTC_TARGET_ARCH).cxx=$(TARGET_CXX_NOCACHE) \ --set=target.$(RUSTC_TARGET_ARCH).linker=$(TARGET_CC_NOCACHE) \ --set=target.$(RUSTC_TARGET_ARCH).ranlib=$(TARGET_RANLIB) \ + --set=target.$(RUSTC_TARGET_ARCH).crt-static=false \ $(if $(CONFIG_USE_MUSL),--set=target.$(RUSTC_TARGET_ARCH).musl-root=$(TOOLCHAIN_DIR)) # CARGO_HOME is an environmental -HOST_CONFIGURE_OPTS += CARGO_HOME="$(CARGO_HOME)" +HOST_CONFIGURE_VARS += CARGO_HOME="$(CARGO_HOME)" # Rust Configuration Arguments HOST_CONFIGURE_ARGS = \ --build=$(RUSTC_HOST_ARCH) \ --target=$(RUSTC_TARGET_ARCH),$(RUSTC_HOST_ARCH) \ --host=$(RUSTC_HOST_ARCH) \ - --prefix=$(CARGO_HOME) \ - --bindir=$(CARGO_HOME)/bin \ - --libdir=$(CARGO_HOME)/lib \ - --sysconfdir=$(CARGO_HOME)/etc \ - --datadir=$(CARGO_HOME)/share \ - --mandir=$(CARGO_HOME)/man \ - --dist-compression-formats=xz \ + --prefix=$(STAGING_DIR)/host \ + --bindir=$(STAGING_DIR)/host/bin \ + --libdir=$(STAGING_DIR)/host/lib \ + --sysconfdir=$(STAGING_DIR)/host/etc \ + --datadir=$(STAGING_DIR)/host/share \ + --mandir=$(STAGING_DIR)/host/man \ + --dist-compression-formats=gz \ --enable-missing-tools \ --disable-sanitizers \ --release-channel=stable \ --enable-cargo-native-static \ - --set=llvm.download-ci-llvm=false \ + --set=llvm.download-ci-llvm=true \ $(TARGET_CONFIGURE_ARGS) define Host/Uninstall @@ -80,23 +87,24 @@ define Host/Uninstall endef define Host/Compile - ( \ - cd $(HOST_BUILD_DIR) ; \ - $(PYTHON) x.py --config ./config.toml dist build-manifest cargo llvm-tools \ - rustc rust-std rust-src ; \ - ) + $(RUST_SCCACHE_VARS) \ + CARGO_HOME=$(CARGO_HOME) \ + TARGET_CFLAGS="$(TARGET_CFLAGS)" \ + OPENWRT_RUSTC_BOOTSTRAP_CACHE=$(DL_DIR)/rustc \ + $(PYTHON) $(HOST_BUILD_DIR)/x.py \ + --build-dir $(HOST_BUILD_DIR)/build \ + --config $(HOST_BUILD_DIR)/config.toml \ + dist build-manifest cargo llvm-tools rustc rust-std rust-src endef define Host/Install ( \ cd $(HOST_BUILD_DIR)/build/dist ; \ - find -iname "*.xz" -exec tar -xJf {} \; ; \ - find ./* -type f -name install.sh -execdir sh {} --prefix=$(CARGO_HOME) --disable-ldconfig \; ; \ - \ - sed -e 's|@RUSTC_TARGET_ARCH@|$(RUSTC_TARGET_ARCH)|g' \ - -e 's|@TARGET_CC_NOCACHE@|$(TARGET_CC_NOCACHE)|g' \ - -e 's|@RUSTC_LDFLAGS@|$(RUSTC_LDFLAGS)|g' \ - $(CURDIR)/files/cargo-config > $(CARGO_HOME)/config ; \ + for targz in *.tar.gz; do \ + $(STAGING_DIR_HOST)/bin/libdeflate-gzip -dc "$$$$targz" | tar -xf - ; \ + done ; \ + find . -mindepth 2 -maxdepth 2 -type f -name install.sh \ + -execdir bash '{}' --prefix=$(STAGING_DIR)/host --disable-ldconfig \; ; \ ) endef 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/patches/0001-Update-xz2-and-use-it-static.patch b/rust/patches/0001-Update-xz2-and-use-it-static.patch index 8d0c4b042..2360136a7 100644 --- a/rust/patches/0001-Update-xz2-and-use-it-static.patch +++ b/rust/patches/0001-Update-xz2-and-use-it-static.patch @@ -11,7 +11,7 @@ Subject: [PATCH] Update xz2 and use it static --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock -@@ -443,9 +443,9 @@ dependencies = [ +@@ -391,9 +391,9 @@ dependencies = [ [[package]] name = "lzma-sys" @@ -23,7 +23,7 @@ Subject: [PATCH] Update xz2 and use it static dependencies = [ "cc", "libc", -@@ -912,9 +912,9 @@ dependencies = [ +@@ -834,9 +834,9 @@ dependencies = [ [[package]] name = "xz2" @@ -37,12 +37,12 @@ Subject: [PATCH] Update xz2 and use it static ] --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml -@@ -50,7 +50,7 @@ toml = "0.5" - ignore = "0.4.10" - opener = "0.5" - once_cell = "1.7.2" +@@ -57,7 +57,7 @@ tar = "0.4" + termcolor = "1.2.0" + toml = "0.5" + walkdir = "2" -xz2 = "0.1" +xz2 = { version = "0.1", features = ["static"] } - walkdir = "2" # Dependencies needed by the build-metrics feature + sysinfo = { version = "0.26.0", optional = true } diff --git a/rust/patches/0002-Bumped-libc-version.patch b/rust/patches/0002-Bumped-libc-version.patch deleted file mode 100644 index 52c8a245c..000000000 --- a/rust/patches/0002-Bumped-libc-version.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 032857e7e403f654129c45dc7e6718a9ad49e377 Mon Sep 17 00:00:00 2001 -From: Nikolay Arhipov -Date: Tue, 6 Jun 2023 16:09:05 +0300 -Subject: [PATCH] Bumped libc version - ---- - Cargo.lock | 4 ++-- - library/std/Cargo.toml | 2 +- - 2 files changed, 3 insertions(+), 3 deletions(-) - ---- a/Cargo.lock -+++ b/Cargo.lock -@@ -1988,9 +1988,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0e - - [[package]] - name = "libc" --version = "0.2.143" -+version = "0.2.146" - source = "registry+https://github.com/rust-lang/crates.io-index" --checksum = "edc207893e85c5d6be840e969b496b53d94cec8be2d501b214f50daa97fa8024" -+checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" - dependencies = [ - "rustc-std-workspace-core", - ] ---- a/library/std/Cargo.toml -+++ b/library/std/Cargo.toml -@@ -15,7 +15,7 @@ cfg-if = { version = "1.0", features = [ - panic_unwind = { path = "../panic_unwind", optional = true } - panic_abort = { path = "../panic_abort" } - core = { path = "../core" } --libc = { version = "0.2.143", default-features = false, features = ['rustc-dep-of-std'] } -+libc = { version = "0.2.146", default-features = false, features = ['rustc-dep-of-std'] } - compiler_builtins = { version = "0.1.92" } - profiler_builtins = { path = "../profiler_builtins", optional = true } - unwind = { path = "../unwind" } diff --git a/rust/patches/0002-rustc-bootstrap-cache.patch b/rust/patches/0002-rustc-bootstrap-cache.patch new file mode 100644 index 000000000..959e23487 --- /dev/null +++ b/rust/patches/0002-rustc-bootstrap-cache.patch @@ -0,0 +1,52 @@ +--- a/src/bootstrap/bootstrap.py ++++ b/src/bootstrap/bootstrap.py +@@ -557,7 +557,7 @@ class RustBuild(object): + shutil.rmtree(bin_root) + + key = self.stage0_compiler.date +- cache_dst = os.path.join(self.build_dir, "cache") ++ cache_dst = os.getenv('OPENWRT_RUSTC_BOOTSTRAP_CACHE', os.path.join(self.build_dir, "cache")) + rustc_cache = os.path.join(cache_dst, key) + if not os.path.exists(rustc_cache): + os.makedirs(rustc_cache) +--- a/src/bootstrap/src/core/download.rs ++++ b/src/bootstrap/src/core/download.rs +@@ -208,7 +208,13 @@ impl Config { + Some(other) => panic!("unsupported protocol {other} in {url}"), + None => panic!("no protocol in {url}"), + } +- t!(std::fs::rename(&tempfile, dest_path)); ++ match std::fs::rename(&tempfile, dest_path) { ++ Ok(v) => v, ++ Err(_) => { ++ t!(std::fs::copy(&tempfile, dest_path)); ++ t!(std::fs::remove_file(&tempfile)); ++ } ++ } + } + + fn download_http_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) { +@@ -544,7 +550,10 @@ impl Config { + key: &str, + destination: &str, + ) { +- let cache_dst = self.out.join("cache"); ++ let cache_dst = match env::var_os("OPENWRT_RUSTC_BOOTSTRAP_CACHE") { ++ Some(v) => PathBuf::from(v), ++ None => self.out.join("cache"), ++ }; + let cache_dir = cache_dst.join(key); + if !cache_dir.exists() { + t!(fs::create_dir_all(&cache_dir)); +@@ -671,7 +680,10 @@ download-rustc = false + let llvm_assertions = self.llvm_assertions; + + let cache_prefix = format!("llvm-{llvm_sha}-{llvm_assertions}"); +- let cache_dst = self.out.join("cache"); ++ let cache_dst = match env::var_os("OPENWRT_RUSTC_BOOTSTRAP_CACHE") { ++ Some(v) => PathBuf::from(v), ++ None => self.out.join("cache"), ++ }; + let rustc_cache = cache_dst.join(cache_prefix); + if !rustc_cache.exists() { + t!(fs::create_dir_all(&rustc_cache)); diff --git a/rust/patches/0003-bump-libc-deps-to-0.2.146.patch b/rust/patches/0003-bump-libc-deps-to-0.2.146.patch new file mode 100644 index 000000000..bb131d23f --- /dev/null +++ b/rust/patches/0003-bump-libc-deps-to-0.2.146.patch @@ -0,0 +1,100 @@ +This patch bumps all libc dependencies and checksums to 0.2.147, which includes the fix for musl 1.2.4. + +--- a/vendor/addr2line-0.19.0/Cargo.lock ++++ b/vendor/addr2line-0.19.0/Cargo.lock +@@ -235,9 +235,9 @@ checksum = "e2abad23fbc42b3700f2f279844d + + [[package]] + name = "libc" +-version = "0.2.126" ++version = "0.2.147" + source = "registry+https://github.com/rust-lang/crates.io-index" +-checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" ++checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + + [[package]] + name = "memchr" +--- a/vendor/backtrace-0.3.67/Cargo.lock ++++ b/vendor/backtrace-0.3.67/Cargo.lock +@@ -64,9 +64,9 @@ checksum = "dec7af912d60cdbd3677c1af9352 + + [[package]] + name = "libc" +-version = "0.2.138" ++version = "0.2.147" + source = "registry+https://github.com/rust-lang/crates.io-index" +-checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" ++checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + + [[package]] + name = "libloading" +--- a/vendor/crossbeam-channel/Cargo.lock ++++ b/vendor/crossbeam-channel/Cargo.lock +@@ -50,9 +50,9 @@ dependencies = [ + + [[package]] + name = "libc" +-version = "0.2.141" ++version = "0.2.147" + source = "registry+https://github.com/rust-lang/crates.io-index" +-checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" ++checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + + [[package]] + name = "num_cpus" +--- a/vendor/elasticlunr-rs/Cargo.lock ++++ b/vendor/elasticlunr-rs/Cargo.lock +@@ -555,9 +555,9 @@ checksum = "e2abad23fbc42b3700f2f279844d + + [[package]] + name = "libc" +-version = "0.2.140" ++version = "0.2.147" + source = "registry+https://github.com/rust-lang/crates.io-index" +-checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" ++checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + + [[package]] + name = "lindera" +--- a/vendor/handlebars/Cargo.lock ++++ b/vendor/handlebars/Cargo.lock +@@ -550,9 +550,9 @@ checksum = "e2abad23fbc42b3700f2f279844d + + [[package]] + name = "libc" +-version = "0.2.140" ++version = "0.2.147" + source = "registry+https://github.com/rust-lang/crates.io-index" +-checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" ++checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + + [[package]] + name = "lock_api" +--- a/vendor/libffi/Cargo.lock ++++ b/vendor/libffi/Cargo.lock +@@ -10,9 +10,9 @@ checksum = "50d30906286121d95be3d479533b + + [[package]] + name = "libc" +-version = "0.2.140" ++version = "0.2.147" + source = "registry+https://github.com/rust-lang/crates.io-index" +-checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" ++checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + + [[package]] + name = "libffi" +--- a/vendor/tracing-tree/Cargo.lock ++++ b/vendor/tracing-tree/Cargo.lock +@@ -296,9 +296,9 @@ checksum = "e2abad23fbc42b3700f2f279844d + + [[package]] + name = "libc" +-version = "0.2.141" ++version = "0.2.147" + source = "registry+https://github.com/rust-lang/crates.io-index" +-checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" ++checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + + [[package]] + name = "linux-raw-sys" 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 diff --git a/rust/rust-values.mk b/rust/rust-values.mk index aaa520d57..534aaa02a 100644 --- a/rust/rust-values.mk +++ b/rust/rust-values.mk @@ -2,25 +2,32 @@ # # Copyright (C) 2023 Luca Barbato and Donald Hoskins +# Clear environment variables which should be handled internally, +# as users might configure their own env on the host + +# CCache +unexport RUSTC_WRAPPER + # Rust Environmental Vars -CONFIG_HOST_SUFFIX:=$(word 4, $(subst -, ,$(GNU_HOST_NAME))) -RUSTC_HOST_ARCH:=$(HOST_ARCH)-unknown-linux-$(CONFIG_HOST_SUFFIX) -CARGO_HOME:=$(STAGING_DIR)/host/cargo -CARGO_VARS:= +RUSTC_HOST_SUFFIX:=$(word 4, $(subst -, ,$(GNU_HOST_NAME))) +RUSTC_HOST_ARCH:=$(HOST_ARCH)-unknown-linux-$(RUSTC_HOST_SUFFIX) +CARGO_HOME:=$(DL_DIR)/cargo ifeq ($(CONFIG_USE_MUSL),y) -# Force linking of the SSP library for musl -ifdef CONFIG_PKG_CC_STACKPROTECTOR_REGULAR - ifeq ($(strip $(PKG_SSP)),1) - RUSTC_LDFLAGS += -lssp_nonshared + # Force linking of the SSP library for musl + ifdef CONFIG_PKG_CC_STACKPROTECTOR_REGULAR + ifeq ($(strip $(PKG_SSP)),1) + RUSTC_LDFLAGS+=-lssp_nonshared + endif + endif + ifdef CONFIG_PKG_CC_STACKPROTECTOR_STRONG + ifeq ($(strip $(PKG_SSP)),1) + RUSTC_LDFLAGS+=-lssp_nonshared + endif endif endif -ifdef CONFIG_PKG_CC_STACKPROTECTOR_STRONG - ifeq ($(strip $(PKG_SSP)),1) - TARGET_CFLAGS += -lssp_nonshared - endif -endif -endif + +CARGO_RUSTFLAGS+=-Ctarget-feature=-crt-static $(RUSTC_LDFLAGS) ifeq ($(HOST_OS),Darwin) ifeq ($(HOST_ARCH),arm64) @@ -51,9 +58,47 @@ ifeq ($(ARCH),arm) ifeq ($(CONFIG_HAS_FPU),y) RUSTC_TARGET_ARCH:=$(subst musleabi,musleabihf,$(RUSTC_TARGET_ARCH)) + RUSTC_TARGET_ARCH:=$(subst gnueabi,gnueabihf,$(RUSTC_TARGET_ARCH)) endif endif -#ifeq ($(ARCH),aarch64) -# RUST_CFLAGS:=-mno-outline-atomics -#endif +ifeq ($(ARCH),aarch64) + RUSTC_CFLAGS:=-mno-outline-atomics +endif + +# Support only a subset for now. +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= \ + $(RUST_SCCACHE_VARS) \ + CARGO_HOME=$(CARGO_HOME) + +CARGO_HOST_PROFILE:=release + +CARGO_PKG_CONFIG_VARS= \ + $(RUST_SCCACHE_VARS) \ + CARGO_BUILD_TARGET=$(RUSTC_TARGET_ARCH) \ + CARGO_HOME=$(CARGO_HOME) \ + CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \ + CARGO_PROFILE_RELEASE_DEBUG=false \ + CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS=false \ + CARGO_PROFILE_RELEASE_LTO=true \ + CARGO_PROFILE_RELEASE_OPT_LEVEL=z \ + CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS=true \ + CARGO_PROFILE_RELEASE_PANIC=unwind \ + CARGO_PROFILE_RELEASE_RPATH=false \ + CARGO_TARGET_$(subst -,_,$(call toupper,$(RUSTC_TARGET_ARCH)))_LINKER=$(TARGET_CC_NOCACHE) \ + RUSTFLAGS="$(CARGO_RUSTFLAGS)" \ + TARGET_CC=$(TARGET_CC_NOCACHE) \ + TARGET_CFLAGS="$(TARGET_CFLAGS) $(RUSTC_CFLAGS)" + +CARGO_PKG_PROFILE:=$(if $(CONFIG_DEBUG),dev,release) diff --git a/shadowsocks-rust/Makefile b/shadowsocks-rust/Makefile index 519722921..10e6146a6 100644 --- a/shadowsocks-rust/Makefile +++ b/shadowsocks-rust/Makefile @@ -8,13 +8,8 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=shadowsocks-rust -ifneq ($(word 1,$(subst ., ,$(LINUX_VERSION))),"5") - PKG_VERSION:=1.17.1 - PKG_HASH:=97a1c8ebf7fd19de94cd6d0dfee398667e1f4e131ec8a37ecb7c3191af7cc75e -else - PKG_VERSION:=1.18.0 - PKG_HASH:=e854743ecef9ab3b371fdcb139e6f4452831b487d449c97c2129abbf4f51e863 -endif +PKG_VERSION:=1.18.0 +PKG_HASH:=e854743ecef9ab3b371fdcb139e6f4452831b487d449c97c2129abbf4f51e863 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz @@ -29,11 +24,7 @@ PKG_BUILD_DEPENDS:=rust/host RUST_PKG_FEATURES:=local-redir include $(INCLUDE_DIR)/package.mk -ifneq ($(word 1,$(subst ., ,$(LINUX_VERSION))),"5") include $(TOPDIR)/feeds/openmptcprouter/rust/rust-package.mk -else -include $(TOPDIR)/feeds/packages/lang/rust/rust-package.mk -endif define Package/shadowsocks-rust/Default define Package/shadowsocks-rust-$(1)