1# This is a small action which uses the pre-installed Android NDK on GitHub
2# Actions builders, configured with `$ANDROID_NDK`, to compile and link Android
3# code. For Rust we mostly need to configure the linker to Cargo and the C
4# compiler to the `cc` crate, so this sets various environment variables to the
5# appropriate tool within `$ANDROID_NDK`.
6
7name: 'Setup Rust to use the Android NDK'
8description: 'Setup Rust to use the android NDK'
9
10inputs:
11  target:
12    description: 'Rust target being used'
13    required: true
14  android-platform:
15    description: 'Platform version to use for the C compiler'
16    required: false
17    default: '26'
18
19runs:
20  using: composite
21  steps:
22    - run: |
23        target=${{ inputs.target }}
24        cc_target=$(echo ${{ inputs.target }} | tr - _)
25        upcase=$(echo $target | tr a-z- A-Z_)
26        ndk_bin=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin
27        linker=$ndk_bin/${target}${{ inputs.android-platform }}-clang
28        echo CARGO_TARGET_${upcase}_LINKER=$linker >> $GITHUB_ENV
29        echo CC_${cc_target}=$linker >> $GITHUB_ENV
30        echo RANLIB_${cc_target}=$ndk_bin/llvm-ranlib >> $GITHUB_ENV
31        echo AR_${cc_target}=$ndk_bin/llvm-ar >> $GITHUB_ENV
32      shell: bash
33