patches for the latest rustc compiler

Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
Uncle Stinky 2026-02-05 18:19:54 +03:00
parent e12b85d5da
commit 4348580127
Signed by: st1nky
GPG Key ID: 016064BD97603B40
5 changed files with 98 additions and 50 deletions

View File

@ -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

View File

@ -1,7 +1,7 @@
DEFAULT_SERVICE_NAME="ghost-node.service"
#!/bin/bash
SERVICE_NAME="${1:-ghost-node.service}"
check_unit_file_validity() {
SERVICE_NAME=$1
if [[ "$SERVICE_NAME" != *.service ]]; then
SERVICE_NAME="${SERVICE_NAME}.service"
fi
@ -13,20 +13,13 @@ check_unit_file_validity() {
if [[ -z "$NETWORK_ONLINE_EXISTS" && -n "$NETWORK_EXISTS" ]]
then
echo "[-] WARNING: missing network-online.target dependency in $SERVICE_FULL_PATH, trying to replace"
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 "[+] INFO: network-online.target is set correctly for $SERVICE_FULL_PATH"
echo "[+] patch-1 already applied: network-online.target is set correctly for $SERVICE_FULL_PATH"
fi
else
echo "[-] No serivce found at $SERVICE_FULL_PATH"
echo "[-] patch-1 skipped: no serivce found at $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

16
scripts/patches/patch-2.sh Executable file
View File

@ -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

17
scripts/patches/patch-3.sh Executable file
View File

@ -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

View File

@ -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..."