Add support for compiling with VS clang-cl toolset

This commit is contained in:
Alula 2024-05-24 15:07:22 +02:00 committed by Thaddeus Crews
parent f648de1a83
commit 346cbc7f1f
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
13 changed files with 92 additions and 36 deletions

View File

@ -30,6 +30,14 @@ jobs:
# Skip debug symbols, they're way too big with MSVC. # Skip debug symbols, they're way too big with MSVC.
sconsflags: debug_symbols=no vsproj=yes vsproj_gen_only=no windows_subsystem=console sconsflags: debug_symbols=no vsproj=yes vsproj_gen_only=no windows_subsystem=console
bin: "./bin/godot.windows.editor.x86_64.exe" bin: "./bin/godot.windows.editor.x86_64.exe"
artifact: true
- name: Editor w/ clang-cl (target=editor, tests=yes, use_llvm=yes)
cache-name: windows-editor-clang
target: editor
tests: true
sconsflags: debug_symbols=no windows_subsystem=console use_llvm=yes
bin: ./bin/godot.windows.editor.x86_64.llvm.exe
- name: Template (target=template_release) - name: Template (target=template_release)
cache-name: windows-template cache-name: windows-template
@ -37,6 +45,7 @@ jobs:
tests: true tests: true
sconsflags: debug_symbols=no tests=yes sconsflags: debug_symbols=no tests=yes
bin: "./bin/godot.windows.template_release.x86_64.console.exe" bin: "./bin/godot.windows.template_release.x86_64.console.exe"
artifact: true
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -84,10 +93,12 @@ jobs:
continue-on-error: true continue-on-error: true
- name: Prepare artifact - name: Prepare artifact
if: ${{ matrix.artifact }}
run: | run: |
Remove-Item bin/* -Include *.exp,*.lib,*.pdb -Force Remove-Item bin/* -Include *.exp,*.lib,*.pdb -Force
- name: Upload artifact - name: Upload artifact
if: ${{ matrix.artifact }}
uses: ./.github/actions/upload-artifact uses: ./.github/actions/upload-artifact
with: with:
name: ${{ matrix.cache-name }} name: ${{ matrix.cache-name }}

View File

@ -803,7 +803,7 @@ elif env.msvc:
env.Append(CXXFLAGS=["/EHsc"]) env.Append(CXXFLAGS=["/EHsc"])
# Configure compiler warnings # Configure compiler warnings
if env.msvc: # MSVC if env.msvc and not methods.using_clang(env): # MSVC
if env["warnings"] == "no": if env["warnings"] == "no":
env.Append(CCFLAGS=["/w"]) env.Append(CCFLAGS=["/w"])
else: else:
@ -853,8 +853,11 @@ else: # GCC, Clang
# for putting them in `Set` or `Map`. We don't mind about unreliable ordering. # for putting them in `Set` or `Map`. We don't mind about unreliable ordering.
common_warnings += ["-Wno-ordered-compare-function-pointers"] common_warnings += ["-Wno-ordered-compare-function-pointers"]
# clang-cl will interpret `-Wall` as `-Weverything`, workaround with compatibility cast
W_ALL = "-Wall" if not env.msvc else "-W3"
if env["warnings"] == "extra": if env["warnings"] == "extra":
env.Append(CCFLAGS=["-Wall", "-Wextra", "-Wwrite-strings", "-Wno-unused-parameter"] + common_warnings) env.Append(CCFLAGS=[W_ALL, "-Wextra", "-Wwrite-strings", "-Wno-unused-parameter"] + common_warnings)
env.Append(CXXFLAGS=["-Wctor-dtor-privacy", "-Wnon-virtual-dtor"]) env.Append(CXXFLAGS=["-Wctor-dtor-privacy", "-Wnon-virtual-dtor"])
if methods.using_gcc(env): if methods.using_gcc(env):
env.Append( env.Append(
@ -876,9 +879,9 @@ else: # GCC, Clang
elif methods.using_clang(env) or methods.using_emcc(env): elif methods.using_clang(env) or methods.using_emcc(env):
env.Append(CCFLAGS=["-Wimplicit-fallthrough"]) env.Append(CCFLAGS=["-Wimplicit-fallthrough"])
elif env["warnings"] == "all": elif env["warnings"] == "all":
env.Append(CCFLAGS=["-Wall"] + common_warnings) env.Append(CCFLAGS=[W_ALL] + common_warnings)
elif env["warnings"] == "moderate": elif env["warnings"] == "moderate":
env.Append(CCFLAGS=["-Wall", "-Wno-unused"] + common_warnings) env.Append(CCFLAGS=[W_ALL, "-Wno-unused"] + common_warnings)
else: # 'no' else: # 'no'
env.Append(CCFLAGS=["-w"]) env.Append(CCFLAGS=["-w"])
@ -1032,7 +1035,9 @@ if env["vsproj"]:
if env["compiledb"]: if env["compiledb"]:
if env.scons_version < (4, 0, 0): if env.scons_version < (4, 0, 0):
# Generating the compilation DB (`compile_commands.json`) requires SCons 4.0.0 or later. # Generating the compilation DB (`compile_commands.json`) requires SCons 4.0.0 or later.
print_error("The `compiledb=yes` option requires SCons 4.0 or later, but your version is %s." % scons_raw_version) print_error(
"The `compiledb=yes` option requires SCons 4.0 or later, but your version is %s." % scons_raw_version
)
Exit(255) Exit(255)
env.Tool("compilation_db") env.Tool("compilation_db")

View File

@ -36,7 +36,7 @@
class PackedDataContainer : public Resource { class PackedDataContainer : public Resource {
GDCLASS(PackedDataContainer, Resource); GDCLASS(PackedDataContainer, Resource);
enum { enum : uint32_t {
TYPE_DICT = 0xFFFFFFFF, TYPE_DICT = 0xFFFFFFFF,
TYPE_ARRAY = 0xFFFFFFFE, TYPE_ARRAY = 0xFFFFFFFE,
}; };

View File

@ -203,7 +203,7 @@ struct LightmapInstance {
class LightStorage : public RendererLightStorage { class LightStorage : public RendererLightStorage {
public: public:
enum ShadowAtlastQuadrant { enum ShadowAtlastQuadrant : uint32_t {
QUADRANT_SHIFT = 27, QUADRANT_SHIFT = 27,
OMNI_LIGHT_FLAG = 1 << 26, OMNI_LIGHT_FLAG = 1 << 26,
SHADOW_INDEX_MASK = OMNI_LIGHT_FLAG - 1, SHADOW_INDEX_MASK = OMNI_LIGHT_FLAG - 1,

View File

@ -163,7 +163,7 @@ def add_source_files(self, sources, files, allow_gen=False):
def disable_warnings(self): def disable_warnings(self):
# 'self' is the environment # 'self' is the environment
if self.msvc: if self.msvc and not using_clang(self):
# We have to remove existing warning level defines before appending /w, # We have to remove existing warning level defines before appending /w,
# otherwise we get: "warning D9025 : overriding '/W3' with '/w'" # otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
self["CCFLAGS"] = [x for x in self["CCFLAGS"] if not (x.startswith("/W") or x.startswith("/w"))] self["CCFLAGS"] = [x for x in self["CCFLAGS"] if not (x.startswith("/W") or x.startswith("/w"))]
@ -817,21 +817,20 @@ def get_compiler_version(env):
"apple_patch3": -1, "apple_patch3": -1,
} }
if not env.msvc: if env.msvc and not using_clang(env):
# Not using -dumpversion as some GCC distros only return major, and
# Clang used to return hardcoded 4.2.1: # https://reviews.llvm.org/D56803
try:
version = (
subprocess.check_output([env.subst(env["CXX"]), "--version"], shell=(os.name == "nt"))
.strip()
.decode("utf-8")
)
except (subprocess.CalledProcessError, OSError):
print_warning("Couldn't parse CXX environment variable to infer compiler version.")
return ret
else:
# TODO: Implement for MSVC # TODO: Implement for MSVC
return ret return ret
# Not using -dumpversion as some GCC distros only return major, and
# Clang used to return hardcoded 4.2.1: # https://reviews.llvm.org/D56803
try:
version = subprocess.check_output(
[env.subst(env["CXX"]), "--version"], shell=(os.name == "nt"), encoding="utf-8"
).strip()
except (subprocess.CalledProcessError, OSError):
print_warning("Couldn't parse CXX environment variable to infer compiler version.")
return ret
match = re.search( match = re.search(
r"(?:(?<=version )|(?<=\) )|(?<=^))" r"(?:(?<=version )|(?<=\) )|(?<=^))"
r"(?P<major>\d+)" r"(?P<major>\d+)"

View File

@ -216,6 +216,7 @@ bool get_default_installation_dir(String &r_dotnet_root) {
#endif #endif
} }
#ifndef WINDOWS_ENABLED
bool get_install_location_from_file(const String &p_file_path, String &r_dotnet_root) { bool get_install_location_from_file(const String &p_file_path, String &r_dotnet_root) {
Error err = OK; Error err = OK;
Ref<FileAccess> f = FileAccess::open(p_file_path, FileAccess::READ, &err); Ref<FileAccess> f = FileAccess::open(p_file_path, FileAccess::READ, &err);
@ -233,6 +234,7 @@ bool get_install_location_from_file(const String &p_file_path, String &r_dotnet_
r_dotnet_root = line; r_dotnet_root = line;
return true; return true;
} }
#endif
bool get_dotnet_self_registered_dir(String &r_dotnet_root) { bool get_dotnet_self_registered_dir(String &r_dotnet_root) {
#if defined(WINDOWS_ENABLED) #if defined(WINDOWS_ENABLED)

View File

@ -118,7 +118,7 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
HANDLE process = GetCurrentProcess(); HANDLE process = GetCurrentProcess();
HANDLE hThread = GetCurrentThread(); HANDLE hThread = GetCurrentThread();
DWORD offset_from_symbol = 0; DWORD offset_from_symbol = 0;
IMAGEHLP_LINE64 line = { 0 }; IMAGEHLP_LINE64 line = {};
std::vector<module_data> modules; std::vector<module_data> modules;
DWORD cbNeeded; DWORD cbNeeded;
std::vector<HMODULE> module_handles(1); std::vector<HMODULE> module_handles(1);

View File

@ -381,6 +381,15 @@ def configure_msvc(env: "SConsEnvironment", vcvars_msvc_config):
## Compile/link flags ## Compile/link flags
if env["use_llvm"]:
env["CC"] = "clang-cl"
env["CXX"] = "clang-cl"
env["LINK"] = "lld-link"
env["AR"] = "llvm-lib"
env.AppendUnique(CPPDEFINES=["R128_STDC_ONLY"])
env.extra_suffix = ".llvm" + env.extra_suffix
env["MAXLINELENGTH"] = 8192 # Windows Vista and beyond, so always applicable. env["MAXLINELENGTH"] = 8192 # Windows Vista and beyond, so always applicable.
if env["silence_msvc"] and not env.GetOption("clean"): if env["silence_msvc"] and not env.GetOption("clean"):
@ -465,7 +474,6 @@ def configure_msvc(env: "SConsEnvironment", vcvars_msvc_config):
env.AppendUnique(CCFLAGS=["/Gd", "/GR", "/nologo"]) env.AppendUnique(CCFLAGS=["/Gd", "/GR", "/nologo"])
env.AppendUnique(CCFLAGS=["/utf-8"]) # Force to use Unicode encoding. env.AppendUnique(CCFLAGS=["/utf-8"]) # Force to use Unicode encoding.
env.AppendUnique(CXXFLAGS=["/TP"]) # assume all sources are C++
# Once it was thought that only debug builds would be too large, # Once it was thought that only debug builds would be too large,
# but this has recently stopped being true. See the mingw function # but this has recently stopped being true. See the mingw function
# for notes on why this shouldn't be enabled for gcc # for notes on why this shouldn't be enabled for gcc
@ -590,6 +598,9 @@ def configure_msvc(env: "SConsEnvironment", vcvars_msvc_config):
if env["target"] in ["editor", "template_debug"]: if env["target"] in ["editor", "template_debug"]:
LIBS += ["psapi", "dbghelp"] LIBS += ["psapi", "dbghelp"]
if env["use_llvm"]:
LIBS += [f"clang_rt.builtins-{env['arch']}"]
env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS]) env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS])
if vcvars_msvc_config: if vcvars_msvc_config:
@ -605,14 +616,22 @@ def configure_msvc(env: "SConsEnvironment", vcvars_msvc_config):
if env["lto"] != "none": if env["lto"] != "none":
if env["lto"] == "thin": if env["lto"] == "thin":
print_error("ThinLTO is only compatible with LLVM, use `use_llvm=yes` or `lto=full`.") if not env["use_llvm"]:
sys.exit(255) print("ThinLTO is only compatible with LLVM, use `use_llvm=yes` or `lto=full`.")
env.AppendUnique(CCFLAGS=["/GL"]) sys.exit(255)
env.AppendUnique(ARFLAGS=["/LTCG"])
if env["progress"]: env.Append(CCFLAGS=["-flto=thin"])
env.AppendUnique(LINKFLAGS=["/LTCG:STATUS"]) env.Append(LINKFLAGS=["-flto=thin"])
elif env["use_llvm"]:
env.Append(CCFLAGS=["-flto"])
env.Append(LINKFLAGS=["-flto"])
else: else:
env.AppendUnique(LINKFLAGS=["/LTCG"]) env.AppendUnique(CCFLAGS=["/GL"])
env.AppendUnique(ARFLAGS=["/LTCG"])
if env["progress"]:
env.AppendUnique(LINKFLAGS=["/LTCG:STATUS"])
else:
env.AppendUnique(LINKFLAGS=["/LTCG"])
if vcvars_msvc_config: if vcvars_msvc_config:
env.Prepend(CPPPATH=[p for p in str(os.getenv("INCLUDE")).split(";")]) env.Prepend(CPPPATH=[p for p in str(os.getenv("INCLUDE")).split(";")])

View File

@ -35,9 +35,8 @@
class Voxelizer { class Voxelizer {
private: private:
enum { enum : uint32_t {
CHILD_EMPTY = 0xFFFFFFFF CHILD_EMPTY = 0xFFFFFFFF
}; };
struct Cell { struct Cell {

View File

@ -49,7 +49,7 @@ namespace RendererRD {
class LightStorage : public RendererLightStorage { class LightStorage : public RendererLightStorage {
public: public:
enum ShadowAtlastQuadrant { enum ShadowAtlastQuadrant : uint32_t {
QUADRANT_SHIFT = 27, QUADRANT_SHIFT = 27,
OMNI_LIGHT_FLAG = 1 << 26, OMNI_LIGHT_FLAG = 1 << 26,
SHADOW_INDEX_MASK = OMNI_LIGHT_FLAG - 1, SHADOW_INDEX_MASK = OMNI_LIGHT_FLAG - 1,

View File

@ -377,7 +377,9 @@ public:
// used for the render pipelines. // used for the render pipelines.
struct AttachmentFormat { struct AttachmentFormat {
enum { UNUSED_ATTACHMENT = 0xFFFFFFFF }; enum : uint32_t {
UNUSED_ATTACHMENT = 0xFFFFFFFF
};
DataFormat format; DataFormat format;
TextureSamples samples; TextureSamples samples;
uint32_t usage_flags; uint32_t usage_flags;

View File

@ -0,0 +1,19 @@
diff --git a/thirdparty/libwebp/src/dsp/cpu.h b/thirdparty/libwebp/src/dsp/cpu.h
index c86540f280..4dbe607aec 100644
--- a/thirdparty/libwebp/src/dsp/cpu.h
+++ b/thirdparty/libwebp/src/dsp/cpu.h
@@ -47,12 +47,12 @@
// x86 defines.
#if !defined(HAVE_CONFIG_H)
-#if defined(_MSC_VER) && _MSC_VER > 1310 && \
+#if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER > 1310 && \
(defined(_M_X64) || defined(_M_IX86))
#define WEBP_MSC_SSE2 // Visual C++ SSE2 targets
#endif
-#if defined(_MSC_VER) && _MSC_VER >= 1500 && \
+#if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER >= 1500 && \
(defined(_M_X64) || defined(_M_IX86))
#define WEBP_MSC_SSE41 // Visual C++ SSE4.1 targets
#endif

View File

@ -47,12 +47,12 @@
// x86 defines. // x86 defines.
#if !defined(HAVE_CONFIG_H) #if !defined(HAVE_CONFIG_H)
#if defined(_MSC_VER) && _MSC_VER > 1310 && \ #if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER > 1310 && \
(defined(_M_X64) || defined(_M_IX86)) (defined(_M_X64) || defined(_M_IX86))
#define WEBP_MSC_SSE2 // Visual C++ SSE2 targets #define WEBP_MSC_SSE2 // Visual C++ SSE2 targets
#endif #endif
#if defined(_MSC_VER) && _MSC_VER >= 1500 && \ #if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER >= 1500 && \
(defined(_M_X64) || defined(_M_IX86)) (defined(_M_X64) || defined(_M_IX86))
#define WEBP_MSC_SSE41 // Visual C++ SSE4.1 targets #define WEBP_MSC_SSE41 // Visual C++ SSE4.1 targets
#endif #endif