feat: Add strip (not working)

This commit is contained in:
2026-02-07 22:36:07 +01:00
parent 2595cc5cf0
commit b6ea57e70d
4 changed files with 278 additions and 188 deletions

View File

@@ -14,18 +14,24 @@ LINUX_TARGET="x86_64-unknown-linux-gnu"
ANDROID_TARGETS=("aarch64-linux-android" "armv7-linux-androideabi" "x86_64-linux-android")
WINDOWS_TARGET="x86_64-pc-windows-gnu"
# Build command with size optimizations
# We use nightly for -Z build-std to significantly reduce binary size
export RUSTUP_TOOLCHAIN=nightly
BUILD_CMD="cargo build --release -Z build-std=std,panic_abort -Zunstable-options"
echo "=== Building for Linux ($LINUX_TARGET) ==="
cargo build --release --target $LINUX_TARGET
$BUILD_CMD --target $LINUX_TARGET
echo "=== Building for Android ==="
for target in "${ANDROID_TARGETS[@]}"; do
echo "--- Building $target ---"
cargo ndk -t $target build --release
# Use cargo ndk with nightly toolchain inherited from environment
cargo ndk -t $target build --release -Z build-std=std,panic_abort -Zunstable-options
done
echo "=== Building for Windows ($WINDOWS_TARGET) ==="
if rustup target list --installed | grep -q "$WINDOWS_TARGET" && command -v x86_64-w64-mingw32-gcc >/dev/null; then
cargo build --release --target $WINDOWS_TARGET
$BUILD_CMD --target $WINDOWS_TARGET
else
echo "Warning: Windows target or x86_64-w64-mingw32-gcc not found. Skipping Windows build."
fi
@@ -44,27 +50,46 @@ cargo run --features uniffi-cli --bin uniffi-bindgen generate \
--out-dir "$KOTLIN_SRC_DIR" \
--no-format
echo "=== Organizing Native Libraries ==="
echo "=== Organizing and Stripping Native Libraries ==="
# Use llvm-strip from NDK if available, otherwise fallback to system strip
if [ -n "$ANDROID_NDK_HOME" ] && [ -f "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip" ]; then
STRIP="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip"
else
STRIP="strip"
fi
echo "Using strip tool: $STRIP"
# Linux x86_64
mkdir -p "$KOTLIN_RES_DIR/linux-x86-64"
cp "target/$LINUX_TARGET/release/${LIB_NAME}.so" "$KOTLIN_RES_DIR/linux-x86-64/${LIB_NAME}.so"
"$STRIP" --strip-all "$KOTLIN_RES_DIR/linux-x86-64/${LIB_NAME}.so"
# Android
mkdir -p "$KOTLIN_RES_DIR/lib/arm64-v8a"
cp "target/aarch64-linux-android/release/${LIB_NAME}.so" "$KOTLIN_RES_DIR/lib/arm64-v8a/${LIB_NAME}.so"
"$STRIP" --strip-all "$KOTLIN_RES_DIR/lib/arm64-v8a/${LIB_NAME}.so"
mkdir -p "$KOTLIN_RES_DIR/lib/armeabi-v7a"
cp "target/armv7-linux-androideabi/release/${LIB_NAME}.so" "$KOTLIN_RES_DIR/lib/armeabi-v7a/${LIB_NAME}.so"
"$STRIP" --strip-all "$KOTLIN_RES_DIR/lib/armeabi-v7a/${LIB_NAME}.so"
mkdir -p "$KOTLIN_RES_DIR/lib/x86_64"
cp "target/x86_64-linux-android/release/${LIB_NAME}.so" "$KOTLIN_RES_DIR/lib/x86_64/${LIB_NAME}.so"
"$STRIP" --strip-all "$KOTLIN_RES_DIR/lib/x86_64/${LIB_NAME}.so"
# Windows
WIN_DLL="target/$WINDOWS_TARGET/release/${PROJECT_NAME}.dll"
if [ -f "$WIN_DLL" ]; then
mkdir -p "$KOTLIN_RES_DIR/win32-x86-64"
cp "$WIN_DLL" "$KOTLIN_RES_DIR/win32-x86-64/${PROJECT_NAME}.dll"
# Use the mingw-specific strip for Windows DLLs if available
if command -v x86_64-w64-mingw32-strip >/dev/null; then
x86_64-w64-mingw32-strip --strip-all "$KOTLIN_RES_DIR/win32-x86-64/${PROJECT_NAME}.dll" || true
else
"$STRIP" --strip-all "$KOTLIN_RES_DIR/win32-x86-64/${PROJECT_NAME}.dll" || true
fi
fi
# This is just for me cuz I have memory like a goldfish and I will forget how to upload it to central... Leave me alone