setup-sdl: Add support for sdl12-compat and sdl2-compat

From 6574e20ac65ce362cd12f9c26b3a5e4d3cd31dee Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Wed, 9 Apr 2025 21:52:54 +0200
Subject: [PATCH] Add support for sdl12-compat and sdl2-compat

---
 action.yml      |  6 ++++++
 packed/index.js | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 src/main.ts     | 16 +++++++++++++++-
 src/version.ts  | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 97 insertions(+), 3 deletions(-)

diff --git a/action.yml b/action.yml
index 9836ff0..2219715 100644
--- a/action.yml
+++ b/action.yml
@@ -20,6 +20,12 @@ inputs:
   version-sdl-ttf:
     description: "Version of SDL_ttf (2.x.y, 2-any, 2-latest, 2-head, 3-head), git hash, or <empty>"
     required: false
+  version-sdl2-compat:
+    description: "Version of sdl2-compat (2.x.y, 2-any, 2-latest, 2-head), git hash, or <empty>"
+    required: false
+  version-sdl12-compat:
+    description: "Version of sdl12-compat (1.x.y, 1-any, 1-latest, 1-head), git hash, or <empty>"
+    required: false
   pre-release:
     description: "Allow pre-releases"
     default: "true"
diff --git a/packed/index.js b/packed/index.js
index a7d06f5..3436a65 100644
--- a/packed/index.js
+++ b/packed/index.js
@@ -572,6 +572,15 @@ function run() {
                                 core.debug("proj=".concat(proj));
                                 core.debug("build_order=".concat(build_order));
                                 core.debug("proj in build_order=".concat(proj in build_order));
+                                if (proj == version_2.Project.SDL12_compat &&
+                                    (build_order.indexOf(version_2.Project.SDL) >= 0 ||
+                                        build_order.indexOf(version_2.Project.SDL2_compat) >= 0)) {
+                                    return 1;
+                                }
+                                if (proj == version_2.Project.SDL2_compat &&
+                                    build_order.indexOf(version_2.Project.SDL) >= 0) {
+                                    return 1;
+                                }
                                 return build_order.findIndex(function (e) { return e == proj; }) >= 0;
                             })) {
                                 build_order.push(project_left);
@@ -590,7 +599,7 @@ function run() {
                     package_dirs = {};
                     project_versions = {};
                     _loop_1 = function (project) {
-                        var project_description, req_step_version, git_branch_hash, git_hash, project_cmake_arguments, dependency_hashes, project_hash, package_dir, cache_key, cache_paths, was_in_cache, project_packages, source_dir, build_dir, cmake_configure_args, CMAKE_GENERATOR, version_extractor, project_version, cmake_export_name;
+                        var project_description, req_step_version, git_branch_hash, git_hash, project_cmake_arguments, dependency_hashes, project_hash, package_dir, cache_key, cache_paths, was_in_cache, project_packages, source_dir, build_dir, cmake_configure_args, CMAKE_GENERATOR, version_extractor, project_version, infix, cmake_export_name;
                         return __generator(this, function (_c) {
                             switch (_c.label) {
                                 case 0:
@@ -756,7 +765,8 @@ function run() {
                                     project_version = version_extractor.extract_from_install_prefix(package_dir);
                                     project_versions[project] = project_version;
                                     core.info("".concat(project, " version is ").concat(project_version.toString()));
-                                    cmake_export_name = "".concat(project_description.cmake_var_out_prefix).concat(project_version.major).concat(project_description.cmake_var_out_suffix);
+                                    infix = project_version.major == 1 ? "" : "".concat(project_version.major);
+                                    cmake_export_name = "".concat(project_description.cmake_var_out_prefix).concat(infix).concat(project_description.cmake_var_out_suffix);
                                     core.exportVariable(cmake_export_name, package_dir);
                                     return [2 /*return*/];
                             }
@@ -1525,6 +1535,8 @@ exports.Version = Version;
 var Project;
 (function (Project) {
     Project["SDL"] = "SDL";
+    Project["SDL2_compat"] = "SDL2_compat";
+    Project["SDL12_compat"] = "SDL12_compat";
     Project["SDL_image"] = "SDL_image";
     Project["SDL_mixer"] = "SDL_mixer";
     Project["SDL_net"] = "SDL_net";
@@ -1760,6 +1772,36 @@ exports.project_descriptions = (_a = {},
             },
             _c),
     },
+    _a[Project.SDL2_compat] = {
+        option_name: "version-sdl2-compat",
+        cmake_var_out_prefix: "SDL2",
+        cmake_var_out_suffix: "_ROOT",
+        deps: [Project.SDL],
+        major_define: "SDL_MAJOR_VERSION",
+        minor_define: "SDL_MINOR_VERSION",
+        patch_define: "SDL_PATCHLEVEL",
+        header_paths: ["include/SDL2"],
+        header_filenames: ["SDL_version.h"],
+        git_url: "https://github.com/libsdl-org/sdl2-compat.git",
+        repo_owner: "libsdl-org",
+        repo_name: "sdl2-compat",
+        version_branch_map: { 2: "main" },
+    },
+    _a[Project.SDL12_compat] = {
+        option_name: "version-sdl12-compat",
+        cmake_var_out_prefix: "SDL",
+        cmake_var_out_suffix: "_ROOT",
+        deps: [Project.SDL2_compat],
+        major_define: "SDL_MAJOR_VERSION",
+        minor_define: "SDL_MINOR_VERSION",
+        patch_define: "SDL_PATCHLEVEL",
+        header_paths: ["include/SDL"],
+        header_filenames: ["SDL_version.h"],
+        git_url: "https://github.com/libsdl-org/sdl12-compat.git",
+        repo_owner: "libsdl-org",
+        repo_name: "sdl12-compat",
+        version_branch_map: { 1: "main" },
+    },
     _a);
 var ReleaseType;
 (function (ReleaseType) {
diff --git a/src/main.ts b/src/main.ts
index a01f874..48e3578 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -535,6 +535,19 @@ async function run() {
           core.debug(`proj=${proj}`);
           core.debug(`build_order=${build_order}`);
           core.debug(`proj in build_order=${proj in build_order}`);
+          if (
+            proj == Project.SDL12_compat &&
+            (build_order.indexOf(Project.SDL) >= 0 ||
+              build_order.indexOf(Project.SDL2_compat) >= 0)
+          ) {
+            return 1;
+          }
+          if (
+            proj == Project.SDL2_compat &&
+            build_order.indexOf(Project.SDL) >= 0
+          ) {
+            return 1;
+          }
           return build_order.findIndex((e) => e == proj) >= 0;
         })
       ) {
@@ -742,7 +755,8 @@ async function run() {
     core.info(`${project} version is ${project_version.toString()}`);
 
     // Set environment variable (e.g. SDL3_ROOT)
-    const cmake_export_name = `${project_description.cmake_var_out_prefix}${project_version.major}${project_description.cmake_var_out_suffix}`;
+    const infix = project_version.major == 1 ? "" : `${project_version.major}`;
+    const cmake_export_name = `${project_description.cmake_var_out_prefix}${infix}${project_description.cmake_var_out_suffix}`;
     core.exportVariable(cmake_export_name, package_dir);
   }
 
diff --git a/src/version.ts b/src/version.ts
index 02699e3..e3ca95f 100644
--- a/src/version.ts
+++ b/src/version.ts
@@ -110,6 +110,8 @@ export class Version {
 
 export enum Project {
   SDL = "SDL",
+  SDL2_compat = "SDL2_compat",
+  SDL12_compat = "SDL12_compat",
   SDL_image = "SDL_image",
   SDL_mixer = "SDL_mixer",
   SDL_net = "SDL_net",
@@ -379,6 +381,36 @@ export const project_descriptions: { [key in Project]: ProjectDescription } = {
       },
     },
   },
+  [Project.SDL2_compat]: {
+    option_name: "version-sdl2-compat",
+    cmake_var_out_prefix: "SDL2",
+    cmake_var_out_suffix: "_ROOT",
+    deps: [Project.SDL],
+    major_define: "SDL_MAJOR_VERSION",
+    minor_define: "SDL_MINOR_VERSION",
+    patch_define: "SDL_PATCHLEVEL",
+    header_paths: ["include/SDL2"],
+    header_filenames: ["SDL_version.h"],
+    git_url: "https://github.com/libsdl-org/sdl2-compat.git",
+    repo_owner: "libsdl-org",
+    repo_name: "sdl2-compat",
+    version_branch_map: { 2: "main" },
+  },
+  [Project.SDL12_compat]: {
+    option_name: "version-sdl12-compat",
+    cmake_var_out_prefix: "SDL",
+    cmake_var_out_suffix: "_ROOT",
+    deps: [Project.SDL2_compat],
+    major_define: "SDL_MAJOR_VERSION",
+    minor_define: "SDL_MINOR_VERSION",
+    patch_define: "SDL_PATCHLEVEL",
+    header_paths: ["include/SDL"],
+    header_filenames: ["SDL_version.h"],
+    git_url: "https://github.com/libsdl-org/sdl12-compat.git",
+    repo_owner: "libsdl-org",
+    repo_name: "sdl12-compat",
+    version_branch_map: { 1: "main" },
+  },
 };
 
 export enum ReleaseType {