Ver código fonte

android: add script in Android archive to create a SDK

Also,
- Move mingw's pkg-support into build-scripts
- Add type annotations to python scripts for mypy
- ci: use v4 tag of actions/cache
- cmake: use PYTHON3_EXECUTABLE for running xxd.py
  (Python3::Interpreter is not always recognized.)
Anonymous Maarten 8 meses atrás
pai
commit
a1c6f99877

+ 2 - 2
.github/actions/setup-ninja/action.yml

@@ -36,7 +36,7 @@ runs:
         echo "cache-key=${archive}-${{ inputs.version }}-${{ runner.os }}-${{ runner.arch }}" >> ${GITHUB_OUTPUT}
     - name: 'Restore cached ${{ steps.calc.outputs.archive }}'
       id: cache-restore
-      uses: actions/cache/restore@main
+      uses: actions/cache/restore@v4
       with:
         path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
         key: ${{ steps.calc.outputs.cache-key }}
@@ -47,7 +47,7 @@ runs:
         Invoke-WebRequest "https://github.com/ninja-build/ninja/releases/download/v${{ inputs.version }}/${{ steps.calc.outputs.archive }}" -OutFile "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
     - name: 'Cache ${{ steps.calc.outputs.archive }}'
       if: ${{ !steps.cache-restore.outputs.cache-hit }}
-      uses: actions/cache/save@main
+      uses: actions/cache/save@v4
       with:
         path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
         key: ${{ steps.calc.outputs.cache-key }}

+ 23 - 3
.github/workflows/release.yml

@@ -596,9 +596,6 @@ jobs:
           echo "Project contents:"
           echo ""
           find "/tmp/projects/org.libsdl.testspriteminimal"
-      - name: 'Remove SDL sources to make sure they are not used'
-        run: |
-          rm -rf "${{ steps.src.outputs.path }}"
       - name: 'Copy SDL3 aar into Gradle project'
         run: |
           cp "${{ github.workspace }}/${{ needs.android.outputs.android-aar }}" "${{ steps.create-gradle-project.outputs.path }}/app/libs"
@@ -615,3 +612,26 @@ jobs:
         run: |
           cd "${{ steps.create-gradle-project.outputs.path }}"
           ./gradlew -i assembleRelease
+      - name: 'Extract Android SDK from AAR'
+        id: sdk
+        run: |
+          python "${{ github.workspace }}/${{ needs.android.outputs.android-aar }}" -o /tmp/SDL3-android
+          echo "prefix=/tmp/SDL3-android" >>$GITHUB_OUTPUT
+      - name: 'CMake (configure + build) x86, x64, arm32, arm64'
+        run: |
+          android_abis="x86 x86_64 armeabi-v7a arm64-v8a"
+          for android_abi in ${android_abis}; do
+            echo "Configure ${android_abi}"
+            cmake -S "${{ steps.src.outputs.path }}/cmake/test"                               \
+              -DTEST_FULL=TRUE                                                                \
+              -DTEST_STATIC=FALSE                                                             \
+              -DTEST_TEST=TRUE                                                                \
+              -DCMAKE_PREFIX_PATH="${{ steps.sdk.outputs.prefix }}"                           \
+              -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake  \
+              -DANDROID_ABI=${android_abi}                                                    \
+              -Werror=dev                                                                     \
+              -DCMAKE_BUILD_TYPE=Release                                                      \
+              -B "${android_abi}"
+          done
+          echo "Build ${android_abi}"
+          cmake --build "${android_abi}" --config Release --verbose

+ 3 - 0
CMakeLists.txt

@@ -3583,8 +3583,11 @@ if(NOT SDL_DISABLE_INSTALL)
   if(ANDROID)
     if(TARGET SDL3-jar)
       set(SDL_INSTALL_JAVADIR "${CMAKE_INSTALL_DATAROOTDIR}/java" CACHE PATH "Path where to install java clases + java sources")
+      set(PROGUARD_RULES_PATH "${CMAKE_CURRENT_SOURCE_DIR}/android-project/app/proguard-rules.pro")
       install(FILES $<TARGET_PROPERTY:SDL3-jar,INSTALL_FILES>
         DESTINATION "${SDL_INSTALL_JAVADIR}/SDL3")
+      install(FILES "${PROGUARD_RULES_PATH}" RENAME "proguard.txt"
+        DESTINATION "${SDL_INSTALL_JAVADIR}/SDL3")
       configure_package_config_file(cmake/SDL3jarTargets.cmake.in SDL3jarTargets.cmake
         INSTALL_DESTINATION "${SDL_SDL_INSTALL_CMAKEDIR}"
         PATH_VARS SDL_INSTALL_JAVADIR

+ 53 - 37
build-scripts/build-release.py

@@ -82,7 +82,7 @@ class VisualStudio:
         self.msbuild = self.find_msbuild()
 
     @property
-    def dry(self):
+    def dry(self) -> bool:
         return self.executer.dry
 
     VS_YEAR_TO_VERSION = {
@@ -97,7 +97,7 @@ class VisualStudio:
         vswhere_spec = ["-latest"]
         if year is not None:
             try:
-                version = cls.VS_YEAR_TO_VERSION[year]
+                version = self.VS_YEAR_TO_VERSION[year]
             except KeyError:
                 logger.error("Invalid Visual Studio year")
                 return None
@@ -115,7 +115,7 @@ class VisualStudio:
         return vsdevcmd_path
 
     def find_msbuild(self) -> typing.Optional[Path]:
-        vswhere_cmd = ["vswhere", "-latest", "-requires", "Microsoft.Component.MSBuild", "-find", "MSBuild\**\Bin\MSBuild.exe"]
+        vswhere_cmd = ["vswhere", "-latest", "-requires", "Microsoft.Component.MSBuild", "-find", r"MSBuild\**\Bin\MSBuild.exe"]
         msbuild_path = Path(self.executer.run(vswhere_cmd, stdout=True, dry_out="/tmp/MSBuild.exe").stdout.strip())
         logger.info("MSBuild path = %s", msbuild_path)
         if self.dry:
@@ -150,10 +150,10 @@ class Releaser:
         self.executer = executer
         self.cmake_generator = cmake_generator
 
-        self.artifacts = {}
+        self.artifacts: dict[str, Path] = {}
 
     @property
-    def dry(self):
+    def dry(self) -> bool:
         return self.executer.dry
 
     def prepare(self):
@@ -161,7 +161,7 @@ class Releaser:
         self.dist_path.mkdir(parents=True, exist_ok=True)
 
     TreeItem = collections.namedtuple("TreeItem", ("path", "mode", "data", "time"))
-    def _get_file_times(self, paths: tuple[str]) -> dict[str, datetime.datetime]:
+    def _get_file_times(self, paths: tuple[str, ...]) -> dict[str, datetime.datetime]:
         dry_out = textwrap.dedent("""\
             time=2024-03-14T15:40:25-07:00
 
@@ -170,18 +170,18 @@ class Releaser:
         git_log_out = self.executer.run(["git", "log", "--name-status", '--pretty=time=%cI', self.commit], stdout=True, dry_out=dry_out).stdout.splitlines(keepends=False)
         current_time = None
         set_paths = set(paths)
-        path_times = {}
+        path_times: dict[str, datetime.datetime] = {}
         for line in git_log_out:
             if not line:
                 continue
             if line.startswith("time="):
                 current_time = datetime.datetime.fromisoformat(line.removeprefix("time="))
                 continue
-            mod_type, paths = line.split(maxsplit=1)
+            mod_type, file_paths = line.split(maxsplit=1)
             assert current_time is not None
-            for path in paths.split():
-                if path in set_paths and path not in path_times:
-                    path_times[path] = current_time
+            for file_path in file_paths.split():
+                if file_path in set_paths and file_path not in path_times:
+                    path_times[file_path] = current_time
         assert set(path_times.keys()) == set_paths
         return path_times
 
@@ -191,19 +191,25 @@ class Releaser:
             return False
         return True
 
-    def _get_git_contents(self) -> dict[str, (TreeItem, bytes, datetime.datetime)]:
+    def _get_git_contents(self) -> dict[str, TreeItem]:
         contents_tgz = subprocess.check_output(["git", "archive", "--format=tar.gz", self.commit, "-o", "/dev/stdout"], text=False)
         contents = tarfile.open(fileobj=io.BytesIO(contents_tgz), mode="r:gz")
         filenames = tuple(m.name for m in contents if m.isfile())
         assert "src/SDL.c" in filenames
         assert "include/SDL3/SDL.h" in filenames
         file_times = self._get_file_times(filenames)
-        git_contents = {
-            ti.name: self.TreeItem(path=ti.name, mode=ti.mode, data=contents.extractfile(ti.name).read(), time=file_times[ti.name]) for ti in contents if ti.isfile() and self._path_filter(ti.name)
-        }
+        git_contents = {}
+        for ti in contents:
+            if not ti.isfile():
+                continue
+            if not self._path_filter(ti.name):
+                continue
+            contents_file = contents.extractfile(ti.name)
+            assert contents_file, f"{ti.name} is not a file"
+            git_contents[ti.name] = self.TreeItem(path=ti.name, mode=ti.mode, data=contents_file.read(), time=file_times[ti.name])
         return git_contents
 
-    def create_source_archives(self):
+    def create_source_archives(self) -> None:
         archive_base = f"{self.project}-{self.version}"
 
         git_contents = self._get_git_contents()
@@ -257,7 +263,7 @@ class Releaser:
 
             self.artifacts[f"src-tar-{comp}"] = tar_path
 
-    def create_xcframework(self, configuration: str="Release"):
+    def create_xcframework(self, configuration: str="Release") -> None:
         dmg_in = self.root / f"Xcode/SDL/build/SDL3.dmg"
         dmg_in.unlink(missing_ok=True)
         self.executer.run(["xcodebuild", "-project", str(self.root / "Xcode/SDL/SDL.xcodeproj"), "-target", "SDL3.dmg", "-configuration", configuration])
@@ -272,7 +278,7 @@ class Releaser:
         self.artifacts["dmg"] = dmg_out
 
     @property
-    def git_hash_data(self):
+    def git_hash_data(self) -> bytes:
         return f"{self.commit}\n".encode()
 
     def _tar_add_git_hash(self, tar_object: tarfile.TarFile, root: typing.Optional[str]=None, time: typing.Optional[datetime.datetime]=None):
@@ -285,7 +291,7 @@ class Releaser:
         tar_info = tarfile.TarInfo(path)
         tar_info.mode = 0o100644
         tar_info.size = len(self.git_hash_data)
-        tar_info.mtime = time.timestamp()
+        tar_info.mtime = int(time.timestamp())
         tar_object.addfile(tar_info, fileobj=io.BytesIO(self.git_hash_data))
 
     def _zip_add_git_hash(self, zip_file: zipfile.ZipFile, root: typing.Optional[str]=None, time: typing.Optional[datetime.datetime]=None):
@@ -301,7 +307,7 @@ class Releaser:
         zip_info.compress_type = zipfile.ZIP_DEFLATED
         zip_file.writestr(zip_info, data=self.git_hash_data)
 
-    def create_mingw_archives(self):
+    def create_mingw_archives(self) -> None:
         build_type = "Release"
         mingw_archs = ("i686", "x86_64")
         build_parent_dir = self.root / "build-mingw"
@@ -345,18 +351,18 @@ class Releaser:
                 self.executer.run(["cmake", "--install", str(build_path), "--strip", "--config", build_type])
             arch_files[arch] = list(Path(r) / f for r, _, files in os.walk(install_path) for f in files)
 
-        extra_files = [
-            ("mingw/pkg-support/INSTALL.txt", ""),
-            ("mingw/pkg-support/Makefile", ""),
-            ("mingw/pkg-support/cmake/sdl3-config.cmake", "cmake/"),
-            ("mingw/pkg-support/cmake/sdl3-config-version.cmake", "cmake/"),
+        extra_files = (
+            ("build-scripts/pkg-support/mingw/INSTALL.txt", ""),
+            ("build-scripts/pkg-support/mingw/Makefile", ""),
+            ("build-scripts/pkg-support/mingw/cmake/SDL3Config.cmake", "cmake/"),
+            ("build-scripts/pkg-support/mingw/cmake/SDL3ConfigVersion.cmake", "cmake/"),
             ("BUGS.txt", ""),
             ("CREDITS.md", ""),
             ("README-SDL.txt", ""),
             ("WhatsNew.txt", ""),
             ("LICENSE.txt", ""),
             ("README.md", ""),
-        ]
+        )
         test_files = list(Path(r) / f for r, _, files in os.walk(self.root / "test") for f in files)
 
         # FIXME: split SDL3.dll debug information into debug library
@@ -385,7 +391,7 @@ class Releaser:
 
                 self.artifacts[f"mingw-devel-tar-{comp}"] = tar_paths[comp]
 
-    def build_vs(self, arch: str, platform: str, vs: VisualStudio, configuration: str="Release"):
+    def build_vs(self, arch: str, platform: str, vs: VisualStudio, configuration: str="Release") -> VcArchDevel:
         dll_path = self.root / f"VisualC/SDL/{platform}/{configuration}/{self.project}.dll"
         pdb_path = self.root / f"VisualC/SDL/{platform}/{configuration}/{self.project}.pdb"
         imp_path = self.root / f"VisualC/SDL/{platform}/{configuration}/{self.project}.lib"
@@ -430,7 +436,7 @@ class Releaser:
 
         return VcArchDevel(dll=dll_path, pdb=pdb_path, imp=imp_path, test=test_path)
 
-    def build_vs_cmake(self, arch: str, arch_cmake: str):
+    def build_vs_cmake(self, arch: str, arch_cmake: str) -> VcArchDevel:
         build_path = self.root / f"build-vs-{arch}"
         install_path = build_path / "prefix"
         dll_path = install_path / f"bin/{self.project}.dll"
@@ -500,7 +506,7 @@ class Releaser:
 
         return VcArchDevel(dll=dll_path, pdb=pdb_path, imp=imp_path, test=test_path)
 
-    def build_vs_devel(self, arch_vc: dict[str, VcArchDevel]):
+    def build_vs_devel(self, arch_vc: dict[str, VcArchDevel]) -> None:
         zip_path = self.dist_path / f"{self.project}-devel-{self.version}-VC.zip"
         archive_prefix = f"{self.project}-{self.version}"
 
@@ -554,7 +560,7 @@ class Releaser:
         logger.info("Selected API version %d", android_api)
         return android_api
 
-    def get_prefab_json_text(self):
+    def get_prefab_json_text(self) -> str:
         return textwrap.dedent(f"""\
             {{
                 "schema_version": 2,
@@ -564,7 +570,7 @@ class Releaser:
             }}
         """)
 
-    def get_prefab_module_json_text(self, library_name: str, extra_libs: list[str]):
+    def get_prefab_module_json_text(self, library_name: str, extra_libs: list[str]) -> str:
         export_libraries_str = ", ".join(f"\"-l{lib}\"" for lib in extra_libs)
         return textwrap.dedent(f"""\
             {{
@@ -573,7 +579,7 @@ class Releaser:
             }}
         """)
 
-    def get_prefab_abi_json_text(self, abi: str, cpp: bool, shared: bool):
+    def get_prefab_abi_json_text(self, abi: str, cpp: bool, shared: bool) -> str:
         return textwrap.dedent(f"""\
             {{
               "abi": "{abi}",
@@ -584,7 +590,7 @@ class Releaser:
             }}
         """)
 
-    def get_android_manifest_text(self):
+    def get_android_manifest_text(self) -> str:
         return textwrap.dedent(f"""\
             <manifest
                 xmlns:android="http://schemas.android.com/apk/res/android"
@@ -595,7 +601,7 @@ class Releaser:
             </manifest>
         """)
 
-    def create_android_archives(self, android_api: int, android_home: Path, android_ndk_home: Path, android_abis: list[str]):
+    def create_android_archives(self, android_api: int, android_home: Path, android_ndk_home: Path, android_abis: list[str]) -> None:
         cmake_toolchain_file = Path(android_ndk_home) / "build/cmake/android.toolchain.cmake"
         if not cmake_toolchain_file.exists():
             logger.error("CMake toolchain file does not exist (%s)", cmake_toolchain_file)
@@ -603,9 +609,19 @@ class Releaser:
         aar_path =  self.dist_path / f"{self.project}-{self.version}.aar"
         added_global_files = False
         with zipfile.ZipFile(aar_path, "w", compression=zipfile.ZIP_DEFLATED) as zip_object:
+            project_description = {
+                "name": self.project,
+                "version": self.version,
+                "git-hash": self.commit,
+            }
+            zip_object.writestr("description.json", json.dumps(project_description, indent=0))
             zip_object.writestr("AndroidManifest.xml", self.get_android_manifest_text())
             zip_object.write(self.root / "android-project/app/proguard-rules.pro", arcname="proguard.txt")
             zip_object.write(self.root / "LICENSE.txt", arcname="META-INF/LICENSE.txt")
+            zip_object.write(self.root / "cmake/sdlcpu.cmake", arcname="cmake/sdlcpu.cmake")
+            zip_object.write(self.root / "build-scripts/pkg-support/android/__main__.py", arcname="__main__.py")
+            zip_object.write(self.root / "build-scripts/pkg-support/android/cmake/SDL3Config.cmake", arcname="cmake/SDL3Config.cmake")
+            zip_object.write(self.root / "build-scripts/pkg-support/android/cmake/SDL3ConfigVersion.cmake", arcname="cmake/SDL3ConfigVersion.cmake")
             zip_object.writestr("prefab/prefab.json", self.get_prefab_json_text())
             self._zip_add_git_hash(zip_file=zip_object)
 
@@ -701,7 +717,7 @@ class Releaser:
         self.artifacts[f"android-aar"] = aar_path
 
     @classmethod
-    def extract_sdl_version(cls, root: Path, project: str):
+    def extract_sdl_version(cls, root: Path, project: str) -> str:
         with open(root / f"include/{project}/SDL_version.h", "r") as f:
             text = f.read()
         major = next(re.finditer(r"^#define SDL_MAJOR_VERSION\s+([0-9]+)$", text, flags=re.M)).group(1)
@@ -710,7 +726,7 @@ class Releaser:
         return f"{major}.{minor}.{micro}"
 
 
-def main(argv=None):
+def main(argv=None) -> int:
     parser = argparse.ArgumentParser(allow_abbrev=False, description="Create SDL release artifacts")
     parser.add_argument("--root", metavar="DIR", type=Path, default=Path(__file__).absolute().parents[1], help="Root of SDL")
     parser.add_argument("--out", "-o", metavar="DIR", dest="dist_path", type=Path, default="dist", help="Output directory")
@@ -739,7 +755,7 @@ def main(argv=None):
         args.dist_path = args.dist_path / "dry"
 
     if args.github:
-        section_printer = GitHubSectionPrinter()
+        section_printer: SectionPrinter = GitHubSectionPrinter()
     else:
         section_printer = SectionPrinter()
 

+ 23 - 19
build-scripts/create-android-project.py

@@ -10,7 +10,7 @@ import textwrap
 
 SDL_ROOT = Path(__file__).resolve().parents[1]
 
-def extract_sdl_version():
+def extract_sdl_version() -> str:
     """
     Extract SDL version from SDL3/SDL_version.h
     """
@@ -23,8 +23,8 @@ def extract_sdl_version():
     micro = int(next(re.finditer(r"#define\s+SDL_MICRO_VERSION\s+([0-9]+)", data)).group(1))
     return f"{major}.{minor}.{micro}"
 
-def replace_in_file(path, regex_what, replace_with):
-    with open(path, "r") as f:
+def replace_in_file(path: Path, regex_what: str, replace_with: str) -> None:
+    with path.open("r") as f:
         data = f.read()
 
     new_data, count = re.subn(regex_what, replace_with, data)
@@ -35,12 +35,12 @@ def replace_in_file(path, regex_what, replace_with):
         f.write(new_data)
 
 
-def android_mk_use_prefab(path):
+def android_mk_use_prefab(path: Path) -> None:
     """
     Replace relative SDL inclusion with dependency on prefab package
     """
 
-    with open(path) as f:
+    with path.open() as f:
         data = "".join(line for line in f.readlines() if "# SDL" not in line)
 
     data, _ = re.subn("[\n]{3,}", "\n\n", data)
@@ -55,18 +55,19 @@ def android_mk_use_prefab(path):
         $(call import-module,prefab/SDL3)
     """)
 
-    with open(path, "w") as f:
+    with path.open("w") as f:
         f.write(newdata)
 
-def cmake_mk_no_sdl(path):
+
+def cmake_mk_no_sdl(path: Path) -> None:
     """
     Don't add the source directories of SDL/SDL_image/SDL_mixer/...
     """
 
-    with open(path) as f:
+    with path.open() as f:
         lines = f.readlines()
 
-    newlines = []
+    newlines: list[str] = []
     for line in lines:
         if "add_subdirectory(SDL" in line:
             while newlines[-1].startswith("#"):
@@ -76,11 +77,12 @@ def cmake_mk_no_sdl(path):
 
     newdata, _ = re.subn("[\n]{3,}", "\n\n", "".join(newlines))
 
-    with open(path, "w") as f:
+    with path.open("w") as f:
         f.write(newdata)
 
-def gradle_add_prefab_and_aar(path, aar):
-    with open(path) as f:
+
+def gradle_add_prefab_and_aar(path: Path, aar: str) -> None:
+    with path.open() as f:
         data = f.read()
 
     data, count = re.subn("android {", textwrap.dedent("""
@@ -95,25 +97,26 @@ def gradle_add_prefab_and_aar(path, aar):
             implementation files('libs/{aar}')"""), data)
     assert count == 1
 
-    with open(path, "w") as f:
+    with path.open("w") as f:
         f.write(data)
 
-def gradle_add_package_name(path, package_name):
-    with open(path) as f:
+
+def gradle_add_package_name(path: Path, package_name: str) -> None:
+    with path.open() as f:
         data = f.read()
 
     data, count = re.subn("org.libsdl.app", package_name, data)
     assert count >= 1
 
-    with open(path, "w") as f:
+    with path.open("w") as f:
         f.write(data)
 
 
-def main():
+def main() -> int:
     description = "Create a simple Android gradle project from input sources."
     epilog = "You need to manually copy a prebuilt SDL3 Android archive into the project tree when using the aar variant."
-    parser = ArgumentParser(description=description, allow_abbrev=False)
-    parser.add_argument("package_name", metavar="PACKAGENAME", help="Android package name e.g. com.yourcompany.yourapp")
+    parser = ArgumentParser(description=description, epilog=epilog, allow_abbrev=False)
+    parser.add_argument("package_name", metavar="PACKAGENAME", help="Android package name (e.g. com.yourcompany.yourapp)")
     parser.add_argument("sources", metavar="SOURCE", nargs="*", help="Source code of your application. The files are copied to the output directory.")
     parser.add_argument("--variant", choices=["copy", "symlink", "aar"], default="copy", help="Choose variant of SDL project (copy: copy SDL sources, symlink: symlink SDL sources, aar: use Android aar archive)")
     parser.add_argument("--output", "-o", default=SDL_ROOT / "build", type=Path, help="Location where to store the Android project")
@@ -225,6 +228,7 @@ def main():
     print("To build and install to a device for testing, run the following:")
     print(f"cd {build_path}")
     print("./gradlew installDebug")
+    return 0
 
 if __name__ == "__main__":
     raise SystemExit(main())

+ 104 - 0
build-scripts/pkg-support/android/__main__.py

@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+
+"""
+Create a SDL SDK prefix from an Android archive
+This file is meant to be placed in a the root of an android .aar archive
+
+Example usage:
+```sh
+python SDL3-3.2.0.aar -o /usr/opt/android-sdks
+cmake -S my-project \
+    -DCMAKE_PREFIX_PATH=/usr/opt/android-sdks \
+    -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
+    -B build-arm64 -DANDROID_ABI=arm64-v8a \
+    -DCMAKE_BUILD_TYPE=Releaase
+cmake --build build-arm64
+```
+"""
+import argparse
+import io
+import json
+import os
+import pathlib
+import re
+import stat
+import zipfile
+
+
+AAR_PATH = pathlib.Path(__file__).resolve().parent
+ANDROID_ARCHS = { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" }
+
+
+def main():
+    parser = argparse.ArgumentParser(
+        description="Convert an Android .aar archive into a SDK",
+        allow_abbrev=False,
+    )
+    parser.add_argument("-o", dest="output", type=pathlib.Path, required=True, help="Folder where to store the SDK")
+    args = parser.parse_args()
+
+    print(f"Creating a SDK at {args.output}...")
+
+    prefix = args.output
+    incdir = prefix / "include"
+    libdir = prefix / "lib"
+
+    RE_LIB_MODULE_ARCH = re.compile(r"prefab/modules/(?P<module>[A-Za-z0-9_-]+)/libs/android\.(?P<arch>[a-zA-Z0-9_-]+)/(?P<filename>lib[A-Za-z0-9_]+\.(?:so|a))")
+    RE_INC_MODULE_ARCH = re.compile(r"prefab/modules/(?P<module>[A-Za-z0-9_-]+)/include/(?P<header>[a-zA-Z0-9_./-]+)")
+    RE_LICENSE = re.compile(r"(?:.*/)?(?P<filename>(?:license|copying)(?:\.md|\.txt)?)", flags=re.I)
+    RE_PROGUARD = re.compile(r"(?:.*/)?(?P<filename>proguard.*\.(?:pro|txt))", flags=re.I)
+    RE_CMAKE = re.compile(r"(?:.*/)?(?P<filename>.*\.cmake)", flags=re.I)
+
+    with zipfile.ZipFile(AAR_PATH) as zf:
+        project_description = json.loads(zf.read("description.json"))
+        project_name = project_description["name"]
+        project_version = project_description["version"]
+        licensedir = prefix / "share/licenses" / project_name
+        cmakedir = libdir / "cmake" / project_name
+        javadir = prefix / "share/java" / project_name
+        javadocdir = prefix / "share/javadoc" / project_name
+
+        def read_zipfile_and_write(path: pathlib.Path, zippath: str):
+            data = zf.read(zippath)
+            path.parent.mkdir(parents=True, exist_ok=True)
+            path.write_bytes(data)
+
+        for zip_info in zf.infolist():
+            zippath = zip_info.filename
+            if m := RE_LIB_MODULE_ARCH.match(zippath):
+                lib_path = libdir / m["arch"] / m["filename"]
+                read_zipfile_and_write(lib_path, zippath)
+                if m["filename"].endswith(".so"):
+                    os.chmod(lib_path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
+
+            elif m := RE_INC_MODULE_ARCH.match(zippath):
+                header_path = incdir / m["header"]
+                read_zipfile_and_write(header_path, zippath)
+            elif m:= RE_LICENSE.match(zippath):
+                license_path = licensedir / m["filename"]
+                read_zipfile_and_write(license_path, zippath)
+            elif m:= RE_PROGUARD.match(zippath):
+                proguard_path = javadir / m["filename"]
+                read_zipfile_and_write(proguard_path, zippath)
+            elif m:= RE_CMAKE.match(zippath):
+                cmake_path = cmakedir / m["filename"]
+                read_zipfile_and_write(cmake_path, zippath)
+            elif zippath == "classes.jar":
+                versioned_jar_path = javadir / f"{project_name}-{project_version}.jar"
+                unversioned_jar_path = javadir / f"{project_name}.jar"
+                read_zipfile_and_write(versioned_jar_path, zippath)
+                os.symlink(src=versioned_jar_path.name, dst=unversioned_jar_path)
+            elif zippath == "classes-sources.jar":
+                jarpath = javadir / f"{project_name}-{project_version}-sources.jar"
+                read_zipfile_and_write(jarpath, zippath)
+            elif zippath == "classes-doc.jar":
+                data = zf.read(zippath)
+                with zipfile.ZipFile(io.BytesIO(data)) as doc_zf:
+                    doc_zf.extractall(javadocdir)
+
+    print("... done")
+    return 0
+
+
+if __name__ == "__main__":
+    raise SystemExit(main())

+ 148 - 0
build-scripts/pkg-support/android/cmake/SDL3Config.cmake

@@ -0,0 +1,148 @@
+# SDL CMake configuration file:
+# This file is meant to be placed in lib/cmake/SDL3 subfolder of a reconstructed Android SDL3 SDK
+
+cmake_minimum_required(VERSION 3.0...3.5)
+
+include(FeatureSummary)
+set_package_properties(SDL3 PROPERTIES
+    URL "https://www.libsdl.org/"
+    DESCRIPTION "low level access to audio, keyboard, mouse, joystick, and graphics hardware"
+)
+
+# Copied from `configure_package_config_file`
+macro(set_and_check _var _file)
+    set(${_var} "${_file}")
+    if(NOT EXISTS "${_file}")
+        message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
+    endif()
+endmacro()
+
+# Copied from `configure_package_config_file`
+macro(check_required_components _NAME)
+    foreach(comp ${${_NAME}_FIND_COMPONENTS})
+        if(NOT ${_NAME}_${comp}_FOUND)
+            if(${_NAME}_FIND_REQUIRED_${comp})
+                set(${_NAME}_FOUND FALSE)
+            endif()
+        endif()
+    endforeach()
+endmacro()
+
+set(SDL3_FOUND TRUE)
+
+if(SDL_CPU_X86)
+    set(_sdl_arch_subdir "x86")
+elseif(SDL_CPU_X64)
+    set(_sdl_arch_subdir "x86_64")
+elseif(SDL_CPU_ARM32)
+    set(_sdl_arch_subdir "armeabi-v7a")
+elseif(SDL_CPU_ARM64)
+    set(_sdl_arch_subdir "arm64-v8a")
+else()
+    set(SDL3_FOUND FALSE)
+    return()
+endif()
+
+get_filename_component(_sdl3_prefix "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
+get_filename_component(_sdl3_prefix "${_sdl3_prefix}/.." ABSOLUTE)
+get_filename_component(_sdl3_prefix "${_sdl3_prefix}/.." ABSOLUTE)
+set_and_check(_sdl3_prefix      "${_sdl3_prefix}")
+set(_sdl3_include_dirs          "${_sdl3_prefix}/include")
+
+set(_sdl3_lib         "${_sdl3_prefix}/lib/${_sdl_arch_subdir}/libSDL3.so")
+set(_sdl3test_lib     "${_sdl3_prefix}/lib/${_sdl_arch_subdir}/libSDL3_test.a")
+set(_sdl3_jar         "${_sdl3_prefix}/share/java/SDL3/SDL3-${SDL3_VERSION}.jar")
+
+unset(_sdl_arch_subdir)
+unset(_sdl3_prefix)
+
+# All targets are created, even when some might not be requested though COMPONENTS.
+# This is done for compatibility with CMake generated SDL3-target.cmake files.
+
+if(NOT TARGET SDL3::Headers)
+    add_library(SDL3::Headers INTERFACE IMPORTED)
+    set_target_properties(SDL3::Headers
+        PROPERTIES
+        INTERFACE_INCLUDE_DIRECTORIES "${_sdl3_include_dirs}"
+    )
+endif()
+set(SDL3_Headers_FOUND TRUE)
+unset(_sdl3_include_dirs)
+
+if(EXISTS "${_sdl3_lib}")
+    if(NOT TARGET SDL3::SDL3-shared)
+        add_library(SDL3::SDL3-shared SHARED IMPORTED)
+        set_target_properties(SDL3::SDL3-shared
+            PROPERTIES
+                INTERFACE_LINK_LIBRARIES "SDL3::Headers"
+                IMPORTED_LOCATION "${_sdl3_lib}"
+                COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
+                INTERFACE_SDL3_SHARED "ON"
+                COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+                INTERFACE_SDL_VERSION "SDL3"
+    )
+    endif()
+    set(SDL3_SDL3-shared_FOUND TRUE)
+else()
+    set(SDL3_SDL3-shared_FOUND FALSE)
+endif()
+unset(_sdl3_lib)
+
+set(SDL3_SDL3-static_FOUND FALSE)
+
+if(EXISTS "${_sdl3test_lib}")
+    if(NOT TARGET SDL3::SDL3_test)
+        add_library(SDL3::SDL3_test STATIC IMPORTED)
+        set_target_properties(SDL3::SDL3_test
+            PROPERTIES
+                INTERFACE_LINK_LIBRARIES "SDL3::Headers"
+                IMPORTED_LOCATION "${_sdl3test_lib}"
+                COMPATIBLE_INTERFACE_STRING "SDL_VERSION"
+                INTERFACE_SDL_VERSION "SDL3"
+        )
+    endif()
+    set(SDL3_SDL3_test_FOUND TRUE)
+else()
+    set(SDL3_SDL3_test_FOUND FALSE)
+endif()
+unset(_sdl3test_lib)
+
+if(SDL3_SDL3-shared_FOUND)
+    set(SDL3_SDL3_FOUND TRUE)
+endif()
+
+function(_sdl_create_target_alias_compat NEW_TARGET TARGET)
+    if(CMAKE_VERSION VERSION_LESS "3.18")
+        # Aliasing local targets is not supported on CMake < 3.18, so make it global.
+        add_library(${NEW_TARGET} INTERFACE IMPORTED)
+        set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}")
+    else()
+        add_library(${NEW_TARGET} ALIAS ${TARGET})
+    endif()
+endfunction()
+
+# Make sure SDL3::SDL3 always exists
+if(NOT TARGET SDL3::SDL3)
+    if(TARGET SDL3::SDL3-shared)
+        _sdl_create_target_alias_compat(SDL3::SDL3 SDL3::SDL3-shared)
+    endif()
+endif()
+
+if(EXISTS "${_sdl3_jar}")
+    if(NOT TARGET SDL3::Jar)
+        add_library(SDL3::Jar INTERFACE IMPORTED)
+        set_property(TARGET SDL3::Jar PROPERTY JAR_FILE "${_sdl3_jar}")
+    endif()
+    set(SDL3_Jar_FOUND TRUE)
+else()
+    set(SDL3_Jar_FOUND FALSE)
+endif()
+unset(_sdl3_jar)
+
+check_required_components(SDL3)
+
+set(SDL3_LIBRARIES SDL3::SDL3)
+set(SDL3_STATIC_LIBRARIES SDL3::SDL3-static)
+set(SDL3_STATIC_PRIVATE_LIBS)
+
+set(SDL3TEST_LIBRARY SDL3::SDL3_test)

+ 57 - 0
build-scripts/pkg-support/android/cmake/SDL3ConfigVersion.cmake

@@ -0,0 +1,57 @@
+# based on the files generated by CMake's write_basic_package_version_file
+
+# SDL CMake version configuration file:
+# This file is meant to be placed in a lib/cmake/SDL3 subfolder of a reconstructed Android SDL3 SDK
+
+if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../../include/SDL3/SDL_version.h")
+    message(AUTHOR_WARNING "Could not find SDL3/SDL_version.h. This script is meant to be placed in the root of SDL3-devel-3.x.y-VC")
+    return()
+endif()
+
+file(READ "${CMAKE_CURRENT_LIST_DIR}/../../../include/SDL3/SDL_version.h" _sdl_version_h)
+string(REGEX MATCH "#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)" _sdl_major_re "${_sdl_version_h}")
+set(_sdl_major "${CMAKE_MATCH_1}")
+string(REGEX MATCH "#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)" _sdl_minor_re "${_sdl_version_h}")
+set(_sdl_minor "${CMAKE_MATCH_1}")
+string(REGEX MATCH "#define[ \t]+SDL_MICRO_VERSION[ \t]+([0-9]+)" _sdl_micro_re "${_sdl_version_h}")
+set(_sdl_micro "${CMAKE_MATCH_1}")
+if(_sdl_major_re AND _sdl_minor_re AND _sdl_micro_re)
+    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_micro}")
+else()
+    message(AUTHOR_WARNING "Could not extract version from SDL3/SDL_version.h.")
+    return()
+endif()
+
+if(PACKAGE_FIND_VERSION_RANGE)
+    # Package version must be in the requested version range
+    if ((PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MIN)
+            OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_GREATER PACKAGE_FIND_VERSION_MAX)
+            OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION_MAX)))
+        set(PACKAGE_VERSION_COMPATIBLE FALSE)
+    else()
+        set(PACKAGE_VERSION_COMPATIBLE TRUE)
+    endif()
+else()
+    if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
+        set(PACKAGE_VERSION_COMPATIBLE FALSE)
+    else()
+        set(PACKAGE_VERSION_COMPATIBLE TRUE)
+        if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
+            set(PACKAGE_VERSION_EXACT TRUE)
+        endif()
+    endif()
+endif()
+
+# if the using project doesn't have CMAKE_SIZEOF_VOID_P set, fail.
+if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "")
+    set(PACKAGE_VERSION_UNSUITABLE TRUE)
+endif()
+
+include("${CMAKE_CURRENT_LIST_DIR}/sdlcpu.cmake")
+SDL_DetectTargetCPUArchitectures(_detected_archs)
+
+# check that the installed version has a compatible architecture as the one which is currently searching:
+if(NOT(SDL_CPU_X86 OR SDL_CPU_X64 OR SDL_CPU_ARM32 OR SDL_CPU_ARM64))
+    set(PACKAGE_VERSION "${PACKAGE_VERSION} (X86,X64,ARM32,ARM64)")
+    set(PACKAGE_VERSION_UNSUITABLE TRUE)
+endif()

+ 0 - 0
mingw/pkg-support/INSTALL.txt → build-scripts/pkg-support/mingw/INSTALL.txt


+ 0 - 0
mingw/pkg-support/Makefile → build-scripts/pkg-support/mingw/Makefile


+ 0 - 0
mingw/pkg-support/cmake/sdl3-config.cmake → build-scripts/pkg-support/mingw/cmake/SDL3Config.cmake


+ 0 - 0
mingw/pkg-support/cmake/sdl3-config-version.cmake → build-scripts/pkg-support/mingw/cmake/SDL3ConfigVersion.cmake


+ 1 - 1
test/CMakeLists.txt

@@ -334,7 +334,7 @@ function(files2headers OUTPUT)
             # Don't add the 'output' header to the output, to avoid marking them as GENERATED
             # (generated files are removed when running the CLEAN target)
             add_custom_command(OUTPUT "${intermediate}"
-                COMMAND Python3::Interpreter "${xxd}" -i "${CMAKE_CURRENT_SOURCE_DIR}/${input}" "-o" "${intermediate}"
+                COMMAND "${Python3_EXECUTABLE}" "${xxd}" -i "${CMAKE_CURRENT_SOURCE_DIR}/${input}" "-o" "${intermediate}"
                 COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${intermediate}" "${output}"
                 DEPENDS "${xxd}" "${bmp}"
             )