From 9e8197b41b0881ecf3ea7c2a77e186048bcf90df Mon Sep 17 00:00:00 2001 From: Chris Speciale Date: Fri, 27 Nov 2026 13:54:21 -0500 Subject: [PATCH 1/5] Let Emscripten builds use the C++ standard they ask for The Emscripten toolchain added --std=c++11 to every C++ compile, after the -std the build tool sets from the group's or the file's cxx_standard, HXCPP_CXX_STANDARD, HXCPP_CPP14 or HXCPP_CPP17. Clang takes the last -std it is given, so all of those did nothing on Emscripten, and every file, the precompiled header included, compiled as C++11. The GCW Zero toolchain had the same flag. Both lines are gone. The build tool already gives every C++ file a standard, C++11 unless something asks for another, so a build that sets none compiles as before. Tests: the Emscripten job builds test/cxx_standard, whose group asks for C++17, one of its files for C++14, and Build_legacy.xml for HXCPP_CPP17. With emcc 3.1.74 all three failed before ("Not C++14", "Not C++17") and build now. test/emscripten still builds and runs. HaxeFoundation/hxcpp#1232 --- .github/workflows/main.yml | 12 ++++++++++++ Changes.md | 2 ++ toolchain/emscripten-toolchain.xml | 1 - toolchain/gcw0-toolchain.xml | 1 - 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 439411273..bee5b3f1e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -273,6 +273,18 @@ jobs: working-directory: test/regression run: haxe --run Run -D emscripten + # Each file must compile with the standard its group, its own + # cxx_standard or HXCPP_CPP17 asks for: the toolchain once pinned C++11 + # after the build tool's -std, so all three built as C++11 + - name: Build with each file's C++ standard + if: ${{ !cancelled() && steps.setup.outcome == 'success' }} + working-directory: test/cxx_standard + run: | + for xml in *.xml; do + haxelib run hxcpp $xml -Demscripten + haxelib run hxcpp $xml clean -Demscripten + done + - name: Run the memory and stack test if: ${{ !cancelled() && steps.setup.outcome == 'success' }} run: timeout 600 sh test/emscripten/run.sh diff --git a/Changes.md b/Changes.md index 9ee21cc4f..5223e0c51 100644 --- a/Changes.md +++ b/Changes.md @@ -2,6 +2,8 @@ libhxcpp 6.0.2 (unreleased) ------------------------------------------------------------ +* Fixed Emscripten builds ignoring the C++ standard: the toolchain added --std=c++11 after the build tool's own -std, so HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 and cxx_standard did nothing there and every file, the precompiled header included, compiled as C++11. Each file gets the standard it asks for now, C++11 by default as before, so an Emscripten build compiles everything once more after updating. The GCW Zero toolchain had the same flag (HaxeFoundation/hxcpp#1232) + libhxcpp 6.0.1 ------------------------------------------------------------ diff --git a/toolchain/emscripten-toolchain.xml b/toolchain/emscripten-toolchain.xml index 27e3dbe6d..6c8cb9180 100644 --- a/toolchain/emscripten-toolchain.xml +++ b/toolchain/emscripten-toolchain.xml @@ -106,7 +106,6 @@ -
diff --git a/toolchain/gcw0-toolchain.xml b/toolchain/gcw0-toolchain.xml index ddbb5295c..aa9050d29 100644 --- a/toolchain/gcw0-toolchain.xml +++ b/toolchain/gcw0-toolchain.xml @@ -29,7 +29,6 @@ - From 6dbdc45700e16b30b3bbffd5a50efcafdb9969b9 Mon Sep 17 00:00:00 2001 From: Chris Speciale Date: Fri, 27 Nov 2026 13:58:53 -0500 Subject: [PATCH 2/5] Compile Objective-C++ with the C++ standard asked for The Objective-C++ standard defaulted to 11 whenever HXCPP_OBJCXX_STANDARD was not set, so its fallback to the group's C++ standard never ran, and .mm files compiled as C++11 whatever HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 or cxx_standard said. With -D objc, Haxe names every generated file .mm, so all of a program's Haxe code was C++11 while the runtime's .cpp files followed the setting. A file with its own cxx_standard also took its group's Objective-C++ standard, and a .m file with its own c_standard its group's Objective-C one. An Objective-C or Objective-C++ standard nobody set is now null, and Compiler.addStandard resolves it to the file's C or C++ standard when it compiles. A file's own c_standard or cxx_standard is nearer than its group's Objective-C or Objective-C++ one, so it wins. objc_standard, objcxx_standard, HXCPP_OBJC_STANDARD and HXCPP_OBJCXX_STANDARD still set them apart. Resolving at compile time also keeps Objective-C++ with the C++ standard of a group opened again with another cxx_standard, where the copy made the first time kept the old one. Tests: test/cxx_standard builds .mm and .m files when the target is macOS or Emscripten: one following its group's C++17, one with cxx_standard 14, one following HXCPP_CPP17, one with objcxx_standard 14 in a C++17 group, and a .m with c_standard 17. Built with emcc 3.1.74, the first three and the .m failed before ("Not C++17", "Not C++14", "Not C17") and all build now. The macOS job and the Emscripten job run them. HaxeFoundation/hxcpp#1250 --- Changes.md | 1 + docs/build_xml/Defines.md | 4 ++-- docs/build_xml/Files.md | 8 ++++---- test/cxx_standard/Build.xml | 6 ++++++ test/cxx_standard/Build_legacy.xml | 1 + test/cxx_standard/Build_section.xml | 2 ++ test/cxx_standard/objc17.m | 6 ++++++ test/cxx_standard/objcxx14.mm | 6 ++++++ test/cxx_standard/objcxx17.mm | 6 ++++++ tools/hxcpp/BuildTool.hx | 17 +++++++++++------ tools/hxcpp/Compiler.hx | 12 ++++++++---- 11 files changed, 53 insertions(+), 16 deletions(-) mode change 100755 => 100644 docs/build_xml/Defines.md mode change 100755 => 100644 docs/build_xml/Files.md create mode 100644 test/cxx_standard/objc17.m create mode 100644 test/cxx_standard/objcxx14.mm create mode 100644 test/cxx_standard/objcxx17.mm diff --git a/Changes.md b/Changes.md index 5223e0c51..7d329cad0 100644 --- a/Changes.md +++ b/Changes.md @@ -3,6 +3,7 @@ libhxcpp 6.0.2 (unreleased) ------------------------------------------------------------ * Fixed Emscripten builds ignoring the C++ standard: the toolchain added --std=c++11 after the build tool's own -std, so HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 and cxx_standard did nothing there and every file, the precompiled header included, compiled as C++11. Each file gets the standard it asks for now, C++11 by default as before, so an Emscripten build compiles everything once more after updating. The GCW Zero toolchain had the same flag (HaxeFoundation/hxcpp#1232) +* Fixed Objective-C++ ignoring the C++ standard: it compiled as C++11 whatever HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 or cxx_standard asked for, and with -D objc, which makes every generated file .mm, so did all of a program's Haxe code while the runtime followed the setting. Objective-C++ follows the C++ standard now, and Objective-C the C one, a file's own cxx_standard or c_standard included; objcxx_standard, objc_standard, HXCPP_OBJCXX_STANDARD and HXCPP_OBJC_STANDARD still set them apart (HaxeFoundation/hxcpp#1250) libhxcpp 6.0.1 ------------------------------------------------------------ diff --git a/docs/build_xml/Defines.md b/docs/build_xml/Defines.md old mode 100755 new mode 100644 index d31903c28..a32ae532a --- a/docs/build_xml/Defines.md +++ b/docs/build_xml/Defines.md @@ -67,8 +67,8 @@ Defines affecting how the code is compiled. These can be on the command line wh | *HXCPP_C_STANDARD* | Set default C standard | | *HXCPP_CXX_STANDARD* | Set default C++ standard | | *HXCPP_CPP17* | Use C++17, as HXCPP_CXX_STANDARD=17 does | -| *HXCPP_OBJC_STANDARD* | Set default Objective-C standard | -| *HXCPP_OBJCXX_STANDARD* | Set default Objective-C++ standard | +| *HXCPP_OBJC_STANDARD* | Set default Objective-C standard. Without it, Objective-C follows the C standard | +| *HXCPP_OBJCXX_STANDARD* | Set default Objective-C++ standard. Without it, Objective-C++ follows the C++ standard | | *exe_link* | Generate executable file (rather than dynamic library on android) | | *static_link* | Generate static library | | *dll_link* | Generate dynamic library | diff --git a/docs/build_xml/Files.md b/docs/build_xml/Files.md old mode 100755 new mode 100644 index 8291d0718..6679466c3 --- a/docs/build_xml/Files.md +++ b/docs/build_xml/Files.md @@ -13,8 +13,8 @@ The files node defines a group of files that all share the same attributes, incl + `c_standard` = Default C standard for the file group + `cxx_standard` = Default C++ standard for the file group - + `objc_standard` = Default Objective-C standard for the file group - + `objcxx_standard` = Default Objective-C++ standard for the file group + + `objc_standard` = Default Objective-C standard for the file group. Without one, Objective-C follows the C standard + + `objcxx_standard` = Default Objective-C++ standard for the file group. Without one, Objective-C++ follows the C++ standard #### Nodes - *depend* - Declare that all files in the group depend on another file or another file group. ```xml @@ -103,8 +103,8 @@ The files node defines a group of files that all share the same attributes, incl + tags = optional override of group tags. See [Tags.md](Tags.md). + `c_standard` = C standard for the file + `cxx_standard` = C++ standard for the file - + `objc_standard` = Objective-C standard for the file - + `objcxx_standard` = Objective-C++ standard for the file + + `objc_standard` = Objective-C standard for the file. Without one, the file follows its own `c_standard` if it has one, else its group + + `objcxx_standard` = Objective-C++ standard for the file. Without one, the file follows its own `cxx_standard` if it has one, else its group + filterout = allows files to be skipped at compile-time if the named define exists. This is useful when the define is set sometime after the file list is parsed. + depend name = filename of additional dependency diff --git a/test/cxx_standard/Build.xml b/test/cxx_standard/Build.xml index 0198e3145..25bf33367 100644 --- a/test/cxx_standard/Build.xml +++ b/test/cxx_standard/Build.xml @@ -5,6 +5,12 @@ + +
+ + + +
diff --git a/test/cxx_standard/Build_legacy.xml b/test/cxx_standard/Build_legacy.xml index e9c4efa99..972c17543 100644 --- a/test/cxx_standard/Build_legacy.xml +++ b/test/cxx_standard/Build_legacy.xml @@ -4,6 +4,7 @@ + diff --git a/test/cxx_standard/Build_section.xml b/test/cxx_standard/Build_section.xml index af4ab0cdb..5d9f98eb0 100644 --- a/test/cxx_standard/Build_section.xml +++ b/test/cxx_standard/Build_section.xml @@ -3,6 +3,8 @@
+ +
diff --git a/test/cxx_standard/objc17.m b/test/cxx_standard/objc17.m new file mode 100644 index 000000000..1faab122e --- /dev/null +++ b/test/cxx_standard/objc17.m @@ -0,0 +1,6 @@ +#ifndef __OBJC__ +#error "Not Objective-C" +#endif +#if __STDC_VERSION__ < 201710L +#error "Not C17" +#endif diff --git a/test/cxx_standard/objcxx14.mm b/test/cxx_standard/objcxx14.mm new file mode 100644 index 000000000..84620d7fb --- /dev/null +++ b/test/cxx_standard/objcxx14.mm @@ -0,0 +1,6 @@ +#ifndef __OBJC__ +#error "Not Objective-C++" +#endif +#if __cplusplus != 201402L +#error "Not C++14" +#endif diff --git a/test/cxx_standard/objcxx17.mm b/test/cxx_standard/objcxx17.mm new file mode 100644 index 000000000..be897f892 --- /dev/null +++ b/test/cxx_standard/objcxx17.mm @@ -0,0 +1,6 @@ +#ifndef __OBJC__ +#error "Not Objective-C++" +#endif +#if __cplusplus < 201703L +#error "Not C++17" +#endif diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index 2198179c2..06467e8e5 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -1111,10 +1111,11 @@ class BuildTool Log.warn('Increasing default Obj-C++ standard to Obj-C++11 instead of Obj-C++${defaultObjCxxStandard}'); defaultObjCxxStandard = 11; } - } else { - defaultObjCxxStandard = 11; } + // An Objective-C or Objective-C++ standard left null follows the file's + // C or C++ one (Compiler.addStandard), so -D objc, which makes every + // generated file .mm, compiles them with the C++ standard asked for if (inXML.has.c_standard) group.mCStandard = Std.parseInt(substitute(inXML.att.c_standard)); else if (group.mCStandard == null) @@ -1123,7 +1124,7 @@ class BuildTool if (inXML.has.objc_standard) group.mObjCStandard = Std.parseInt(substitute(inXML.att.objc_standard)); else if (group.mObjCStandard == null) - group.mObjCStandard = defaultObjCStandard != null ? defaultObjCStandard : group.mCStandard; + group.mObjCStandard = defaultObjCStandard; if (inXML.has.cxx_standard) group.mCxxStandard = Std.parseInt(substitute(inXML.att.cxx_standard)); @@ -1133,7 +1134,7 @@ class BuildTool if (inXML.has.objcxx_standard) group.mObjCxxStandard = Std.parseInt(substitute(inXML.att.objcxx_standard)); else if (group.mObjCxxStandard == null) - group.mObjCxxStandard = defaultObjCxxStandard != null ? defaultObjCxxStandard : group.mCxxStandard; + group.mObjCxxStandard = defaultObjCxxStandard; for(el in inXML.elements) { @@ -1149,10 +1150,14 @@ class BuildTool group.addFile( file ); } + // A file's own C or C++ standard is nearer than its group's + // Objective-C or Objective-C++ one, so it takes the file's file.mCStandard = el.has.c_standard ? Std.parseInt(substitute(el.att.c_standard)) : group.mCStandard; - file.mObjCStandard = el.has.objc_standard ? Std.parseInt(substitute(el.att.objc_standard)) : group.mObjCStandard; + file.mObjCStandard = el.has.objc_standard ? Std.parseInt(substitute(el.att.objc_standard)) : + el.has.c_standard ? null : group.mObjCStandard; file.mCxxStandard = el.has.cxx_standard ? Std.parseInt(substitute(el.att.cxx_standard)) : group.mCxxStandard; - file.mObjCxxStandard = el.has.objcxx_standard ? Std.parseInt(substitute(el.att.objcxx_standard)) : group.mObjCxxStandard; + file.mObjCxxStandard = el.has.objcxx_standard ? Std.parseInt(substitute(el.att.objcxx_standard)) : + el.has.cxx_standard ? null : group.mObjCxxStandard; if (el.has.tag) { diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 691ea224b..caee2a32e 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -184,13 +184,17 @@ class Compiler args.push('-std=c${inFile.mCStandard}'); } } + // With no Objective-C or Objective-C++ standard of its own, a file + // follows its C or C++ one case ObjC: - if (inFile.mObjCStandard != null) { - args.push('-std=c${inFile.mObjCStandard}'); + var standard = inFile.mObjCStandard != null ? inFile.mObjCStandard : inFile.mCStandard; + if (standard != null) { + args.push('-std=c${standard}'); } case ObjCxx: - if (inFile.mObjCxxStandard != null) { - args.push('-std=c++${inFile.mObjCxxStandard}'); + var standard = inFile.mObjCxxStandard != null ? inFile.mObjCxxStandard : inFile.mCxxStandard; + if (standard != null) { + args.push('-std=c++${standard}'); } case Cxx: if (inFile.mCxxStandard != null) { From 6f074eefb2cea0373f880513d6ecc0f0700d7f96 Mon Sep 17 00:00:00 2001 From: Chris Speciale Date: Fri, 27 Nov 2026 14:04:19 -0500 Subject: [PATCH 3/5] Make a cached precompiled header again when its headers change date Clang keeps the date of each header in a precompiled header, and refuses the precompiled header once a date differs, though the content is the same. The compile cache finds a precompiled header by the content of the group's headers, so after a fresh clone, a branch switched and back, or a CI cache restored over a new checkout, the cached one was reused and the first file that had to compile failed with "has been modified since the precompiled header was built". This hit every clang build with HXCPP_COMPILE_CACHE: macOS, iOS, Android, Emscripten and Linux with clang. #469 fixed headers whose content changed unseen; this is the other way round. A cached precompiled header now keeps, beside it, the date of the header it is made from and of every header its group depends on, which for hxcpp.h is every header it includes. When one differs, earlier as well as later, it is made again, once, and the rest of the group still comes from the cache. Only builds whose compiler checks the dates do this: clang, and clang-cl, whose /Yu reads a clang precompiled header. cl.exe and gcc do not check, and there a new precompiled header would cost more than it saves: MSVC recompiles every cached object older than it. This needs no change to the headers and works with any clang. Having clang compare the content instead (-fpch-validate-input-files-content) would need a newer clang on every platform, and with it clang has been seen to include a #pragma once header again that the precompiled header already holds, so every such header would need include guards. A date that moves back, as a restored or copied tree can give, is caught as well as one that moves forward. Tests: test/compile_cache/pch_dates.sh builds a program with the cache, then edits and builds it again with hxcpp.h dated later and then earlier than the precompiled header. With emcc 3.1.74 (clang 20) the edited builds failed with "mtime changed" before and pass now, and a build with nothing changed still reuses the precompiled header. It passes with MSVC as before. It runs in the test suites on every platform, in the Emscripten job and in the clang-cl job, which is the first to build clang-cl with the cache. HaxeFoundation/hxcpp#1466 --- .github/workflows/main.yml | 10 ++++++ .github/workflows/test.yml | 6 ++++ Changes.md | 1 + test/compile_cache/pch_dates.sh | 56 +++++++++++++++++++++++++++++++++ tools/hxcpp/Compiler.hx | 47 ++++++++++++++++++++++++++- 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 test/compile_cache/pch_dates.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bee5b3f1e..cdb4e682b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -93,6 +93,12 @@ jobs: working-directory: test/haxe run: bin\TestMain + # clang-cl's /Yu reads a clang precompiled header, which keeps each + # header's date, so the compile cache must make it again when one changes + - name: Build with the cached precompiled header after a header's date changes + shell: bash + run: bash test/compile_cache/pch_dates.sh -D HXCPP_MSVC_LLVM -D HXCPP_M64 + check-android: name: Build for Android (${{ matrix.abi }}) if: github.event_name != 'pull_request' @@ -285,6 +291,10 @@ jobs: haxelib run hxcpp $xml clean -Demscripten done + - name: Build with the cached precompiled header after a header's date changes + if: ${{ !cancelled() && steps.setup.outcome == 'success' }} + run: bash test/compile_cache/pch_dates.sh -D emscripten + - name: Run the memory and stack test if: ${{ !cancelled() && steps.setup.outcome == 'success' }} run: timeout 600 sh test/emscripten/run.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d3b15f405..7783c034e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -204,6 +204,12 @@ jobs: if: ${{ !cancelled() && steps.setup.outcome == 'success' }} shell: bash run: bash test/compile_errors/check.sh + # Clang refused a cached precompiled header once a header's date changed + - name: build tool cached precompiled header after a header's date changes + continue-on-error: ${{ inputs.warn_only }} + if: ${{ !cancelled() && steps.setup.outcome == 'success' }} + shell: bash + run: bash test/compile_cache/pch_dates.sh -D $HXCPP_ARCH_FLAG - name: build tool MSVC setup scripts with ! in the Visual Studio path continue-on-error: ${{ inputs.warn_only }} if: ${{ !cancelled() && steps.setup.outcome == 'success' && runner.os == 'Windows' }} diff --git a/Changes.md b/Changes.md index 7d329cad0..c99611847 100644 --- a/Changes.md +++ b/Changes.md @@ -4,6 +4,7 @@ libhxcpp 6.0.2 (unreleased) * Fixed Emscripten builds ignoring the C++ standard: the toolchain added --std=c++11 after the build tool's own -std, so HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 and cxx_standard did nothing there and every file, the precompiled header included, compiled as C++11. Each file gets the standard it asks for now, C++11 by default as before, so an Emscripten build compiles everything once more after updating. The GCW Zero toolchain had the same flag (HaxeFoundation/hxcpp#1232) * Fixed Objective-C++ ignoring the C++ standard: it compiled as C++11 whatever HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 or cxx_standard asked for, and with -D objc, which makes every generated file .mm, so did all of a program's Haxe code while the runtime followed the setting. Objective-C++ follows the C++ standard now, and Objective-C the C one, a file's own cxx_standard or c_standard included; objcxx_standard, objc_standard, HXCPP_OBJCXX_STANDARD and HXCPP_OBJC_STANDARD still set them apart (HaxeFoundation/hxcpp#1250) +* Fixed builds with the compile cache failing on clang once a header's date changed but not its content, as after a fresh clone, a branch switched and back or a restored CI cache: the cached precompiled header is found by content, and clang refused it with "has been modified since the precompiled header was built" at the first file that had to compile, on macOS, iOS, Android, Emscripten and Linux with clang. A cached precompiled header keeps the dates of the headers it was made from now, and is made again when one differs, later or earlier (HaxeFoundation/hxcpp#1466) libhxcpp 6.0.1 ------------------------------------------------------------ diff --git a/test/compile_cache/pch_dates.sh b/test/compile_cache/pch_dates.sh new file mode 100644 index 000000000..5572afafd --- /dev/null +++ b/test/compile_cache/pch_dates.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# HaxeFoundation/hxcpp#1466: clang keeps each header's date in a precompiled +# header and refuses it once a date differs, though the content is the same. +# The compile cache finds a precompiled header by content, so a fresh clone, a +# branch switched and back or a restored CI cache stopped the next compile with +# "has been modified since the precompiled header was built". +# This builds a program with the compile cache, then edits it and builds it +# again with hxcpp.h dated later, and then earlier, than the cached precompiled +# header. Each build must succeed and print what it was edited to. Only clang +# and clang-cl check the dates, but every compiler must pass. +# Uses HXCPP_COMPILE_CACHE, or a cache of its own when that is not set. +# Usage: test/compile_cache/pch_dates.sh [extra haxe args, eg -D HXCPP_M64 or -D emscripten] +cd "$(dirname "$0")" +extra=("$@") +hxcpp=$(haxelib libpath hxcpp | tr -d '\r') +header="${hxcpp//\\//}/include/hxcpp.h" +[ -f "$header" ] || { echo "::error::no hxcpp.h at $header"; exit 1; } +rm -rf bin +mkdir -p bin/src +[ -n "$HXCPP_COMPILE_CACHE" ] || export HXCPP_COMPILE_CACHE="$PWD/bin/cache" + +# Later builds in the same checkout see the header's date as it was +touch -r "$header" bin/header-date +trap 'touch -r bin/header-date "$header"' EXIT + +run() { + if [ -f bin/cpp/Main.js ]; then node bin/cpp/Main.js + elif [ -f bin/cpp/Main.exe ]; then bin/cpp/Main.exe + else bin/cpp/Main + fi +} + +# build : builds and runs a Main that prints its name +build() { + printf 'class Main {\n\tstatic function main() {\n\t\tSys.println("%s");\n\t}\n}\n' "$1" > bin/src/Main.hx + if ! haxe -cp bin/src -m Main --cpp bin/cpp "${extra[@]}" > bin/build.log 2>&1; then + echo "::error::the build $1 failed" + tail -20 bin/build.log + return 1 + fi + local out + out=$(run | tr -d '\r') + if [ "$out" != "$1" ]; then + echo "::error::the build $1 printed \"$out\"" + return 1 + fi + echo "$1: built and printed its name" +} + +failed=0 +build first || failed=1 +touch "$header" +build later || failed=1 +touch -t 200001010000 "$header" +build earlier || failed=1 +exit $failed diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index caee2a32e..65255bce3 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -635,6 +635,39 @@ class Compiler return CompileCache.getPchDir(inGroup.getCacheProject(),md5); } + // Clang keeps the date of each header in a precompiled header, and refuses + // it once one differs, though the content is the same. The cache finds a + // precompiled header by content, so a fresh clone, a branch switched and + // back, or a restored CI cache stopped the next compile with "has been + // modified since the precompiled header was built". The dates it was made + // with are kept beside it, and it is made again when one differs, earlier + // or later. Clang-cl's /Yu does the same; cl.exe and gcc do not check + function pchChecksDates() + { + return mPCH=="clang" || (mPCH=="msvc" && BuildTool.isMsvcLlvm()); + } + + // The precompiled header and every header the group depends on, which + // for hxcpp.h is every header it includes (libhxcpp #469) + function getPchDates(inGroup:FileGroup) + { + var header = inGroup.mPrecompiledHeaderDir + "/" + inGroup.mPrecompiledHeader + ".h"; + var paths = inGroup.mCacheDepends.indexOf(header)<0 ? [header].concat(inGroup.mCacheDepends) : inGroup.mCacheDepends; + var lines = new Array(); + for(path in paths) + lines.push( (FileSystem.exists(path) ? Std.string(FileSystem.stat(path).mtime.getTime()) : "missing") + " " + path ); + return lines.join("\n"); + } + + static function readDates(inName:String):String + { + try { + if (FileSystem.exists(inName)) + return sys.io.File.getContent(inName); + } catch(e:Dynamic) { } + return null; + } + public function precompile(inGroup:FileGroup, inReuseIfPossible:Bool) { // header will be like "hxcpp" or "wx/wx" @@ -649,13 +682,19 @@ class Compiler // Like objs/hxcpp.pch or objs/wx.gch var pch_name = dir + "/" + file + mPCHExt; + var dates = inGroup.isCached() && pchChecksDates() ? getPchDates(inGroup) : null; + var datesName = dir + "/" + file + ".dates"; mPCHRebuilt = false; if (inGroup.isCached() || inReuseIfPossible) { // No obj needed for gcc var obj = mPCH=="msvc" ? PathManager.combine(dir, file + mExt) : null; if (FileSystem.exists(pch_name) && (obj==null || FileSystem.exists(obj)) ) - return obj; + { + if (dates==null || readDates(datesName)==dates) + return obj; + Log.v('Headers of $pch_name have other dates than when it was made'); + } } mPCHRebuilt = true; @@ -714,6 +753,12 @@ class Compiler //throw "Error creating pch: " + result + " - build cancelled"; } + if (dates!=null) + { + try { sys.io.File.saveContent(datesName, dates); } + catch(e:Dynamic) { Log.v('Could not write $datesName: $e'); } + } + if (mPCH == "msvc") return PathManager.combine(dir, file + mExt); return null; From b24dac67389e828b6865c073ae8bdc5dedf86358 Mon Sep 17 00:00:00 2001 From: Chris Speciale Date: Fri, 27 Nov 2026 14:13:34 -0500 Subject: [PATCH 4/5] Trim the compile cache by what builds last used Trimming the cache to HXCPP_CACHE_MB, and "cache days", took an entry's last use from the later of its access and change times. Reusing an entry changes neither: an object up to date in the cache is linked from there without being compiled or copied, one found in the cache by a compile is not touched, and Windows does not update access times by default (DisableLastAccess is 3, system managed and off, on the Windows host here). So the objects every build reused looked as old as when they were compiled, were the first to go, and were compiled again. #473 changed how often trimming runs, not what it removes. Marking an entry by changing its date would cost more than it saves: the linker relinks when an object is newer than its output, so a build with nothing to do would link again, and rewriting thousands of files would undo #473's fast builds. Marking only the entries a compile finds in the cache would miss the ones reused in place, which are most of them. So each target now writes, in the cache's .used folder, the entries its build took from the cache: every object of its cached groups, compiled, found or reused in place, the directory of each cached precompiled header, and each cached library with the record of what it was linked from. The file is named for the target and its object folder, so a debug and a release build keep a list each, and its date is when they were last used. It is rewritten only when the entries change or it is an hour old. Trimming takes an entry's last use as the latest of its own dates and the lists that name it, a precompiled header's files go by their directory's, and a list older than everything trimming keeps is removed with what it named. "cache details" shows the same date, and "cache clear" removes the lists. Tests: test/compile_cache/trim.sh builds a small project with a cached group, a precompiled header and a cached library, edits a file and builds again, which reuses the rest in place, then dates every cache entry back to 2000 and runs "cache days 1". The same build must then do nothing, and the first version of the edited file must compile again. On Windows with MSVC, trimming removed 9 of 9 files before, so the build compiled, precompiled and linked everything again, and removes the 1 stale object now. The test suites run it on every platform. HaxeFoundation/hxcpp#1469 --- .github/workflows/test.yml | 5 ++ Changes.md | 1 + test/compile_cache/trim.sh | 54 ++++++++++++++ test/compile_cache/trim/Build.xml | 20 ++++++ test/compile_cache/trim/lib.cpp | 1 + test/compile_cache/trim/other.cpp | 3 + test/compile_cache/trim/pre.h | 7 ++ tools/hxcpp/BuildTool.hx | 14 ++++ tools/hxcpp/CompileCache.hx | 116 +++++++++++++++++++++++++++--- tools/hxcpp/Linker.hx | 3 + 10 files changed, 214 insertions(+), 10 deletions(-) create mode 100644 test/compile_cache/trim.sh create mode 100644 test/compile_cache/trim/Build.xml create mode 100644 test/compile_cache/trim/lib.cpp create mode 100644 test/compile_cache/trim/other.cpp create mode 100644 test/compile_cache/trim/pre.h diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7783c034e..80c83e237 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -210,6 +210,11 @@ jobs: if: ${{ !cancelled() && steps.setup.outcome == 'success' }} shell: bash run: bash test/compile_cache/pch_dates.sh -D $HXCPP_ARCH_FLAG + - name: build tool compile cache trimming keeps what builds use + continue-on-error: ${{ inputs.warn_only }} + if: ${{ !cancelled() && steps.setup.outcome == 'success' }} + shell: bash + run: bash test/compile_cache/trim.sh -D$HXCPP_ARCH_FLAG - name: build tool MSVC setup scripts with ! in the Visual Studio path continue-on-error: ${{ inputs.warn_only }} if: ${{ !cancelled() && steps.setup.outcome == 'success' && runner.os == 'Windows' }} diff --git a/Changes.md b/Changes.md index c99611847..361cdc344 100644 --- a/Changes.md +++ b/Changes.md @@ -5,6 +5,7 @@ libhxcpp 6.0.2 (unreleased) * Fixed Emscripten builds ignoring the C++ standard: the toolchain added --std=c++11 after the build tool's own -std, so HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 and cxx_standard did nothing there and every file, the precompiled header included, compiled as C++11. Each file gets the standard it asks for now, C++11 by default as before, so an Emscripten build compiles everything once more after updating. The GCW Zero toolchain had the same flag (HaxeFoundation/hxcpp#1232) * Fixed Objective-C++ ignoring the C++ standard: it compiled as C++11 whatever HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 or cxx_standard asked for, and with -D objc, which makes every generated file .mm, so did all of a program's Haxe code while the runtime followed the setting. Objective-C++ follows the C++ standard now, and Objective-C the C one, a file's own cxx_standard or c_standard included; objcxx_standard, objc_standard, HXCPP_OBJCXX_STANDARD and HXCPP_OBJC_STANDARD still set them apart (HaxeFoundation/hxcpp#1250) * Fixed builds with the compile cache failing on clang once a header's date changed but not its content, as after a fresh clone, a branch switched and back or a restored CI cache: the cached precompiled header is found by content, and clang refused it with "has been modified since the precompiled header was built" at the first file that had to compile, on macOS, iOS, Android, Emscripten and Linux with clang. A cached precompiled header keeps the dates of the headers it was made from now, and is made again when one differs, later or earlier (HaxeFoundation/hxcpp#1466) +* Fixed the compile cache removing what builds still use when it trims to HXCPP_CACHE_MB, or with "cache days": it took an entry's last use from its access and change times, which reusing it changes neither, as an object up to date in the cache is linked from there and Windows does not update access times. So objects every build reused looked as old as when they were compiled, went first, and were compiled again. Each target now lists in the cache's .used folder what its last build took from the cache, reused or not, and trimming takes that list's date as their last use; no object's date changes, so a build with nothing to do still links nothing. "cache details" shows that date (HaxeFoundation/hxcpp#1469) libhxcpp 6.0.1 ------------------------------------------------------------ diff --git a/test/compile_cache/trim.sh b/test/compile_cache/trim.sh new file mode 100644 index 000000000..e4f5d8887 --- /dev/null +++ b/test/compile_cache/trim.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# HaxeFoundation/hxcpp#1469: trimming the compile cache, to HXCPP_CACHE_MB or +# by age, took an entry's use from its access and change times. Reusing an +# entry changes neither: an object up to date in the cache is linked from +# there, and Windows does not update access times. So entries every build +# reused looked as old as when they were compiled, and went first. +# This builds trim/Build.xml with a cache of its own, edits main.cpp and builds +# again, which reuses the rest in place, then dates every entry back to 2000, +# as if compiled long ago and never read since. Trimming to one day must keep +# all the last build used, so that build does nothing again, and remove the +# first main.cpp's object, which nothing has used since. +# Usage: test/compile_cache/trim.sh [extra build tool args, eg -DHXCPP_M64] +cd "$(dirname "$0")" +extra=("$@") +rm -rf bin/trim +mkdir -p bin/trim +cp trim/* bin/trim/ +cd bin/trim +export HXCPP_COMPILE_CACHE="$PWD/cache" + +# build : builds with a main.cpp of its own +build() { + printf '#include \n\nint main() { return other() + libValue() - %s; }\n' "$2" > main.cpp + if ! haxelib run hxcpp Build.xml "${extra[@]}" > "$1.log" 2>&1; then + echo "::error::the build $1 failed" + tail -20 "$1.log" + exit 1 + fi +} + +build first 1 +build second 2 +# The records of what each build used keep their dates +find cache -path cache/.used -prune -o -type f -exec touch -t 200001010000 {} + +haxelib run hxcpp cache days 1 "${extra[@]}" > trim.log 2>&1 || { echo "::error::trimming failed"; cat trim.log; exit 1; } +grep "Cache:" trim.log + +failed=0 +build again 2 +if grep -q "Compiling group\|Creating\|Link:" again.log; then + echo "::error::trimming removed what the last build used, so building it again did this:" + grep "Compiling group\|Creating\|Link:" again.log + failed=1 +else + echo "trimming kept what the last build used" +fi +build old 1 +if grep -q "Compiling group" old.log; then + echo "trimming removed the first main.cpp's object" +else + echo "::error::trimming kept the first main.cpp's object, which nothing has used since" + failed=1 +fi +exit $failed diff --git a/test/compile_cache/trim/Build.xml b/test/compile_cache/trim/Build.xml new file mode 100644 index 000000000..f6f6e723e --- /dev/null +++ b/test/compile_cache/trim/Build.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/test/compile_cache/trim/lib.cpp b/test/compile_cache/trim/lib.cpp new file mode 100644 index 000000000..c8fad5088 --- /dev/null +++ b/test/compile_cache/trim/lib.cpp @@ -0,0 +1 @@ +int libValue() { return 2; } diff --git a/test/compile_cache/trim/other.cpp b/test/compile_cache/trim/other.cpp new file mode 100644 index 000000000..24c79eb25 --- /dev/null +++ b/test/compile_cache/trim/other.cpp @@ -0,0 +1,3 @@ +#include + +int other() { return 1; } diff --git a/test/compile_cache/trim/pre.h b/test/compile_cache/trim/pre.h new file mode 100644 index 000000000..f73adbdd5 --- /dev/null +++ b/test/compile_cache/trim/pre.h @@ -0,0 +1,7 @@ +#ifndef TRIM_TEST_PRE_H +#define TRIM_TEST_PRE_H + +int other(); +int libValue(); + +#endif diff --git a/tools/hxcpp/BuildTool.hx b/tools/hxcpp/BuildTool.hx index 06467e8e5..821309af1 100644 --- a/tools/hxcpp/BuildTool.hx +++ b/tools/hxcpp/BuildTool.hx @@ -477,6 +477,9 @@ class BuildTool // more after them all: any of them can call into it, as hxcpp_std does var linkAgain = new Array(); var runtimeAgain:String = null; + // What this target takes from the compile cache, compiled, found there + // or reused in place, so trimming keeps it (CompileCache.recordUse) + var cacheUsed = new Array(); for(group in target.mFileGroups) { var useCache = CompileCache.hasCache && group.mUseCache; @@ -556,6 +559,8 @@ class BuildTool Profile.push("pch"); var obj = mCompiler.precompile(group,cached || to_be_compiled.length==0); + if (useCache) + cacheUsed.push(mCompiler.getPchDir(group) + "/"); if (obj!=null) { pchStamp = FileSystem.stat(obj).mtime.getTime(); @@ -732,6 +737,11 @@ class BuildTool var libTarget = new Target(libName, "linker", "static_link" ); linker.link(libTarget,groupObjs, mCompiler, [] ); target.mAutoLibs.push(linker.mLastOutName); + if (useCache) + { + cacheUsed.push(linker.mLastOutName); + cacheUsed.push(linker.mLastHashName); + } // Linux the libraries must be added again if the references were not resolved the firs time if (group.mAddTwice) { @@ -754,10 +764,14 @@ class BuildTool { objs = objs.concat(groupObjs); } + if (useCache) + cacheUsed = cacheUsed.concat(groupObjs); if (group.mDir!="." && group.mSetImportDir) Sys.setCwd( baseDir ); } + if (cacheUsed.length>0) + CompileCache.recordUse(mCompiler.mObjDir + " " + targetKey, cacheUsed); if (runtimeAgain!=null) linkAgain.push(runtimeAgain); for(lib in linkAgain) diff --git a/tools/hxcpp/CompileCache.hx b/tools/hxcpp/CompileCache.hx index 9392f3e1b..86bff30d7 100644 --- a/tools/hxcpp/CompileCache.hx +++ b/tools/hxcpp/CompileCache.hx @@ -109,6 +109,88 @@ class CompileCache return true; } + // Trimming keeps what builds use, but reusing an entry leaves it as it + // was: an object up to date in the cache is linked from there, and + // Windows does not update access times. Changing an object's date would + // relink every build. So each target lists here the entries its last + // build used, and the list's date is when it used them + static inline var USE_DIR = ".used"; + + public static function recordUse(inTarget:String, inEntries:Array) + { + if (!hasCache) + return; + var prefix = compileCache + "/"; + var seen = new Map(); + var names = new Array(); + for(entry in inEntries) + { + entry = entry.split("\\").join("/"); + if (!StringTools.startsWith(entry, prefix)) + continue; + var parts = entry.substr(prefix.length).split("/"); + if (parts.length<2) + continue; + // A precompiled header's directory is used as a whole + var name = parts[1].substr(0,3)=="pch" ? parts[0] + "/" + parts[1] : parts.join("/"); + if (!seen.exists(name)) + { + seen.set(name,true); + names.push(name); + } + } + names.sort(Reflect.compare); + var content = names.join("\n"); + var dir = compileCache + "/" + USE_DIR; + var record = dir + "/" + haxe.crypto.Md5.encode(inTarget); + try + { + // The same entries recorded within the hour is near enough + if (FileSystem.exists(record) && Date.now().getTime() - FileSystem.stat(record).mtime.getTime() < 3600 * 1000.0 && + sys.io.File.getContent(record)==content) + return; + if (!FileSystem.exists(dir)) + PathManager.mkdir(dir); + sys.io.File.saveContent(record, content); + } + catch(e:Dynamic) + { + Log.v('Could not record the cache entries used in $record: $e'); + } + } + + // When each entry was last used, as far as the records tell + static function readUse(ioRecords:Array<{ filename:String, time:Float }>) + { + var used = new Map(); + var dir = compileCache + "/" + USE_DIR; + if (!FileSystem.exists(dir) || !FileSystem.isDirectory(dir)) + return used; + for(file in FileSystem.readDirectory(dir)) + { + var filename = dir + "/" + file; + try + { + var time = FileSystem.stat(filename).mtime.getTime(); + ioRecords.push( { filename:filename, time:time } ); + for(name in sys.io.File.getContent(filename).split("\n")) + if (name!="" && (!used.exists(name) || used.get(name), inProject:String, inDir:String, inFile:String, inInfo:sys.FileStat) + { + var time = inInfo.atime==null ? inInfo.mtime.getTime() : Math.max(inInfo.atime.getTime(),inInfo.mtime.getTime()); + var name = inDir.substr(0,3)=="pch" ? inProject + "/" + inDir : inProject + "/" + inDir + "/" + inFile; + return inUsed.exists(name) ? Math.max(time, inUsed.get(name)) : time; + } + public static function clear(inDays:Int,inMB:Int,inLogInfo:Bool,inProject:String) { try @@ -120,11 +202,16 @@ class CompileCache var tooOld = Date.now().getTime() - inDays * 24 * 3600 * 1000.0; var sizeKB:Float = 0; var fileInfo = []; + var records = []; + var used = readUse(records); for(project in projects) { if (inProject!=null && inProject!=project) continue; + // Not the use records, nor the time of the last trim + if (project.substr(0,1)==".") + continue; var projectHasDirs = false; var projDir = compileCache + "/" + project; if(!FileSystem.isDirectory(projDir)) @@ -152,18 +239,14 @@ class CompileCache if (inDays>0) { var info = FileSystem.stat(filename); - var atime = info.atime; - var time = atime==null ? info.mtime.getTime() : - Math.max(info.atime.getTime(),info.mtime.getTime() ); + var time = lastUse(used, project, dir, file, info); if (time>=tooOld) doDelete = false; } else if (inMB>0) { var info = FileSystem.stat(filename); - var atime = info.atime; - var time = atime==null ? info.mtime.getTime() : - Math.max(info.atime.getTime(),info.mtime.getTime() ); + var time = lastUse(used, project, dir, file, info); fileInfo.push( {filename:filename, time:time, size:info.size } ); sizeKB += info.size/1024; doDelete = false; @@ -211,6 +294,9 @@ class CompileCache } } + // A record older than every entry kept keeps nothing. Trimming one + // project leaves the records, which list others' entries too + var recordsBefore:Null = inDays>0 ? tooOld : null; if (inMB*1024(); From 6a127ef89db97b6cd3bc519eb19bf4ce18d9679e Mon Sep 17 00:00:00 2001 From: Chris Speciale Date: Fri, 27 Nov 2026 14:20:51 -0500 Subject: [PATCH 5/5] Use the native MSVC on a Windows ARM64 machine On an ARM64 machine setup set msvc_host_arch to x86, so the ARM64 desktop and WinRT scripts asked for the x86-hosted cross compiler, from VsDevCmd (-host_arch=x86) and from HXCPP_MSVC_VER's install (vcvarsx86_arm64.bat) alike. Windows runs it emulated in 32 bits, and it can run out of memory on a precompiled header, even with the ARM64-hosted compiler installed beside it. msvc_host_arch is now the hosts to try, best first: "arm64 x64 x86" on an ARM64 machine, where the x64-hosted compiler runs emulated but with a 64-bit address space, and "x64" elsewhere, as before. The ARM64 scripts take the first whose cl.exe for arm64 is in the install's default MSVC tools, and run VsDevCmd, or the vcvars script Visual Studio names for it (vcvarsarm64.bat for the native one), with that host. They look for the compiler rather than its folder: an install without the ARM64 tools can still have HostArm64\arm64, as the x64 one here does, holding only the address sanitizer's files. With none found, the first host is used, as before. Leaving -host_arch out is no answer: VsDevCmd then takes the host to be the target, which picks ARM64-hosted tools on an x64 machine as well. Windows ARM64 also gets a CI job, the core suites on windows-11-arm on pushes to main. setup-haxe's latest release, v2.1.1, has no Windows arm64 support, so that runner uses the commit that added it (2158bbde, merged on 2026-10-18), pinned by its hash, which installs the x64 Haxe and Neko for Windows to run emulated. The C++ itself compiles with the ARM64-hosted compiler. Tests: test/msvc_setup/check.ps1 gives a stand-in install, for HXCPP_MSVC_VER, a compiler for arm64 on each host, and takes them away one by one: the ARM64 script runs vcvarsarm64.bat, then vcvarsamd64_arm64.bat, then vcvarsx86_arm64.bat, and the old script failed all three. With the real Visual Studio, both ARM64 scripts must call VsDevCmd for the best host it has a compiler for arm64 on, which on the ARM64 runner is the native one; this machine has no compiler for arm64, so that part is skipped here. HaxeFoundation/hxcpp#1400 --- .github/workflows/platforms.yml | 14 +++++++++ .github/workflows/setup/action.yml | 10 +++++++ Changes.md | 1 + test/msvc_setup/check.ps1 | 45 ++++++++++++++++++++++++---- toolchain/msvc-arm64-setup.bat | 26 +++++++++++----- toolchain/msvc-winrt-arm64-setup.bat | 8 ++++- tools/hxcpp/Setup.hx | 6 +++- 7 files changed, 96 insertions(+), 14 deletions(-) diff --git a/.github/workflows/platforms.yml b/.github/workflows/platforms.yml index e595494a7..6afa13708 100644 --- a/.github/workflows/platforms.yml +++ b/.github/workflows/platforms.yml @@ -44,6 +44,20 @@ jobs: scope: ${{ inputs.pr && 'smoke' || 'full' }} stress: '["default generational verify", "generational-verify moving big-blocks", "always-move check-pointer", "big-generational big-verify nursery dynamic-size debug-level"]' + # Haxe has no Windows arm64 build, so the x64 Haxe and Neko run emulated, + # and the C++ compiles with the ARM64-hosted compiler + WindowsArm64: + if: ${{ !inputs.pr }} + uses: ./.github/workflows/test.yml + name: Windows arm64 + with: + haxe: ${{ inputs.haxe }} + arch: Arm64 + sep: \ + ext: .dll + os: windows-11-arm + scope: smoke + MacOS64: if: ${{ !inputs.pr }} uses: ./.github/workflows/test.yml diff --git a/.github/workflows/setup/action.yml b/.github/workflows/setup/action.yml index 9a04d692a..8da7cf5b5 100644 --- a/.github/workflows/setup/action.yml +++ b/.github/workflows/setup/action.yml @@ -7,10 +7,20 @@ runs: using: composite steps: - name: install haxe + if: runner.os != 'Windows' || runner.arch != 'ARM64' uses: krdlab/setup-haxe@v2 with: haxe-version: ${{ inputs.haxe }} + # setup-haxe's releases, v2.1.1 the latest, have no Windows arm64 support. + # The commit that added it, merged on 2026-10-18, installs the x64 Haxe + # and Neko there, which Windows runs emulated; use a release once one has it + - name: install haxe (Windows arm64) + if: runner.os == 'Windows' && runner.arch == 'ARM64' + uses: krdlab/setup-haxe@2158bbdec718708920c54ab91fb19d8ddfa28f32 + with: + haxe-version: ${{ inputs.haxe }} + - name: install haxe libraries shell: pwsh run: | diff --git a/Changes.md b/Changes.md index 361cdc344..fc7226ce7 100644 --- a/Changes.md +++ b/Changes.md @@ -6,6 +6,7 @@ libhxcpp 6.0.2 (unreleased) * Fixed Objective-C++ ignoring the C++ standard: it compiled as C++11 whatever HXCPP_CXX_STANDARD, HXCPP_CPP14, HXCPP_CPP17 or cxx_standard asked for, and with -D objc, which makes every generated file .mm, so did all of a program's Haxe code while the runtime followed the setting. Objective-C++ follows the C++ standard now, and Objective-C the C one, a file's own cxx_standard or c_standard included; objcxx_standard, objc_standard, HXCPP_OBJCXX_STANDARD and HXCPP_OBJC_STANDARD still set them apart (HaxeFoundation/hxcpp#1250) * Fixed builds with the compile cache failing on clang once a header's date changed but not its content, as after a fresh clone, a branch switched and back or a restored CI cache: the cached precompiled header is found by content, and clang refused it with "has been modified since the precompiled header was built" at the first file that had to compile, on macOS, iOS, Android, Emscripten and Linux with clang. A cached precompiled header keeps the dates of the headers it was made from now, and is made again when one differs, later or earlier (HaxeFoundation/hxcpp#1466) * Fixed the compile cache removing what builds still use when it trims to HXCPP_CACHE_MB, or with "cache days": it took an entry's last use from its access and change times, which reusing it changes neither, as an object up to date in the cache is linked from there and Windows does not update access times. So objects every build reused looked as old as when they were compiled, went first, and were compiled again. Each target now lists in the cache's .used folder what its last build took from the cache, reused or not, and trimming takes that list's date as their last use; no object's date changes, so a build with nothing to do still links nothing. "cache details" shows that date (HaxeFoundation/hxcpp#1469) +* Fixed builds on a Windows ARM64 machine using the x86-hosted MSVC, which Windows runs emulated in 32 bits and which can run out of memory on a precompiled header: setup asked for it for ARM64 desktop and WinRT builds, through Visual Studio's VsDevCmd and through HXCPP_MSVC_VER's vcvars scripts alike. The ARM64-hosted compiler is used now when it is installed, else the x64-hosted one, which runs emulated with a 64-bit address space, and the x86-hosted one only when neither is. CI runs the core suites on Windows ARM64 (HaxeFoundation/hxcpp#1400) libhxcpp 6.0.1 ------------------------------------------------------------ diff --git a/test/msvc_setup/check.ps1 b/test/msvc_setup/check.ps1 index 17f81e227..d7040cdbf 100644 --- a/test/msvc_setup/check.ps1 +++ b/test/msvc_setup/check.ps1 @@ -35,22 +35,57 @@ foreach ($script in "msvc-setup", "msvc64-setup", "msvc-arm64-setup", "msvc-winr } ${env:ProgramFiles(x86)} = $realPf86 +# On an ARM64 machine msvc_host_arch lists the compilers' hosts best first, and +# the ARM64 scripts call VsDevCmd for the first with a compiler for arm64 +# installed: the native one when there is one +$arm64Hosts = "arm64", "x64", "x86" +$env:msvc_host_arch = $arm64Hosts -join " " +$vcTools = (Get-Content "$realVs\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt").Trim() +$expect = $arm64Hosts | Where-Object { Test-Path "$realVs\VC\Tools\MSVC\$vcTools\bin\Host$_\arm64\cl.exe" } | Select-Object -First 1 +if ($null -eq $expect) { + "skip the ARM64 scripts on an ARM64 machine: this Visual Studio has no compiler for arm64" +} +else { + foreach ($script in "msvc-arm64-setup", "msvc-winrt-arm64-setup") { + $out = cmd /c "$root\toolchain\$script.bat" 2>&1 | Out-String + if ($out -match "(?m)^HXCPP_VARS" -and $out -match "(?m)^VSCMD_ARG_HOST_ARCH=$expect\s*$") { + "ok $script on an ARM64 machine uses the $expect-hosted compiler" + } else { + "FAIL $script on an ARM64 machine: expected the $expect-hosted compiler" + $out -split "`r?`n" | Where-Object { $_ -match "^(Error|VSCMD_ARG_HOST_ARCH|HXCPP_VARS)" } + $failures++ + } + } +} + # HXCPP_MSVC_VER names an install by its Common7\Tools folder, and the ARM64 # script runs that install's vcvars script for the host. A stand-in install -# whose vcvars scripts only say which one ran, named as Visual Studio names them +# whose vcvars scripts only say which one ran, named as Visual Studio names them, +# with a compiler for arm64 on each host until the cases below take them away $fake = "$work\fake vs" New-Item -ItemType Directory -Force "$fake\Common7\Tools", "$fake\VC\Auxiliary\Build" | Out-Null -foreach ($name in "x86_amd64", "x86_arm64", "amd64_x86", "amd64_arm64") { +foreach ($name in "x86_amd64", "x86_arm64", "amd64_x86", "amd64_arm64", "arm64") { Set-Content -Encoding ascii "$fake\VC\Auxiliary\Build\vcvars$name.bat" "@set VCVARS_RAN=$name" } +Set-Content -Encoding ascii "$fake\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" "14.99.0" +foreach ($h in $arm64Hosts) { + New-Item -ItemType Directory -Force "$fake\VC\Tools\MSVC\14.99.0\bin\Host$h\arm64" | Out-Null + Set-Content -Encoding ascii "$fake\VC\Tools\MSVC\14.99.0\bin\Host$h\arm64\cl.exe" "" +} $env:HXCPP_MSVC = "$fake\Common7\Tools\" -foreach ($case in @(@{ host = "x64"; expect = "amd64_arm64" }, @{ host = "x86"; expect = "x86_arm64" })) { +foreach ($case in @( + @{ host = "x64"; expect = "amd64_arm64"; on = "an x64 host" }, + @{ host = "x86"; expect = "x86_arm64"; on = "an x86 host" }, + @{ host = $arm64Hosts -join " "; expect = "arm64"; on = "an ARM64 host" }, + @{ host = $arm64Hosts -join " "; without = "arm64"; expect = "amd64_arm64"; on = "an ARM64 host without the ARM64-hosted compiler" }, + @{ host = $arm64Hosts -join " "; without = "x64"; expect = "x86_arm64"; on = "an ARM64 host with only the x86-hosted compiler" })) { + if ($case.ContainsKey("without")) { Remove-Item "$fake\VC\Tools\MSVC\14.99.0\bin\Host$($case.without)\arm64\cl.exe" } $env:msvc_host_arch = $case.host $out = cmd /c "$root\toolchain\msvc-arm64-setup.bat" 2>&1 | Out-String if ($out -match "(?m)^HXCPP_VARS" -and $out -match "(?m)^VCVARS_RAN=$($case.expect)\s*$") { - "ok msvc-arm64-setup with HXCPP_MSVC on an $($case.host) host" + "ok msvc-arm64-setup with HXCPP_MSVC on $($case.on)" } else { - "FAIL msvc-arm64-setup with HXCPP_MSVC on an $($case.host) host: expected vcvars$($case.expect).bat" + "FAIL msvc-arm64-setup with HXCPP_MSVC on $($case.on): expected vcvars$($case.expect).bat" $out -split "`r?`n" | Where-Object { $_ -match "^(Error|VCVARS_RAN|HXCPP_VARS)" } $failures++ } diff --git a/toolchain/msvc-arm64-setup.bat b/toolchain/msvc-arm64-setup.bat index b3ba42657..d763140f2 100644 --- a/toolchain/msvc-arm64-setup.bat +++ b/toolchain/msvc-arm64-setup.bat @@ -2,21 +2,33 @@ setlocal @set "vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" @set InstallDir= @if exist "%vswhere%" for /f "usebackq tokens=*" %%i in (`"%vswhere%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.arm64 -property installationPath`) do @set "InstallDir=%%i" -@rem Visual Studio names the x64 host amd64 in its vcvars scripts -@set "vcvars_host=%msvc_host_arch%" -@if /i "%vcvars_host%"=="x64" set "vcvars_host=amd64" +@if exist "%HXCPP_MSVC%\..\..\VC\" set "InstallDir=%HXCPP_MSVC%\..\.." +@rem msvc_host_arch lists the compilers' hosts best first, and the first with a +@rem compiler for arm64 installed is used: on an ARM64 machine the native one, +@rem then the x64-hosted one, which Windows runs emulated with a 64-bit address +@rem space, and last the x86-hosted one, emulated in 32 bits, which can run out +@rem of memory on a precompiled header. With none found, the first is used +@set "vctools=" +@if exist "%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" set /p vctools=<"%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" +@set "host=" +@for %%h in (%msvc_host_arch%) do @if not defined host if exist "%InstallDir%\VC\Tools\MSVC\%vctools%\bin\Host%%h\arm64\cl.exe" set "host=%%h" +@if not defined host for /f "tokens=1" %%h in ("%msvc_host_arch%") do @set "host=%%h" +@rem Visual Studio names the x64 host amd64 in its vcvars scripts, and the ARM64 host's own script vcvarsarm64 +@set "vcvars=vcvars%host%_arm64.bat" +@if /i "%host%"=="x64" set "vcvars=vcvarsamd64_arm64.bat" +@if /i "%host%"=="arm64" set "vcvars=vcvarsarm64.bat" @if exist "%HXCPP_MSVC%\..\..\VC\" ( - @if not exist "%hxcpp_msvc%\..\..\VC\Auxiliary\Build\vcvars%vcvars_host%_arm64.bat" ( - @echo Error: the specified MSVC version does not have vcvars%vcvars_host%_arm64.bat setup script + @if not exist "%hxcpp_msvc%\..\..\VC\Auxiliary\Build\%vcvars%" ( + @echo Error: the specified MSVC version does not have %vcvars% setup script ) else ( @echo "%HXCPP_MSVC%" - @call "%HXCPP_MSVC%\..\..\VC\Auxiliary\Build\vcvars%vcvars_host%_arm64.bat" + @call "%HXCPP_MSVC%\..\..\VC\Auxiliary\Build\%vcvars%" @echo HXCPP_VARS @set ) ) else if exist "%vswhere%" ( @if exist "%InstallDir%\Common7\Tools\VsDevCmd.bat" ( - @call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -host_arch=%msvc_host_arch% -arch=arm64 -app_platform=Desktop -no_logo + @call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -host_arch=%host% -arch=arm64 -app_platform=Desktop -no_logo @echo HXCPP_VARS @set ) else ( diff --git a/toolchain/msvc-winrt-arm64-setup.bat b/toolchain/msvc-winrt-arm64-setup.bat index 8f4714a08..d2dcdc0de 100644 --- a/toolchain/msvc-winrt-arm64-setup.bat +++ b/toolchain/msvc-winrt-arm64-setup.bat @@ -2,8 +2,14 @@ setlocal @set "vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" @set InstallDir= @if exist "%vswhere%" for /f "usebackq tokens=*" %%i in (`"%vswhere%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.arm64 -property installationPath`) do @set "InstallDir=%%i" +@rem The first host in msvc_host_arch with a compiler for arm64 installed, as msvc-arm64-setup.bat picks it +@set "vctools=" +@if exist "%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" set /p vctools=<"%InstallDir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" +@set "host=" +@for %%h in (%msvc_host_arch%) do @if not defined host if exist "%InstallDir%\VC\Tools\MSVC\%vctools%\bin\Host%%h\arm64\cl.exe" set "host=%%h" +@if not defined host for /f "tokens=1" %%h in ("%msvc_host_arch%") do @set "host=%%h" @if exist "%InstallDir%\Common7\Tools\VsDevCmd.bat" ( - @call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -host_arch=%msvc_host_arch% -arch=arm64 -app_platform=UWP -no_logo + @call "%InstallDir%\Common7\Tools\VsDevCmd.bat" -host_arch=%host% -arch=arm64 -app_platform=UWP -no_logo @echo HXCPP_VARS @set ) else ( diff --git a/tools/hxcpp/Setup.hx b/tools/hxcpp/Setup.hx index c073cf8e3..acf39c62c 100644 --- a/tools/hxcpp/Setup.hx +++ b/tools/hxcpp/Setup.hx @@ -857,7 +857,11 @@ class Setup Sys.putEnv("HXCPP_WINXP_COMPAT","1"); xpCompat = true; } - Sys.putEnv("msvc_host_arch", ioDefines.exists("windows_arm_host") ? "x86" : "x64" ); + // The hosts of the compilers to use for arm64, best first: the ARM64 + // scripts take the first that is installed. On an ARM64 machine the + // x86-hosted compiler runs emulated in 32 bits, and can run out of + // memory on a precompiled header + Sys.putEnv("msvc_host_arch", ioDefines.exists("windows_arm_host") ? "arm64 x64 x86" : "x64" ); var vc_setup_proc = new Process("cmd.exe", ["/C", BuildTool.HXCPP + "\\toolchain\\msvc" + extra + "-setup.bat" ]); var vars_found = false;