SCons: Better validation for platform-specific opt-in drivers

This replaces cryptic compilation errors with a clear error message
and early build termination.
This commit is contained in:
Rémi Verschelde 2024-08-21 08:58:18 +02:00
parent 5ca419e32c
commit 6e9bcc0f18
No known key found for this signature in database
GPG Key ID: C3336907360768E1
6 changed files with 20 additions and 8 deletions

View File

@ -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))

View File

@ -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

View File

@ -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")

View File

@ -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,
}

View File

@ -57,7 +57,7 @@ def get_flags():
"arch": detect_arch(),
"use_volk": False,
"metal": True,
"supported": ["mono"],
"supported": ["metal", "mono"],
}

View File

@ -247,7 +247,7 @@ def get_flags():
return {
"arch": arch,
"supported": ["mono"],
"supported": ["d3d12", "mono", "xaudio2"],
}