Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ _helper_module("version", "version.py")
_helper_module("core.core_builders", "core/core_builders.py")
_helper_module("main.main_builders", "main/main_builders.py")
_helper_module("misc.utility.color", "misc/utility/color.py")
_helper_module("misc.utility.compatibility", "misc/utility/compatibility.py")

# Local
import gles3_builders
Expand Down
5 changes: 4 additions & 1 deletion drivers/apple_embedded/SCsub
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from misc.utility.compatibility import try_use_cxx20_module

Import("env")

env_apple_embedded = env.Clone()

# Enable module support
env_apple_embedded.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
# env_apple_embedded.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
try_use_cxx20_module(env_apple_embedded)

# Use bundled Vulkan headers
vulkan_dir = "#thirdparty/vulkan"
Expand Down
5 changes: 4 additions & 1 deletion drivers/metal/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from misc.utility.compatibility import try_use_cxx20_module

Import("env")

env_metal = env.Clone()
Expand Down Expand Up @@ -40,7 +42,8 @@ if "-std=gnu++17" in env_metal["CXXFLAGS"]:
env_metal.Append(CXXFLAGS=["-std=c++20"])

# Enable module support
env_metal.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
# env_metal.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
try_use_cxx20_module(env_metal)

# Driver source files

Expand Down
53 changes: 53 additions & 0 deletions misc/utility/compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
import os
import subprocess

import methods

is_able_to_use_module_cache = None


def try_use_cxx20_module(env):
"""
Use C++20's `module` if current compiler supports that.
Referencing https://en.cppreference.com/w/cpp/compiler_support/20.
"""
global is_able_to_use_module_cache

if is_able_to_use_module_cache is not None:
return is_able_to_use_module_cache
else:
is_able_to_use_module_cache = True

# According to the reference, currently (06/03/2025, mm/dd/yyyy),
# only msvc has full support of module.
if env.msvc and is_msvc_support_module(env):
env.Append(CCFLAGS=["/experimental:module"])
# Apple clang also supports module.
elif methods.using_clang(env) and is_clang_support_module():
env.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
else:
is_able_to_use_module_cache = False


def is_msvc_support_module(env) -> bool:
"""
MSVC supports C++ modules after 19.2.8.
"""
# Only "major", "minor", and "patch" has int type.
version = methods.get_compiler_version(env)
major: int = version["major"]
minor: int = version["minor"]
patch: int = version["patch"]

return major > 19 or (version["major"] == 19 and minor >= 2) or (major == 19 and minor == 2 and patch >= 8)


def is_clang_support_module() -> bool:
"""
Check if the clang is Apple clang.
"""
env = os.environ.copy()
env["LC_ALL"] = "C"
version_text: str = subprocess.check_output(["clang", "--version"], env=env, encoding="utf-8")
return "Apple clang version" in version_text
4 changes: 3 additions & 1 deletion platform/ios/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from misc.utility.scons_hints import *

from platform_ios_builders import generate_bundle

from misc.utility.compatibility import try_use_cxx20_module
from platform_methods import combine_libs_apple_embedded

Import("env")
Expand All @@ -20,7 +21,8 @@ env_ios = env.Clone()
ios_lib = env_ios.add_library("ios", ios_lib)

# (iOS) Enable module support
env_ios.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
# env_ios.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
try_use_cxx20_module(env_ios)

combine_command = env_ios.CommandNoCache(
"#bin/libgodot" + env_ios["LIBSUFFIX"], [ios_lib] + env_ios["LIBS"], env.Run(combine_libs_apple_embedded)
Expand Down
4 changes: 3 additions & 1 deletion platform/visionos/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from misc.utility.scons_hints import *

from platform_visionos_builders import generate_bundle

from misc.utility.compatibility import try_use_cxx20_module
from platform_methods import combine_libs_apple_embedded

Import("env")
Expand All @@ -19,7 +20,8 @@ env_visionos = env.Clone()
visionos_lib = env_visionos.add_library("visionos", visionos_lib)

# Enable module support
env_visionos.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
# env_visionos.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
try_use_cxx20_module(env_visionos)

combine_command = env_visionos.Command(
"#bin/libgodot" + env_visionos["LIBSUFFIX"], [visionos_lib] + env_visionos["LIBS"], combine_libs_apple_embedded
Expand Down