Add an android_api option for premake

Instead of hardcoding android21, make this option configurable.

Diffs=
d5a774b4b4 Add an android_api option for premake (#8892)

Co-authored-by: Chris Dalton <99840794+csmartdalton@users.noreply.github.com>
diff --git a/.rive_head b/.rive_head
index 09370f2..9684d81 100644
--- a/.rive_head
+++ b/.rive_head
@@ -1 +1 @@
-5328d573c738f9d597ab7dab14ef328b7d91b149
+d5a774b4b46a147fd72e3ffd9dc730ab313d4a13
diff --git a/build/build_rive.sh b/build/build_rive.sh
index 4742e6d..850305e 100755
--- a/build/build_rive.sh
+++ b/build/build_rive.sh
@@ -111,11 +111,6 @@
     fi
 else
     # New build. Parse arguments into premake options.
-    RIVE_PREMAKE_FILE="${RIVE_PREMAKE_FILE:-./premake5.lua}"
-    if [ ! -f "$RIVE_PREMAKE_FILE" ]; then
-        echo "Premake file "$RIVE_PREMAKE_FILE" not found"
-        exit -1
-    fi
 
     # Only use default arguments if RIVE_PREMAKE_ARGS is unset (not just empty).
     if [ -z "${RIVE_PREMAKE_ARGS+null_detector_string}" ]; then
@@ -132,9 +127,10 @@
                 RIVE_ARCH="${RIVE_ARCH:-universal}" # The simulator requires universal builds.
                 ;;
             "android") RIVE_OS="${RIVE_OS:-android}" ;;
-            "arm") RIVE_ARCH="${RIVE_ARCH:-arm}" ;;
             "arm64") RIVE_ARCH="${RIVE_ARCH:-arm64}" ;;
+            "arm") RIVE_ARCH="${RIVE_ARCH:-arm}" ;;
             "x64") RIVE_ARCH="${RIVE_ARCH:-x64}" ;;
+            "x86") RIVE_ARCH="${RIVE_ARCH:-x86}" ;;
             "universal") RIVE_ARCH="${RIVE_ARCH:-universal}" ;;
             "wasm") RIVE_ARCH="${RIVE_ARCH:-wasm}" ;;
             "ninja") RIVE_BUILD_SYSTEM="${RIVE_BUILD_SYSTEM:-ninja}" ;;
@@ -181,7 +177,7 @@
         RIVE_BUILD_SYSTEM="${RIVE_BUILD_SYSTEM:-gmake2}"
     fi
 
-    RIVE_PREMAKE_ARGS="$RIVE_BUILD_SYSTEM --file=$RIVE_PREMAKE_FILE --config=$RIVE_CONFIG --out=$RIVE_OUT $RIVE_PREMAKE_ARGS"
+    RIVE_PREMAKE_ARGS="$RIVE_BUILD_SYSTEM --config=$RIVE_CONFIG --out=$RIVE_OUT $RIVE_PREMAKE_ARGS"
     if [ ! -z "$RIVE_OS" ]; then RIVE_PREMAKE_ARGS="$RIVE_PREMAKE_ARGS --os=$RIVE_OS"; fi
     if [ ! -z "$RIVE_VARIANT" ]; then RIVE_PREMAKE_ARGS="$RIVE_PREMAKE_ARGS --variant=$RIVE_VARIANT"; fi
     if [ ! -z "$RIVE_ARCH" ]; then RIVE_PREMAKE_ARGS="$RIVE_PREMAKE_ARGS --arch=$RIVE_ARCH"; fi
diff --git a/build/rive_build_config.lua b/build/rive_build_config.lua
index d93aad9..52970d5 100644
--- a/build/rive_build_config.lua
+++ b/build/rive_build_config.lua
@@ -62,6 +62,12 @@
 })
 
 newoption({
+    trigger = 'android_api',
+    description = 'Target Android API version number',
+    default = '21',
+})
+
+newoption({
     trigger = 'variant',
     value = 'type',
     description = 'Choose a particular variant to build',
@@ -361,6 +367,14 @@
         ndk_toolchain = ndk_toolchain .. '/linux-x86_64'
     end
 
+    local android_base_targets = {
+        arm64 = 'aarch64-linux-android',
+        arm = 'armv7a-linux-androideabi',
+        x64 = 'x86_64-linux-android',
+        x86 = 'i686-linux-android',
+    }
+    local android_target = android_base_targets[_OPTIONS['arch']] .. _OPTIONS['android_api']
+
     -- clone the clang toolset into a custom one called "android_ndk".
     premake.tools.android_ndk = {}
     for k, v in pairs(premake.tools.clang) do
@@ -369,16 +383,20 @@
 
     -- update the android_ndk toolset to use the appropriate binaries.
     local android_ndk_tools = {
-        cc = ndk_toolchain .. '/bin/clang',
-        cxx = ndk_toolchain .. '/bin/clang++',
+        cc = ndk_toolchain .. '/bin/' .. android_target .. '-clang',
+        cxx = ndk_toolchain .. '/bin/' .. android_target .. '-clang++',
         ar = ndk_toolchain .. '/bin/llvm-ar',
     }
     function premake.tools.android_ndk.gettoolname(cfg, tool)
         return android_ndk_tools[tool]
     end
 
-    valid_cc_tools = premake.action._list['gmake2'].valid_tools['cc']
-    valid_cc_tools[#valid_cc_tools + 1] = 'android_ndk'
+    -- suppress "** Warning: Unsupported toolset 'android_ndk'".
+    local premake_valid_tools = premake.action._list[_ACTION].valid_tools
+    if premake_valid_tools ~= nil then
+        premake_valid_tools['cc'][#premake_valid_tools['cc'] + 1] = 'android_ndk'
+    end
+
     toolset('android_ndk')
 
     buildoptions({
@@ -404,62 +422,6 @@
         '-static-libstdc++',
     })
 
-    filter({ 'options:arch=x86', 'options:not for_unreal' })
-    do
-        architecture('x86')
-        buildoptions({ '--target=i686-none-linux-android21' })
-        linkoptions({ '--target=i686-none-linux-android21' })
-    end
-
-    filter({ 'options:arch=x86', 'options:for_unreal' })
-    do
-        architecture('x86')
-        buildoptions({ '--target=i686-none-linux-android31' })
-        linkoptions({ '--target=i686-none-linux-android31' })
-    end
-
-    filter({ 'options:arch=x64', 'options:not for_unreal' })
-    do
-        architecture('x64')
-        buildoptions({ '--target=x86_64-none-linux-android21' })
-        linkoptions({ '--target=x86_64-none-linux-android21' })
-    end
-
-    filter({ 'options:arch=x64', 'options:for_unreal' })
-    do
-        architecture('x64')
-        buildoptions({ '--target=x86_64-none-linux-android31' })
-        linkoptions({ '--target=x86_64-none-linux-android31' })
-    end
-
-    filter({ 'options:arch=arm', 'options:not for_unreal' })
-    do
-        architecture('arm')
-        buildoptions({ '--target=armv7a-none-linux-android21' })
-        linkoptions({ '--target=armv7a-none-linux-android21' })
-    end
-
-    filter({ 'options:arch=arm', 'options:for_unreal' })
-    do
-        architecture('arm')
-        buildoptions({ '--target=armv7a-none-linux-android31' })
-        linkoptions({ '--target=armv7a-none-linux-android31' })
-    end
-
-    filter({ 'options:arch=arm64', 'options:not for_unreal' })
-    do
-        architecture('arm64')
-        buildoptions({ '--target=aarch64-none-linux-android21' })
-        linkoptions({ '--target=aarch64-none-linux-android21' })
-    end
-
-    filter({ 'options:arch=arm64', 'options:for_unreal' })
-    do
-        architecture('arm64')
-        buildoptions({ '--target=aarch64-none-linux-android31' })
-        linkoptions({ '--target=aarch64-none-linux-android31' })
-    end
-
     filter({})
 end
 
@@ -664,10 +626,13 @@
         return emsdk_tools[tool]
     end
 
-    system('emscripten')
+    -- suppress "** Warning: Unsupported toolset 'emsdk'".
+    local premake_valid_tools = premake.action._list[_ACTION].valid_tools
+    if premake_valid_tools ~= nil then
+        premake_valid_tools['cc'][#premake_valid_tools['cc'] + 1] = 'emsdk'
+    end
 
-    valid_cc_tools = premake.action._list['gmake2'].valid_tools['cc']
-    valid_cc_tools[#valid_cc_tools + 1] = 'emsdk'
+    system('emscripten')
     toolset('emsdk')
 
     linkoptions({ '-sALLOW_MEMORY_GROWTH=1', '-sDYNAMIC_EXECUTION=0' })