Skip to content

Fix five build tool problems shared with stock hxcpp - #495

Open
dimensionscape wants to merge 8 commits into
mainfrom
fix/build-tool-survey
Open

dimensionscape wants to merge 8 commits into
mainfrom
fix/build-tool-survey

Conversation

@dimensionscape

@dimensionscape dimensionscape commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Five build tool problems that libhxcpp shares with stock hxcpp, each fixed our own way in a commit of its own, with a test or CI check and a 6.1.0 Changes.md line.

  • Emscripten ignored the C++ standard (add support for cpp20 HaxeFoundation/hxcpp#1232). The toolchain added --std=c++11 after the build tool's own -std, so HXCPP_CXX_STANDARD, HXCPP_CPP14/17 and cxx_standard did nothing there, and every file, the precompiled header included, built as C++11. The line is gone from the Emscripten and GCW Zero toolchains, and the Emscripten job now builds test/cxx_standard.
  • Objective-C++ ignored the C++ standard (c++ standard flags are ignored by mac toolchain for objective c++ files HaxeFoundation/hxcpp#1250). It defaulted to C++11, and with -D objc, which makes every generated file .mm, so did all of a program's Haxe code. An Objective-C or Objective-C++ standard nobody set now follows the file's C or C++ standard, a file's own cxx_standard or c_standard included. The explicit settings still win. test/cxx_standard has .mm and .m cases, built when the target is macOS or Emscripten.
  • Clang refused a cached precompiled header after a header's date changed (Make clang validate cached PCHs by content and replace #pragma once HaxeFoundation/hxcpp#1466). This happened after a fresh clone, a branch switched and back, or a restored CI cache: the compile cache finds a precompiled header by content, but clang checks dates. A cached precompiled header now keeps the dates of the headers it was made from, and is made again once when one differs, earlier or later. This applies on clang and clang-cl. It needs no header changes and no particular clang version. New check: test/compile_cache/pch_dates.sh.
  • Cache trimming removed what builds still use (Mark compile cache entries as used when they are reused HaxeFoundation/hxcpp#1469). It judged use by access and change times, which reusing an entry changes neither, and Windows does not update access times. Each target now lists in the cache's .used folder what its last build took from the cache: objects compiled, found or reused in place, precompiled header folders, and cached libraries. 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. New check: test/compile_cache/trim.sh.
  • A Windows ARM64 machine used the x86-hosted MSVC ([ci] Add windows arm64 build HaxeFoundation/hxcpp#1400). That compiler runs emulated in 32 bits and can run out of memory on a precompiled header. The ARM64 desktop and WinRT scripts now use the first compiler for arm64 that is installed, in the order ARM64-hosted, x64-hosted, x86-hosted, through VsDevCmd and HXCPP_MSVC_VER alike. There is a new Windows ARM64 job (windows-11-arm, core suites, pushes to main only). setup-haxe's latest release has no Windows arm64 support, so that runner pins the commit that added it, 2158bbde.

Tests:

  • Each new check fails before its fix and passes after it, run locally on Windows x64 with Haxe 4.3.7, MSVC 19.50 and emcc 3.1.74 (clang 20):
    • test/cxx_standard for Emscripten: "Not C++14", "Not C++17" and "Not C17" before.
    • pch_dates.sh: "mtime changed" before.
    • trim.sh: 9 of 9 cache files removed before, 1 now.
    • test/msvc_setup/check.ps1: the new host cases fail against the old script.
  • pch_dates.sh and trim.sh also pass with MSVC. test/emscripten still builds and runs.
  • Not run yet:
    • The Windows ARM64 job has never run, so its first run may turn up other ARM64 problems.
    • Apple clang (macOS) is only covered by CI.
    • That clang-cl checks precompiled header dates is reasoned, not tested: the new step in the clang-cl job will show it.
    • This machine has no compiler for arm64, so check.ps1's real Visual Studio ARM64 case skips here and runs on the ARM64 runner.

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
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
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
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
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
6.0.2 is out, so this branch's five Changes.md lines move from it to a
new 6.0.3 (unreleased) section. haxelib.json still says 6.0.2.
These changes are for 6.1.0, so the five Changes.md lines go under its
heading.
@dimensionscape
dimensionscape marked this pull request as ready for review November 28, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant