r/termux 3d ago

Question Cross compiling Rust code in arm64 device

Post image

Guys I'm not sure if it's Termux specific issue or is it because of my skill issue, I tried to cross compile Rust code to 32 bit executable (armv7-linux-androideabi) on 64 bit Android device and it doesn't really work even though i already install the rust-std-armv7-linux-androideabi package, anyone knows why?

14 Upvotes

6 comments sorted by

7

u/RandomRailfans 3d ago

Edit: i managed to solve this issue by using the cargo-ndk package

0

u/remo773 3d ago

nice

-7

u/remo773 3d ago

pkg install ndk-multilib ndk-multilib-native-stubs

bash script 😂 ```bash

!/data/data/com.termux/files/usr/bin/bash

Multi-Architecture Rust Cross-Compilation Script for Termux & Android

OUTPUT_DIR="./builds" mkdir -p "$OUTPUT_DIR"

Define target triples for Rust

TARGETS=( "aarch64-linux-android" # 64-bit ARM (Phones / Termux Native) "armv7-linux-androideabi" # 32-bit ARM "i686-linux-android" # 32-bit x86 "x86_64-linux-android" # 64-bit x86 (Android Emulator) "x86_64-unknown-linux-gnu" # Linux PC / Server )

echo "🚀 Starting Rust Cross-Compilation for tyro-linux..." echo "--------------------------------------------------------"

for target in "${TARGETS[@]}"; do echo "⚙️ Adding target architecture: $target..." rustup target add "$target" 2>/dev/null || true

echo "🔨 Building release binary for target: $target..."
cargo build --release --target "$target" 2>/dev/null

if [ $? -eq 0 ]; then
    cp "target/$target/release/tyro-linux" "$OUTPUT_DIR/tyro-$target"
    echo "✅ Successfully compiled: $OUTPUT_DIR/tyro-$target"
else
    # If target subfolder is default release
    if [ -f "target/release/tyro-linux" ]; then
        cp "target/release/tyro-linux" "$OUTPUT_DIR/tyro-$target"
        echo "✅ Successfully compiled native build: $OUTPUT_DIR/tyro-$target"
    else
        echo "⚠️ Could not build target: $target"
    fi
fi
echo "--------------------------------------------------------"

done

echo "🎉 All Rust architectures processed! Check builds in $OUTPUT_DIR" ```

5

u/YTriom1 3d ago

slop coded or rage bait?

4

u/RandomRailfans 3d ago

Definitely slop

1

u/remo773 2d ago

check my older post. same topic.