From 5e5748cfd37f256370fde82ea13ffdf5cc0e457c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Sun, 10 Sep 2023 13:44:35 +0100
Subject: [PATCH 1/5] chore: initial exploration

---
 .gitignore                    |  2 ++
 frontends/libretro/Cargo.toml | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/.gitignore b/.gitignore
index 98b51824..40b4a7dc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,9 +4,11 @@ Cargo.lock
 
 /.idea
 
+/ndk
 /target
 /res/roms.prop
 /frontends/*/target
+/frontends/*/ndk
 
 /src/gen/build.rs
 /src/gen/_build.rs
diff --git a/frontends/libretro/Cargo.toml b/frontends/libretro/Cargo.toml
index eef98140..a522f8a4 100644
--- a/frontends/libretro/Cargo.toml
+++ b/frontends/libretro/Cargo.toml
@@ -18,3 +18,15 @@ cpulog = ["boytacean/cpulog"]
 
 [dependencies.boytacean]
 path = "../.."
+
+[target.aarch64-linux-android]
+ar = "./ndk/arm64/bin/aarch64-linux-android-ar"
+linker = "./ndk/arm64/bin/aarch64-linux-android-clang"
+
+[target.armv7-linux-androideabi]
+ar = "./ndk/arm/bin/arm-linux-androideabi-ar"
+linker = "./ndk/arm/bin/arm-linux-androideabi-clang"
+
+[target.i686-linux-android]
+ar = "./ndk/x86/bin/i686-linux-android-ar"
+linker = "./ndk/x86/bin/i686-linux-android-clang"

From 4dda078ef8f409e2e795cae5cccd020b0a48a445 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Sun, 10 Sep 2023 21:09:55 +0100
Subject: [PATCH 2/5] chore: initial  working structure

---
 .cargo/config.toml            | 11 +++++++++++
 frontends/libretro/Cargo.toml | 12 ------------
 2 files changed, 11 insertions(+), 12 deletions(-)
 create mode 100644 .cargo/config.toml

diff --git a/.cargo/config.toml b/.cargo/config.toml
new file mode 100644
index 00000000..8f202373
--- /dev/null
+++ b/.cargo/config.toml
@@ -0,0 +1,11 @@
+[target.aarch64-linux-android]
+ar = "./ndk/arm64/bin/aarch64-linux-android-ar"
+linker = "./ndk/arm64/bin/aarch64-linux-android-clang"
+
+[target.armv7-linux-androideabi]
+ar = "./ndk/arm/bin/arm-linux-androideabi-ar"
+linker = "./ndk/arm/bin/arm-linux-androideabi-clang"
+
+[target.i686-linux-android]
+ar = "./ndk/x86/bin/i686-linux-android-ar"
+linker = "./ndk/x86/bin/i686-linux-android-clang"
diff --git a/frontends/libretro/Cargo.toml b/frontends/libretro/Cargo.toml
index a522f8a4..eef98140 100644
--- a/frontends/libretro/Cargo.toml
+++ b/frontends/libretro/Cargo.toml
@@ -18,15 +18,3 @@ cpulog = ["boytacean/cpulog"]
 
 [dependencies.boytacean]
 path = "../.."
-
-[target.aarch64-linux-android]
-ar = "./ndk/arm64/bin/aarch64-linux-android-ar"
-linker = "./ndk/arm64/bin/aarch64-linux-android-clang"
-
-[target.armv7-linux-androideabi]
-ar = "./ndk/arm/bin/arm-linux-androideabi-ar"
-linker = "./ndk/arm/bin/arm-linux-androideabi-clang"
-
-[target.i686-linux-android]
-ar = "./ndk/x86/bin/i686-linux-android-ar"
-linker = "./ndk/x86/bin/i686-linux-android-clang"

From eb84c7fe965d57edd395ab07bfd6bc3a3f92926c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Sun, 10 Sep 2023 21:26:20 +0100
Subject: [PATCH 3/5] docs: build information for Android

---
 frontends/libretro/README.md | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/frontends/libretro/README.md b/frontends/libretro/README.md
index bcf317a0..b234824d 100644
--- a/frontends/libretro/README.md
+++ b/frontends/libretro/README.md
@@ -5,3 +5,30 @@
 ```bash
 cargo build
 ```
+
+### Android
+
+Configure `NDK_HOME` environment variable to point to your Android NDK directory and then create local toolchain replicas in the root project directory using:
+
+```bash
+mkdir -p ndk
+${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch arm64 --install-dir ndk/arm64
+${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch arm --install-dir ndk/arm
+${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch x86 --install-dir ndk/x86
+```
+
+To install the Rust targets for Android using rustup run:
+
+```bash
+rustup target add aarch64-linux-android
+rustup target add armv7-linux-androideabi
+rustup target add i686-linux-android
+```
+
+Then you're ready to build Boytacean's libretro core using the following commands (for release builds):
+
+```bash
+cargo build --target=aarch64-linux-android --release
+cargo build --target=armv7-linux-androideabi --release
+cargo build --target=i686-linux-android --release
+```

From 77afe97143afd37ef20aabd53042dbb92b0703df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Sat, 16 Sep 2023 16:53:45 +0100
Subject: [PATCH 4/5] chore: initial build for libretro android

---
 .github/workflows/main.yml | 60 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 111590e4..b27ea8c4 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -170,3 +170,63 @@ jobs:
       - name: Build release version
         run: cd frontends/libretro && cargo build --release
         if: matrix.rust-version == '1.71.0'
+  build-libretro-android:
+    name: Build Libretro Android
+    timeout-minutes: 30
+    strategy:
+      matrix:
+        rust-version: [
+          "1.71.0",
+          "latest"
+        ]
+    runs-on: ubuntu-latest
+    container: rust:${{ matrix.rust-version }}
+    steps:
+      - name: Checkout code from repository
+        uses: actions/checkout@v3
+      - name: Install Android NDK
+        uses: nttld/setup-ndk@v1
+        id: setup-ndk
+        with:
+          ndk-version: r25c
+      - name: Install Dependencies
+        run: |
+          apt-get update
+          apt-get install -y -q zip
+      - name: Install Rust components
+        run: |
+          rustup component add rustfmt
+          rustup component add clippy
+      - name: Print Rust information
+        run: rustc --version
+      - name: Setup local NDK
+        run: |
+          mkdir -p ndk
+          ${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch arm64 --install-dir ndk/arm64
+          ${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch arm --install-dir ndk/arm
+          ${NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch x86 --install-dir ndk/x86
+        env:
+          NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
+      - name: Add Rust Android targets
+        run: |
+          rustup target add aarch64-linux-android
+          rustup target add armv7-linux-androideabi
+          rustup target add i686-linux-android
+      - name: Verify Rust code format
+        run: cd frontends/libretro && cargo fmt --all -- --check
+      - name: Verify Rust code linting
+        run: cd frontends/libretro && cargo clippy -- -D warnings -A unknown-lints
+      - name: Run unit tests
+        run: cd frontends/libretro && cargo test
+      - name: Build development version
+        run: |
+          cd frontends/libretro
+          cargo build --target=aarch64-linux-android
+          cargo build --target=armv7-linux-androideabi
+          cargo build --target=i686-linux-android
+      - name: Build release version
+        run: |
+          cd frontends/libretro
+          cargo build --target=aarch64-linux-android --release
+          cargo build --target=armv7-linux-androideabi --release
+          cargo build --target=i686-linux-android --release

From e06c1d4c8102e7d6bc404c32dac7369dc6e5736d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Sat, 16 Sep 2023 17:03:02 +0100
Subject: [PATCH 5/5] chore: new info file delivery

---
 .github/workflows/deploy.yml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 81a03996..ec5e0f3a 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -34,6 +34,7 @@ jobs:
         with:
           name: boytacean-linux
           path: |
+            frontends/libretro/res/boytacean_libretro.info
             target/release/boytacean-sdl-linux-x64
             target/release/libboytacean.so
             target/release/boytacean_libretro.so
@@ -153,6 +154,7 @@ jobs:
         uses: softprops/action-gh-release@v1
         with:
           files: |
+            boytacean-linux//boytacean_libretro.info
             boytacean-linux/boytacean-sdl-linux-x64
             boytacean-linux/libboytacean.so
             boytacean-linux/boytacean_libretro.so