From 7ed7ba11cbdddbdc06f547b8c76c5099f5d42694 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sat, 1 Aug 2026 22:46:02 +0100 Subject: [PATCH 1/8] Add support for LLVM-based MSVC builds --- toolchain/msvc-toolchain.xml | 42 ++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/toolchain/msvc-toolchain.xml b/toolchain/msvc-toolchain.xml index fc2383848..d07e64a32 100644 --- a/toolchain/msvc-toolchain.xml +++ b/toolchain/msvc-toolchain.xml @@ -3,7 +3,27 @@ + +
+ + + + + + + +
+ +
+ + + + + + + +
@@ -52,8 +72,10 @@ + + @@ -107,18 +129,26 @@ - - + +
+ +
+
+ + +
+ - + - +
+ @@ -142,6 +172,7 @@ + @@ -166,6 +197,7 @@ + @@ -175,6 +207,7 @@ + @@ -197,6 +230,7 @@ + From 9e266a50dbcb9c90b436e070d8d500f38ee6d67f Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sat, 1 Aug 2026 22:46:43 +0100 Subject: [PATCH 2/8] Fix pcre2 std flag check For the clang based MSVC toolchain, MSVC_VER doesn't get set, only isMsvc. --- src/hx/libs/regexp/pcre2_sources.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hx/libs/regexp/pcre2_sources.xml b/src/hx/libs/regexp/pcre2_sources.xml index a70d8fa0e..e91bb83c8 100644 --- a/src/hx/libs/regexp/pcre2_sources.xml +++ b/src/hx/libs/regexp/pcre2_sources.xml @@ -3,7 +3,7 @@ - + @@ -32,4 +32,4 @@ - \ No newline at end of file + From 6740a79f31747d309c4d0ae35cd00e1217df5ba3 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sat, 1 Aug 2026 22:48:08 +0100 Subject: [PATCH 3/8] Keep msvc style pch for msvc llvm If inPCH was specified, then respect it rather than reading the compiler output. --- tools/hxcpp/Compiler.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index e93674865..6fcb57e1e 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -695,7 +695,7 @@ class Compiler mPCH = inPCH; createCompilerVersion(); final regex = ~/clang/i; - if (inPCH != null && regex.match(mCompilerVersionString)) { + if (inPCH == null && regex.match(mCompilerVersionString)) { mPCH = "clang"; } switch (mPCH) { From 015ff5a24ecd0f402f8d03240e09cd40af90e0bd Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sun, 2 Aug 2026 01:01:29 +0100 Subject: [PATCH 4/8] Avoid -Yl use for msvc llvm pch clang-cl does not handle pchs in the same way, and it gives a warning when this flag is included. --- tools/hxcpp/BuildTool.hx | 5 +++++ tools/hxcpp/Compiler.hx | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index 4f553eade..766d57fab 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -1525,6 +1525,11 @@ class BuildTool return instance.mDefines.get("toolchain")=="msvc"; } + public static function isMsvcLlvm() + { + return isMsvc() && instance.mDefines.exists("HXCPP_MSVC_LLVM"); + } + public static function isMingw() { return instance.mDefines.get("toolchain")=="mingw"; diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 6fcb57e1e..e2384648c 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -640,8 +640,10 @@ class Compiler if (mPCH == "msvc") { args.push( mPCHCreate + header + ".h" ); - var symbol = "link" + Md5.encode( PathManager.combine(dir, file + mExt) ); - args.push( "-Yl" + symbol ); + if (!BuildTool.isMsvcLlvm()) { + var symbol = "link" + Md5.encode( PathManager.combine(dir, file + mExt) ); + args.push( "-Yl" + symbol ); + } // Create a temp file for including ... var tmp_cpp = dir + "/" + file + ".cpp"; From 9556dd52e6db73d87ecf3d8e0c6b70c7f8a995a3 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sat, 1 Aug 2026 23:45:41 +0100 Subject: [PATCH 5/8] Skip cl version check for msvc llvm --- tools/hxcpp/Setup.hx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/hxcpp/Setup.hx b/tools/hxcpp/Setup.hx index d2bd8fefd..813a095e7 100644 --- a/tools/hxcpp/Setup.hx +++ b/tools/hxcpp/Setup.hx @@ -901,6 +901,8 @@ class Setup } } + if (ioDefines.exists("HXCPP_MSVC_LLVM")) return; + try { var proc = new Process("cl.exe",[]); From 1a91db30663a0f8c2312be1447a6859049babaf7 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sat, 1 Aug 2026 22:48:40 +0100 Subject: [PATCH 6/8] Support llvm msvc build from linux host --- toolchain/msvc-toolchain.xml | 12 +++++++++++- tools/hxcpp/BuildTool.hx | 11 ++++++++--- tools/hxcpp/Setup.hx | 3 ++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/toolchain/msvc-toolchain.xml b/toolchain/msvc-toolchain.xml index d07e64a32..efc8ca49e 100644 --- a/toolchain/msvc-toolchain.xml +++ b/toolchain/msvc-toolchain.xml @@ -3,7 +3,7 @@ - +
@@ -75,6 +75,11 @@ +
+ + +
+ @@ -150,6 +155,7 @@ + @@ -175,6 +181,7 @@ + @@ -199,6 +206,7 @@ + @@ -210,6 +218,7 @@ + @@ -235,6 +244,7 @@ + diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index 766d57fab..bb5434e05 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -2134,9 +2134,14 @@ class BuildTool // Cross-compile? if(defines.exists("windows")) { - defines.set("toolchain","mingw"); - defines.set("mingw", "mingw"); - defines.set("xcompile","1"); + if (defines.exists("HXCPP_MSVC_LLVM")) + defines.set("toolchain", "msvc"); + else + { + defines.set("toolchain","mingw"); + defines.set("mingw", "mingw"); + } + defines.set("xcompile", "1"); defines.set("BINDIR", arm64 ? "WindowsArm64" : m64 ? "Windows64":"Windows"); } else diff --git a/tools/hxcpp/Setup.hx b/tools/hxcpp/Setup.hx index 813a095e7..899cc3bf4 100644 --- a/tools/hxcpp/Setup.hx +++ b/tools/hxcpp/Setup.hx @@ -781,7 +781,8 @@ class Setup public static function setupMSVC(ioDefines:Hash, in64:Bool, inArm64, isWinRT:Bool) { var detectMsvc = !ioDefines.exists("NO_AUTO_MSVC") && - !ioDefines.exists("HXCPP_MSVC_CUSTOM"); + !ioDefines.exists("HXCPP_MSVC_CUSTOM") && + !ioDefines.exists("HXCPP_MSVC_ROOT"); if (ioDefines.exists("HXCPP_MSVC_VER")) { From 544a6aa146997bf50087a914b6b735ca061da004 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sun, 2 Aug 2026 00:15:23 +0100 Subject: [PATCH 7/8] docs: Add HXCPP_MSVC_LLVM and HXCPP_MSVC_ROOT --- docs/build_xml/Defines.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/build_xml/Defines.md b/docs/build_xml/Defines.md index 319c47cca..6d89b214a 100755 --- a/docs/build_xml/Defines.md +++ b/docs/build_xml/Defines.md @@ -91,3 +91,5 @@ Defines affecting target architecture. | *HXCPP_MINGW* | Compile for windows using mingw | | *NO_AUTO_MSVC* | Do not detect msvc location, use the one already in the executable path | | *HXCPP_WINXP_COMPAT* | Remain compatible with Windows XP. Disables condition variables. No effect on ARM. | +| *HXCPP_MSVC_LLVM* | Compile for windows using the LLVM-based MSVC toolchain | +| *HXCPP_MSVC_ROOT* | Set the root for MSVC libraries and headers | From b8e80fb623444505e6b94fed3112eb11faad9dea Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sun, 2 Aug 2026 15:30:31 +0100 Subject: [PATCH 8/8] Preserve old pch detection behavior > Apple and Android toolchains set USE_PRECOMPILED_HEADERS to gcc (by including gcc-toolchain.xml) so that needs to be overriden for precompiled headers to work. Just hardcode a special case for clang-cl for now. --- tools/hxcpp/Compiler.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index e2384648c..5531497dd 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -697,7 +697,7 @@ class Compiler mPCH = inPCH; createCompilerVersion(); final regex = ~/clang/i; - if (inPCH == null && regex.match(mCompilerVersionString)) { + if (inPCH != null && regex.match(mCompilerVersionString) && !BuildTool.isMsvcLlvm()) { mPCH = "clang"; } switch (mPCH) {