From 5a9338a1870bab0bb932ab74b4365367d01feb12 Mon Sep 17 00:00:00 2001 From: Flux Date: Tue, 21 Jan 2025 17:05:38 +0200 Subject: [PATCH] intel archs conditional --- rust_to_flutter.sh | 68 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/rust_to_flutter.sh b/rust_to_flutter.sh index cd730d6..aa03ea5 100644 --- a/rust_to_flutter.sh +++ b/rust_to_flutter.sh @@ -1,24 +1,51 @@ -#!/bin/bash +#!/usr/bin/env bash set -e # Check for required arguments +if [ "$#" -lt 2 ]; then + echo "Usage: $0 [-x] " + echo " -x: Include x86 and x86_64 targets (optional)" + exit 1 +fi + +# Parse optional -x flag +INCLUDE_X86=false +while getopts ":x" opt; do + case $opt in + x) + INCLUDE_X86=true + ;; + *) + echo "Invalid option: -$OPTARG" + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +# Validate remaining arguments if [ "$#" -ne 2 ]; then - echo "Usage: $0 " + echo "Usage: $0 [-x] " exit 1 fi # Convert to absolute paths -RUST_PROJECT_FOLDER=$(cd "$1" && pwd) -FLUTTER_PROJECT_FOLDER=$(cd "$2" && pwd) +RUST_PROJECT_FOLDER="$(cd "$1" && pwd)" +FLUTTER_PROJECT_FOLDER="$(cd "$2" && pwd)" # Supported targets for Android -ANDROID_ARCHS=("arm64-v8a" "armeabi-v7a" "x86_64" "x86") -ANDROID_TARGETS=("aarch64-linux-android" "armv7-linux-androideabi" "x86_64-linux-android" "i686-linux-android") +ANDROID_ARCHS=("arm64-v8a" "armeabi-v7a") +ANDROID_TARGETS=("aarch64-linux-android" "armv7-linux-androideabi") +if [ "$INCLUDE_X86" = true ]; then + ANDROID_ARCHS+=("x86_64" "x86") + ANDROID_TARGETS+=("x86_64-linux-android" "i686-linux-android") +fi + IOS_TARGETS=("aarch64-apple-ios" "x86_64-apple-ios") # Check if on macOS for iOS targets -if [[ "$OSTYPE" == "darwin"* ]]; then +if [[ "${OSTYPE:-}" == "darwin"* ]]; then INCLUDE_IOS_TARGETS=true else INCLUDE_IOS_TARGETS=false @@ -26,11 +53,11 @@ else fi # Enter the Rust project folder -cd "$RUST_PROJECT_FOLDER" || exit +cd "$RUST_PROJECT_FOLDER" || exit 1 # Function to check and install missing targets install_missing_targets() { - for target in "${@}"; do + for target in "$@"; do if ! rustup target list --installed | grep -q "$target"; then echo "Installing target: $target" rustup target add "$target" @@ -64,11 +91,10 @@ if [ "$INCLUDE_IOS_TARGETS" = true ]; then done fi - # Copy compiled libraries to Flutter project for Android for i in "${!ANDROID_ARCHS[@]}"; do - arch=${ANDROID_ARCHS[$i]} - target=${ANDROID_TARGETS[$i]} + arch="${ANDROID_ARCHS[$i]}" + target="${ANDROID_TARGETS[$i]}" RELEASE_DIR="target/$target/release" LIB_FILE=$(find "$RELEASE_DIR" -maxdepth 1 -name "lib*.so" | head -n 1) @@ -76,7 +102,7 @@ for i in "${!ANDROID_ARCHS[@]}"; do DEST_DIR="$FLUTTER_PROJECT_FOLDER/android/app/src/main/jniLibs/$arch" mkdir -p "$DEST_DIR" cp "$LIB_FILE" "$DEST_DIR/" - echo "Copied $arch library to $2/android/app/src/main/jniLibs/$arch" + echo "Copied $arch library to $DEST_DIR" else echo "No .so files found for $arch in $RELEASE_DIR" fi @@ -87,14 +113,14 @@ if [ "$INCLUDE_IOS_TARGETS" = true ]; then IOS_DEST_DIR="$FLUTTER_PROJECT_FOLDER/ios/Runner" mkdir -p "$IOS_DEST_DIR" for target in "${IOS_TARGETS[@]}"; do - RELEASE_DIR="target/$target/release" - LIB_FILE=$(find "$RELEASE_DIR" -maxdepth 1 -name "lib*.so" | head -n 1) - if [ -n "$LIB_FILE" ]; then - cp "$LIB_FILE" "$IOS_DEST_DIR/" - echo "Copied $target library to $IOS_DEST_DIR" - else - echo "No library found for $target in $RELEASE_DIR" - fi + RELEASE_DIR="target/$target/release" + LIB_FILE=$(find "$RELEASE_DIR" -maxdepth 1 -name "lib*.a" | head -n 1) + if [ -n "$LIB_FILE" ]; then + cp "$LIB_FILE" "$IOS_DEST_DIR/" + echo "Copied $target library to $IOS_DEST_DIR" + else + echo "No library found for $target in $RELEASE_DIR" + fi done fi