From 6e9bcc0f18becbed199ad48d3dec01621dc39237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 21 Aug 2024 08:58:18 +0200 Subject: [PATCH] SCons: Better validation for platform-specific opt-in drivers This replaces cryptic compilation errors with a clear error message and early build termination. --- SConstruct | 6 +++--- drivers/SCsub | 10 ++++++++++ modules/mono/config.py | 6 ++++-- platform/ios/detect.py | 2 +- platform/macos/detect.py | 2 +- platform/windows/detect.py | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/SConstruct b/SConstruct index ca160c1762b..94574aacb22 100644 --- a/SConstruct +++ b/SConstruct @@ -218,11 +218,11 @@ opts.Add(BoolVariable("deprecated", "Enable compatibility code for deprecated an opts.Add(EnumVariable("precision", "Set the floating-point precision level", "single", ("single", "double"))) opts.Add(BoolVariable("minizip", "Enable ZIP archive support using minizip", True)) opts.Add(BoolVariable("brotli", "Enable Brotli for decompresson and WOFF2 fonts support", True)) -opts.Add(BoolVariable("xaudio2", "Enable the XAudio2 audio driver", False)) +opts.Add(BoolVariable("xaudio2", "Enable the XAudio2 audio driver on supported platforms", False)) opts.Add(BoolVariable("vulkan", "Enable the vulkan rendering driver", True)) opts.Add(BoolVariable("opengl3", "Enable the OpenGL/GLES3 rendering driver", True)) -opts.Add(BoolVariable("d3d12", "Enable the Direct3D 12 rendering driver", False)) -opts.Add(BoolVariable("metal", "Enable the Metal rendering driver (Apple arm64 only)", False)) +opts.Add(BoolVariable("d3d12", "Enable the Direct3D 12 rendering driver on supported platforms", False)) +opts.Add(BoolVariable("metal", "Enable the Metal rendering driver on supported platforms (Apple arm64 only)", False)) opts.Add(BoolVariable("openxr", "Enable the OpenXR driver", True)) opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loader dynamically", True)) opts.Add(BoolVariable("disable_exceptions", "Force disabling exception handling code", True)) diff --git a/drivers/SCsub b/drivers/SCsub index 521d607740a..44d29fb7c17 100644 --- a/drivers/SCsub +++ b/drivers/SCsub @@ -3,6 +3,7 @@ Import("env") env.drivers_sources = [] +supported = env.get("supported", []) # OS drivers SConscript("unix/SCsub") @@ -17,6 +18,9 @@ if env["platform"] == "windows": if not env.msvc: SConscript("backtrace/SCsub") if env["xaudio2"]: + if "xaudio2" not in supported: + print("Target platform '{}' does not support the XAudio2 audio driver. Aborting.".format(env["platform"])) + Exit(255) SConscript("xaudio2/SCsub") # Midi drivers @@ -28,12 +32,18 @@ SConscript("winmidi/SCsub") if env["vulkan"]: SConscript("vulkan/SCsub") if env["d3d12"]: + if "d3d12" not in supported: + print("Target platform '{}' does not support the D3D12 rendering driver. Aborting.".format(env["platform"])) + Exit(255) SConscript("d3d12/SCsub") if env["opengl3"]: SConscript("gl_context/SCsub") SConscript("gles3/SCsub") SConscript("egl/SCsub") if env["metal"]: + if "metal" not in supported: + print("Target platform '{}' does not support the Metal rendering driver. Aborting.".format(env["platform"])) + Exit(255) SConscript("metal/SCsub") # Core dependencies diff --git a/modules/mono/config.py b/modules/mono/config.py index 5ebdb83b366..0573fc662a9 100644 --- a/modules/mono/config.py +++ b/modules/mono/config.py @@ -11,9 +11,11 @@ def can_build(env, platform): def configure(env): # Check if the platform has marked mono as supported. supported = env.get("supported", []) - if "mono" not in supported: - raise RuntimeError("This module does not currently support building for this platform") + import sys + + print("The 'mono' module does not currently support building for this platform. Aborting.") + sys.exit(255) env.add_module_version_string("mono") diff --git a/platform/ios/detect.py b/platform/ios/detect.py index ecd1f3d32d0..989a7f21f39 100644 --- a/platform/ios/detect.py +++ b/platform/ios/detect.py @@ -52,7 +52,7 @@ def get_flags(): "target": "template_debug", "use_volk": False, "metal": True, - "supported": ["mono"], + "supported": ["metal", "mono"], "builtin_pcre2_with_jit": False, } diff --git a/platform/macos/detect.py b/platform/macos/detect.py index bfd18bea99f..e35423d41f0 100644 --- a/platform/macos/detect.py +++ b/platform/macos/detect.py @@ -57,7 +57,7 @@ def get_flags(): "arch": detect_arch(), "use_volk": False, "metal": True, - "supported": ["mono"], + "supported": ["metal", "mono"], } diff --git a/platform/windows/detect.py b/platform/windows/detect.py index b4830c5908e..11dd4548f1f 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -247,7 +247,7 @@ def get_flags(): return { "arch": arch, - "supported": ["mono"], + "supported": ["d3d12", "mono", "xaudio2"], }