From 4348580127ce96a865ef3de816389701483a60f9 Mon Sep 17 00:00:00 2001 From: Uncle Stinky Date: Thu, 5 Feb 2026 18:19:54 +0300 Subject: [PATCH] patches for the latest rustc compiler Signed-off-by: Uncle Stinky --- scripts/patch.sh | 15 ++++++++++- scripts/patches/patch-1.sh | 47 ++++++++++++++------------------- scripts/patches/patch-2.sh | 16 ++++++++++++ scripts/patches/patch-3.sh | 17 ++++++++++++ scripts/starter.sh | 53 ++++++++++++++++++++++---------------- 5 files changed, 98 insertions(+), 50 deletions(-) create mode 100755 scripts/patches/patch-2.sh create mode 100755 scripts/patches/patch-3.sh diff --git a/scripts/patch.sh b/scripts/patch.sh index 8eb362c..41401a8 100755 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -1,2 +1,15 @@ +#!/bin/bash + SCRIPT_DIR=$(dirname "$0") -bash "$SCRIPT_DIR/patches/patch-1.sh" +PATCHES_DIR="$SCRIPT_DIR/patches" + +if [[ ! -d "$PATCHES_DIR" ]]; then + echo "[-] Error: directory with patches not found: $PATCHES_DIR" + exit 1 +fi + +for patch_file in "$PATCHES_DIR"/*.sh; do + if [ -f "$patch_file" ] && [ -x "$patch_file" ]; then + "$patch_file" + fi +done diff --git a/scripts/patches/patch-1.sh b/scripts/patches/patch-1.sh index 8a28e85..400b600 100755 --- a/scripts/patches/patch-1.sh +++ b/scripts/patches/patch-1.sh @@ -1,32 +1,25 @@ -DEFAULT_SERVICE_NAME="ghost-node.service" +#!/bin/bash -check_unit_file_validity() { - SERVICE_NAME=$1 - if [[ "$SERVICE_NAME" != *.service ]]; then - SERVICE_NAME="${SERVICE_NAME}.service" - fi +SERVICE_NAME="${1:-ghost-node.service}" - SERVICE_FULL_PATH="/etc/systemd/system/$SERVICE_NAME" - if [[ -e "$SERVICE_FULL_PATH" ]]; then - NETWORK_ONLINE_EXISTS=$(grep -Fx "After=network-online.target" "$SERVICE_FULL_PATH") - NETWORK_EXISTS=$(grep -Fx "After=network.target" "$SERVICE_FULL_PATH") +if [[ "$SERVICE_NAME" != *.service ]]; then + SERVICE_NAME="${SERVICE_NAME}.service" +fi - if [[ -z "$NETWORK_ONLINE_EXISTS" && -n "$NETWORK_EXISTS" ]] - then - echo "[-] WARNING: missing network-online.target dependency in $SERVICE_FULL_PATH, trying to replace" - sudo sed -i "s/After=network.target/After=network-online.target\nRequires=network-online.target/g" "$SERVICE_FULL_PATH" - else - echo "[+] INFO: network-online.target is set correctly for $SERVICE_FULL_PATH" - fi +SERVICE_FULL_PATH="/etc/systemd/system/$SERVICE_NAME" +if [[ -e "$SERVICE_FULL_PATH" ]]; then + NETWORK_ONLINE_EXISTS=$(grep -Fx "After=network-online.target" "$SERVICE_FULL_PATH") + NETWORK_EXISTS=$(grep -Fx "After=network.target" "$SERVICE_FULL_PATH") + + if [[ -z "$NETWORK_ONLINE_EXISTS" && -n "$NETWORK_EXISTS" ]] + then + echo "[+] patch-1 will be applied: missing network-online.target dependency in $SERVICE_FULL_PATH, trying to replace" + sudo sed -i "s/After=network.target/After=network-online.target\nRequires=network-online.target/g" "$SERVICE_FULL_PATH" + echo "sudo systemctl daemon-reload" + echo "sudo systemctl restart $SERVICE_NAME" else - echo "[-] No serivce found at $SERVICE_FULL_PATH" + echo "[+] patch-1 already applied: network-online.target is set correctly for $SERVICE_FULL_PATH" fi - -} - -check_unit_file_validity $DEFAULT_SERVICE_NAME -read -p "[?] Enter names for the node service, separated by commas (default: ghost-node): " -a SERVICE_NAMES -for NAME in "${SERVICE_NAMES[@]}"; do - check_unit_file_validity $NAME -done -sudo systemctl daemon-reload +else + echo "[-] patch-1 skipped: no serivce found at $SERVICE_FULL_PATH" +fi diff --git a/scripts/patches/patch-2.sh b/scripts/patches/patch-2.sh new file mode 100755 index 0000000..8a1dc4e --- /dev/null +++ b/scripts/patches/patch-2.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +LATEST_TESTED_VERSION=83 +DEPENDENCY_PATH=~/.local/share/cargo/git/checkouts/polkadot-sdk-dee0edd6eefa0594/b401690/substrate/primitives/io/src/lib.rs + +cargo_version=$(cargo --version | cut -d'.' -f2) +if [ "$cargo_version" -gt "$LATEST_TESTED_VERSION" ]; then + if grep -q '#\[no_mangle\]' "$DEPENDENCY_PATH"; then + sed -i '/#\[no_mangle\]/d' "$DEPENDENCY_PATH" + echo "[+] patch-2 will be applied: remove unnecessary #[no_mangle] from the source code for sp-io" + else + echo "[+] patch-2 already applied: #[no_mangle] already removed from source code of sp-io" + fi +else + echo "[+] patch-2 not needed: rustc compiler version is compatible" +fi diff --git a/scripts/patches/patch-3.sh b/scripts/patches/patch-3.sh new file mode 100755 index 0000000..8ef91f4 --- /dev/null +++ b/scripts/patches/patch-3.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +LATEST_GCC_WORKING_VERSION=14 +PATH_TO_BUILD_CONFIG=~/.local/share/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/librocksdb-sys-0.11.0+8.1.1/build.rs +GCC_MAJOR=$(gcc -dumpversion | cut -d. -f1) + +if [ "$GCC_MAJOR" -gt "$LATEST_GCC_WORKING_VERSION" ]; then + if grep -q "config.flag(\"-include\").flag(\"cstdint\");" "$PATH_TO_BUILD_CONFIG"; then + echo "[+] patch-3 already applied: no need to change build config of librocksdb" + else + sed -i "/$(printf '%s' "config.compile(\"librocksdb.a\");" | sed 's/[].[*^$\/]/\\&/g')/i \ + if !target.contains(\"windows\") {\n config.flag(\"-include\").flag(\"cstdint\");\n }" "$PATH_TO_BUILD_CONFIG" + echo "[+] patch-3 will be applied: cstdint included for build config of librocksdb" + fi +else + echo "[+] patch-3 not needed: gcc version is good to compile without patch" +fi diff --git a/scripts/starter.sh b/scripts/starter.sh index 2d35f87..77ce85b 100755 --- a/scripts/starter.sh +++ b/scripts/starter.sh @@ -80,27 +80,36 @@ extract_seed() { echo $seed } -downgrade_compiler_if_needed() { - echo "[+] fetching the latest ghost-node source code" - git switch main - git pull origin main - - # 1.86.0 works fine, tested with: - # 1.87.0 throws errors during compilation - # 1.88.0 throws errors during compilation - LATEST_TESTED_VERSION=86 - cargo_version=$(cargo --version | cut -d'.' -f2) - if [ "$cargo_version" -gt "$LATEST_TESTED_VERSION" ]; then - echo "[+] downgrading rustc compiler version to 1.86.0" - rustup default 1.86.0 - toolchain_name=$(rustup show | grep default | head -n 1 | cut -d' ' -f1) - rustup target add wasm32-unknown-unknown --toolchain $toolchain_name - rustup component add rust-src --toolchain $toolchain_name - cd $PROJECT_FOLDER - echo "[+] clean build cache..." +upgrade_compiler_if_needed() { + UPDATE_STATUS=$(rustup check 2>&1) + if echo "$UPDATE_STATUS" | grep -q "Update available"; then + asd + echo "[+] clean all cache on the current system" + cargo install cargo-cache cargo clean + cargo cache --remove-dir all + + echo "[+] upgrading rustc compiler version to latest" + rustup update + toolchain_name=$(rustup show | grep default | head -n 1 | cut -d' ' -f1) + + if ! rustup target list --installed | grep -q "wasm32-unknown-unknown"; then + echo "[+] installing wasm32-unknown-unknown target" + rustup target add wasm32-unknown-unknown + fi + + if ! rustup component list --installed | grep -q "rust-src"; then + echo "[+] installing rust-src component" + rustup component add rust-src + fi + + echo "[+] fetching all dependencies" + cargo fetch + + echo "[+] trying to apply all patches" + "$SCRIPT_FOLDER"/patch.sh else - echo "[+] rustc compiler version is compatible" + echo "[+] rustc compiler version is up to date" fi } @@ -223,7 +232,7 @@ if [[ $HARD_RESET = true ]]; then exit 1 fi - downgrade_compiler_if_needed + upgrade_compiler_if_needed echo "[+] trying to stop current ghost-node" sudo systemctl stop ghost-node @@ -332,12 +341,12 @@ if [[ $SET_ENVIRONMENT = true ]]; then if prompt "[?] setup the rust environment (e.g. WASM support)?"; then rustup default stable - downgrade_compiler_if_needed + upgrade_compiler_if_needed fi fi if [[ ! -z $RELEASE ]]; then - downgrade_compiler_if_needed + upgrade_compiler_if_needed if prompt "[?] 'cargo build $RELEASE $FEATURES' is what you want?"; then cd $PROJECT_FOLDER echo "[+] starting build in 3 seconds..."