Skip to content

Conversation

@Leojangh
Copy link

Hi ! This change makes aarch64-linux-android available! Now it can run on Android.

@DelSkayn
Copy link
Owner

DelSkayn commented Jan 23, 2025

Hi! Thanks for your contribution.

Unfortunately we don't accept PR for platforms that do not add support for also generating the bindings and test compiling in CI.

This is to ensure we are able to keep the platform supported in the future.

If you can make that improvement than I can consider to merge this PR.

@Leojangh
Copy link
Author

Hi! Thanks for your contribution.

Unfortunately we don't accept PR for platforms that do not add support for also generating the bindings and test compiling in CI.

This is to ensure we are able to keep the platform supported in the future.

If you can make that improvement than I can consider to merge this PR.

OK I'm going to improve it.

xuxiaocheng0201 added a commit to xuxiaocheng0201/example-rquickjs-android that referenced this pull request Mar 4, 2025
xuxiaocheng0201 added a commit to xuxiaocheng0201/example-rquickjs-android that referenced this pull request Mar 4, 2025
@xuxiaocheng0201
Copy link

xuxiaocheng0201 commented Mar 10, 2025

An example of building Android using GitHub Actions (I have tried almost fifty times):
.github/workflows/ci.yml:

name: Build

permissions:
  contents: read

on:
  push:
    branch:
      - master

env:
  CARGO_TERM_COLOR: always

jobs:
  build-android:
    name: Build android
    runs-on: ubuntu-latest
    steps:
      - name: Check rust version
        run: rustup --version

      - name: Checkout
        uses: actions/checkout@v4

      - name: Build arm64
        run: |
          rustup target add aarch64-linux-android
          export CC_aarch64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang
          export CXX_aarch64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang++
          export AR_aarch64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
          export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$CC_aarch64_linux_android
          export CLANG_PATH=$CC_aarch64_linux_android
          cargo build --target aarch64-linux-android --release -vv
        env:
          RUST_BACKTRACE: full

      - name: Build arm32
        run: |
          rustup target add armv7-linux-androideabi
          export CC_armv7_linux_androideabi=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi30-clang
          export CXX_armv7_linux_androideabi=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi30-clang++
          export AR_armv7_linux_androideabi=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
          export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=$CC_armv7_linux_androideabi
          export CLANG_PATH=$CC_armv7_linux_androideabi
          cargo build --target armv7-linux-androideabi --release -vv
        env:
          RUST_BACKTRACE: full

      - name: Build x86_64
        run: |
          rustup target add x86_64-linux-android
          export CC_x86_64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang
          export CXX_x86_64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android30-clang++
          export AR_x86_64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
          export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=$CC_x86_64_linux_android
          export CLANG_PATH=$CC_x86_64_linux_android
          cargo build --target x86_64-linux-android --release -vv
        env:
          RUST_BACKTRACE: full

      - name: Build x86_32
        run: |
          rustup target add i686-linux-android
          export CC_i686_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android30-clang
          export CXX_i686_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android30-clang++
          export AR_i686_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
          export CARGO_TARGET_I686_LINUX_ANDROID_LINKER=$CC_i686_linux_android
          export CLANG_PATH=$CC_i686_linux_android
          cargo build --target i686-linux-android --release -vv
        env:
          RUST_BACKTRACE: full

Cargo.toml:

[package]
name = "example-rquickjs-android"
version = "0.1.0"
edition = "2024"

[dependencies]
rquickjs = { version = "~0.9", features = ["bindgen"] }

src/main.rs:

fn main() -> rquickjs::Result<()> {
    let runtime = rquickjs::Runtime::new()?;
    let context = rquickjs::Context::full(&runtime)?;
    let string = context.with(|ctx| ctx.eval::<String, _>("'Hello, World!'"))?;
    println!("{string}");
    Ok(())
}

@srfsh
Copy link

srfsh commented Apr 1, 2025

For what is worth, this works fine for me.

_ => panic!("Unsupported platform"),
};
let is_windows = env::consts::OS == "windows";
let clang = format!("{ndk}\\toolchains\\llvm\\prebuilt\\{host_tag}\\bin\\aarch64-linux-android{min_sdk}-clang") + if is_windows { ".cmd" } else { "" };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails on linux due to path separators

Copy link

@xuxiaocheng0201 xuxiaocheng0201 May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try the ci.yml I wrote above. It doesn't need this PR.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a custom build process with macroquad, but thanks for info, I will try replicating it

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone finding this through search: the way to make rquickjs work with macroquad android target is to modify the cargo-quad-apk like this:

juh9870/cargo-quad-apk-bindgen@3ed23b9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants