tanis2000 / minigame-rust

A simple game made in Rust that runs on desktop and mobile
MIT License
122 stars 18 forks source link

Using SDL_TTF #10

Open trezm opened 6 years ago

trezm commented 6 years ago

Hey all! Amazing work done here, honestly!!! I've been looking for a good starting place to write a rust game in SDL2 for my Android phone and I've found it :)

That being said -- I was able to get a good build script working (see below,) but I can't seem to figure out how to include SDL_TTF in the bundle. Does anyone have a good idea of where I could start?

#!/bin/bash

###
#
# $1 is the ndk location
# $2 is the output for platform dependent toolchains
# $3 is the android sdk

export ANDROID_NDK_HOME=$1
export ANDROID_HOME=$3
echo "Building toolchain..."
$1/build/tools/make_standalone_toolchain.py --arch arm --install-dir $2/android-ndk-arm
$1/build/tools/make_standalone_toolchain.py --arch arm64 --install-dir $2/android-ndk-arm64
$1/build/tools/make_standalone_toolchain.py --arch x86 --install-dir $2/android-ndk-x86
$1/build/tools/make_standalone_toolchain.py --arch x86_64 --install-dir $2/android-ndk-x86_64

echo "Configuring..."
echo "
[target.armv7-linux-androideabi]
linker = \"$2/android-ndk-arm/bin/arm-linux-androideabi-gcc\"

[target.aarch64-linux-android]
linker = \"$2/android-ndk-arm64/bin/aarch64-linux-android-gcc\"

[target.i686-linux-android]
linker = \"$2/android-ndk-x86/bin/i686-linux-android-gcc\"

[target.x86_64-linux-android]
linker = \"$2/android-ndk-x86_64/bin/x86_64-linux-android-gcc\"
" > ./.cargo/config

echo "Building Android SDL..."
cd android/Minigame/sdl
../gradlew assemble
cd ../../..

echo "Building Rust Library..."
CC=$2/android-ndk-arm/bin/arm-linux-androideabi-gcc CXX=$2/android-ndk-arm/bin/arm-linux-androideabi-clang++ AR=$2/android-ndk-arm/bin/arm-linux-androideabi-ar cargo build --no-default-features --target armv7-linux-androideabi --lib
CC=$2/android-ndk-arm64/bin/aarch64-linux-android-gcc CXX=$2/android-ndk-arm64/bin/aarch64-linux-android-clang++ AR=$2/android-ndk-arm64/bin/aarch64-linux-android-ar cargo build --no-default-features --target aarch64-linux-android --lib
CC=$2/android-ndk-x86/bin/i686-linux-android-gcc CXX=$2/android-ndk-x86/bin/i686-linux-android-clang++ AR=$2/android-ndk-x86/bin/i686-linux-android-ar cargo build --no-default-features --target i686-linux-android --lib
CC=$2/android-ndk-x86_64/bin/x86_64-linux-android-gcc CXX=$2/android-ndk-x86_64/bin/x86_64-linux-android-clang++ AR=$2/android-ndk-x86_64/bin/x86_64-linux-android-ar cargo build --no-default-features --target x86_64-linux-android --lib

echo "Copying files..."
cp target/armv7-linux-androideabi/debug/libminigame.so android/Minigame/app/src/main/jniLibs/armeabi/
cp target/armv7-linux-androideabi/debug/libminigame.so android/Minigame/app/src/main/jniLibs/armeabi-v7a/
cp target/i686-linux-android/debug/libminigame.so android/Minigame/app/src/main/jniLibs/x86/
cp target/x86_64-linux-android/debug/libminigame.so android/Minigame/app/src/main/jniLibs/x86_64/

cp target/aarch64-linux-android/debug/libminigame.so android/Minigame/app/src/main/jniLibs/arm64-v8a/
cp $2/android-ndk-arm64/aarch64-linux-android/lib/libc++_shared.so android/Minigame/app/src/main/jniLibs/arm64-v8a/

echo "Building android app..."
cd android/Minigame/app
../gradlew assemble
cd ../../..
tanis2000 commented 6 years ago

Nice script you've come up with. I might add something similar to this project, too. I'd still need to add the iOS stuff in there as well, but that's pretty easy.

Before venturing into trying to add SDL2_TTF, are you sure you don't want to use https://github.com/redox-os/rusttype instead? I stopped using SDL2_TTF a long time ago and switched to https://github.com/nothings/stb/blob/master/stb_truetype.h which is also ported to Rust as https://github.com/dylanede/stb_truetype-rs

trezm commented 6 years ago

I wasn't aware there were other options really! I'm new to game dev specifically, so I'll give those a shot. Great resources, I'll report back how they work out :)