Skip to content

Commit

Permalink
SCons: Better validation for platform-specific opt-in drivers
Browse files Browse the repository at this point in the history
This replaces cryptic compilation errors with a clear error message
and early build termination.
  • Loading branch information
akien-mga committed Aug 21, 2024
1 parent 5ca419e commit 6e9bcc0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions drivers/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Import("env")

env.drivers_sources = []
supported = env.get("supported", [])

# OS drivers
SConscript("unix/SCsub")
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions modules/mono/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion platform/ios/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion platform/macos/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_flags():
"arch": detect_arch(),
"use_volk": False,
"metal": True,
"supported": ["mono"],
"supported": ["metal", "mono"],
}


Expand Down
2 changes: 1 addition & 1 deletion platform/windows/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def get_flags():

return {
"arch": arch,
"supported": ["mono"],
"supported": ["d3d12", "mono", "xaudio2"],
}


Expand Down

0 comments on commit 6e9bcc0

Please sign in to comment.