From 288f840562df116db30fbbadd18d76803f1c1d31 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 20:47:11 +0000 Subject: [PATCH 1/6] Make clang validate cached precompiled headers by content The compile cache names a PCH directory by a hash of the header contents, so a cached PCH is reused by any checkout whose headers have the same content. clang, however, rejects a PCH when the modification times of its headers differ from those recorded at build time. With a fresh clone of hxcpp, such as on CI with a restored cache, every file of a cached group then fails with "hxcpp.h has been modified since the precompiled header was built". Pass -fpch-validate-input-files-content for cached groups, both when building the PCH and when using it, so that clang compares the content when the modification times differ. The flag is part of the PCH directory hash, so PCHs built without it, which don't record the content, are not reused. GCC and MSVC don't validate timestamps. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Va4FXDQpNU3H6pxTyu2gEb --- tools/hxcpp/Compiler.hx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 8afdc4bbe..93c35d3ce 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -71,6 +71,7 @@ class Compiler //testing... public var useCacheInPlace = true; + static inline var CLANG_PCH_CONTENT_CHECK = "-fpch-validate-input-files-content"; //public var useCacheInPlace = false; public function new(inID,inExe:String) @@ -283,6 +284,8 @@ class Compiler case "gcc": args.unshift("-I"+pchDir); case "clang": + if (inFile.mGroup.isCached()) + args.push(CLANG_PCH_CONTENT_CHECK); args.push("-include-pch"); args.push(pchDir + "/" + inFile.mGroup.getPchName() + mPCHExt); } @@ -594,7 +597,14 @@ class Compiler for(flag in mFlags) flag.add(args,tags); - return args.concat( mCPPFlags ); + args = args.concat( mCPPFlags ); + // A cached PCH is shared by all checkouts whose headers have the same content, but clang + // rejects it when the modification times of those headers differ, e.g. in a fresh clone. + // Make clang compare the content instead. The flag is part of the PCH directory hash, so + // PCHs that were built without it are not reused. + if (mPCH=="clang" && inGroup.isCached()) + args.push(CLANG_PCH_CONTENT_CHECK); + return args; } public function getPchDir(inGroup:FileGroup) From 3ac84d4c52f8836fe235ea5f5b538af93048df1c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 22:49:38 +0000 Subject: [PATCH 2/6] Only pass the PCH content check to clang versions that support it -fpch-validate-input-files-content was added in clang 10, which Apple ships as Apple clang 12. Older toolchains such as Android NDK r21 (clang 9) would fail on the unknown flag, so check the compiler's version string and leave the flag out when it is older or not recognisable. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Va4FXDQpNU3H6pxTyu2gEb --- tools/hxcpp/Compiler.hx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 93c35d3ce..6a89345b3 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -284,7 +284,7 @@ class Compiler case "gcc": args.unshift("-I"+pchDir); case "clang": - if (inFile.mGroup.isCached()) + if (usePchContentCheck(inFile.mGroup)) args.push(CLANG_PCH_CONTENT_CHECK); args.push("-include-pch"); args.push(pchDir + "/" + inFile.mGroup.getPchName() + mPCHExt); @@ -602,11 +602,28 @@ class Compiler // rejects it when the modification times of those headers differ, e.g. in a fresh clone. // Make clang compare the content instead. The flag is part of the PCH directory hash, so // PCHs that were built without it are not reused. - if (mPCH=="clang" && inGroup.isCached()) + if (usePchContentCheck(inGroup)) args.push(CLANG_PCH_CONTENT_CHECK); return args; } + function usePchContentCheck(inGroup:FileGroup) + { + return mPCH=="clang" && inGroup.isCached() && clangSupportsPchContentCheck(); + } + + // -fpch-validate-input-files-content was added in clang 10, which Apple ships as Apple clang 12. + // Without a recognisable version, leave it out. + function clangSupportsPchContentCheck() + { + var version = ~/(Apple )?clang version ([0-9]+)\./; + if (mCompilerVersionString==null || !version.match(mCompilerVersionString)) + return false; + var major = Std.parseInt(version.matched(2)); + var isApple = StringTools.startsWith(version.matched(0), "Apple"); + return major!=null && major >= (isApple ? 12 : 10); + } + public function getPchDir(inGroup:FileGroup) { if (!inGroup.isCached()) From c8aae96a91fb69eea26d0f278c12558bc5a79a5d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 22:57:57 +0000 Subject: [PATCH 3/6] Shorten the comment on the PCH content check Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Va4FXDQpNU3H6pxTyu2gEb --- tools/hxcpp/Compiler.hx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 6a89345b3..85619f55a 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -598,10 +598,7 @@ class Compiler flag.add(args,tags); args = args.concat( mCPPFlags ); - // A cached PCH is shared by all checkouts whose headers have the same content, but clang - // rejects it when the modification times of those headers differ, e.g. in a fresh clone. - // Make clang compare the content instead. The flag is part of the PCH directory hash, so - // PCHs that were built without it are not reused. + // Allow clang to reuse a cached PCH when content matches, even if timestamp differs if (usePchContentCheck(inGroup)) args.push(CLANG_PCH_CONTENT_CHECK); return args; From d3e4166d737967d946bf2d6a9025502752c564f8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 11:18:11 +0000 Subject: [PATCH 4/6] Rebuild a cached clang PCH when its headers are newer instead -fpch-validate-input-files-content makes clang accept a cached PCH whose headers have newer modification times, but clang then no longer treats those headers as already included: a header with #pragma once, such as hx/atomic/AtomicObject.hpp, is included a second time and fails with "redefinition of 'AtomicObject_obj'". This showed up on hxcoro's macOS CI as soon as files were recompiled against a restored PCH. Drop the flag and its version check. When a cached clang PCH is older than one of the group's dependencies, as in a fresh clone, build it again instead. That takes seconds and keeps the cached objects. GCC and MSVC don't check header timestamps, so they keep reusing the PCH as before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Va4FXDQpNU3H6pxTyu2gEb --- tools/hxcpp/Compiler.hx | 42 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 85619f55a..43fa22a17 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -71,7 +71,6 @@ class Compiler //testing... public var useCacheInPlace = true; - static inline var CLANG_PCH_CONTENT_CHECK = "-fpch-validate-input-files-content"; //public var useCacheInPlace = false; public function new(inID,inExe:String) @@ -284,8 +283,6 @@ class Compiler case "gcc": args.unshift("-I"+pchDir); case "clang": - if (usePchContentCheck(inFile.mGroup)) - args.push(CLANG_PCH_CONTENT_CHECK); args.push("-include-pch"); args.push(pchDir + "/" + inFile.mGroup.getPchName() + mPCHExt); } @@ -597,28 +594,7 @@ class Compiler for(flag in mFlags) flag.add(args,tags); - args = args.concat( mCPPFlags ); - // Allow clang to reuse a cached PCH when content matches, even if timestamp differs - if (usePchContentCheck(inGroup)) - args.push(CLANG_PCH_CONTENT_CHECK); - return args; - } - - function usePchContentCheck(inGroup:FileGroup) - { - return mPCH=="clang" && inGroup.isCached() && clangSupportsPchContentCheck(); - } - - // -fpch-validate-input-files-content was added in clang 10, which Apple ships as Apple clang 12. - // Without a recognisable version, leave it out. - function clangSupportsPchContentCheck() - { - var version = ~/(Apple )?clang version ([0-9]+)\./; - if (mCompilerVersionString==null || !version.match(mCompilerVersionString)) - return false; - var major = Std.parseInt(version.matched(2)); - var isApple = StringTools.startsWith(version.matched(0), "Apple"); - return major!=null && major >= (isApple ? 12 : 10); + return args.concat( mCPPFlags ); } public function getPchDir(inGroup:FileGroup) @@ -632,6 +608,20 @@ class Compiler return CompileCache.getPchDir(inGroup.getCacheProject(),md5); } + // clang rejects a PCH when one of its headers is newer than when the PCH was built. A cached + // PCH can come from another checkout with the same header contents, e.g. a fresh clone on CI + // with a restored cache, so build it again in that case. + function isClangPchOutOfDate(inGroup:FileGroup, inPchName:String) + { + if (mPCH!="clang") + return false; + var pchStamp = FileSystem.stat(inPchName).mtime.getTime(); + for(depend in inGroup.mCacheDepends) + if (FileSystem.stat(depend).mtime.getTime() > pchStamp) + return true; + return false; + } + public function precompile(inGroup:FileGroup, inReuseIfPossible:Bool) { // header will be like "hxcpp" or "wx/wx" @@ -650,7 +640,7 @@ class Compiler { // 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)) ) + if (FileSystem.exists(pch_name) && (obj==null || FileSystem.exists(obj)) && !isClangPchOutOfDate(inGroup, pch_name)) return obj; } From a297477b3e4f0144d0f936e4e6339f2f96bc2624 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 12:22:03 +0000 Subject: [PATCH 5/6] Only compare a cached clang PCH with its own header The group's dependencies can include files that the PCH doesn't read, so checking all of them could rebuild a PCH that was fine to reuse. A fresh clone updates the modification time of the precompiled header too, which is the case that needs a rebuild. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Va4FXDQpNU3H6pxTyu2gEb --- tools/hxcpp/Compiler.hx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index 43fa22a17..eedadcb1f 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -610,16 +610,14 @@ class Compiler // clang rejects a PCH when one of its headers is newer than when the PCH was built. A cached // PCH can come from another checkout with the same header contents, e.g. a fresh clone on CI - // with a restored cache, so build it again in that case. + // with a restored cache, so build it again when the precompiled header itself is newer. function isClangPchOutOfDate(inGroup:FileGroup, inPchName:String) { if (mPCH!="clang") return false; - var pchStamp = FileSystem.stat(inPchName).mtime.getTime(); - for(depend in inGroup.mCacheDepends) - if (FileSystem.stat(depend).mtime.getTime() > pchStamp) - return true; - return false; + var header = inGroup.mPrecompiledHeaderDir + "/" + inGroup.mPrecompiledHeader + ".h"; + return FileSystem.exists(header) && + FileSystem.stat(header).mtime.getTime() > FileSystem.stat(inPchName).mtime.getTime(); } public function precompile(inGroup:FileGroup, inReuseIfPossible:Bool) From c4a90d4302dbe12775a99d92f4b145860395f561 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 12:04:02 +0000 Subject: [PATCH 6/6] Go back to the PCH content check and replace #pragma once With -fpch-validate-input-files-content, clang reuses a cached PCH whose headers have newer modification times, but then includes headers that use #pragma once a second time (llvm/llvm-project#239569). That is what failed on hxcoro's macOS CI with "redefinition of 'AtomicObject_obj'". Include guards don't have the problem, so convert the 35 headers in include, src and test that use #pragma once to include guards named after their path, as the other headers are, and restore the content check from c8aae96 instead of rebuilding the PCH when hxcpp.h is newer. The new "Check for pragma once" step in the header check job keeps #pragma once out of include, src and test. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Va4FXDQpNU3H6pxTyu2gEb --- .github/workflows/main.yml | 6 +++ include/cpp/encoding/Ascii.hpp | 7 +++- include/cpp/encoding/Utf16.hpp | 5 ++- include/cpp/encoding/Utf8.hpp | 5 ++- include/cpp/marshal/Boxed.hpp | 7 +++- include/cpp/marshal/Definitions.inc | 5 ++- include/cpp/marshal/Marshal.hpp | 7 +++- include/cpp/marshal/PointerReference.hpp | 7 +++- include/cpp/marshal/PointerType.hpp | 7 +++- include/cpp/marshal/RootHandle.hpp | 7 +++- include/cpp/marshal/ValueReference.hpp | 7 +++- include/cpp/marshal/ValueType.hpp | 7 +++- include/cpp/marshal/View.hpp | 5 ++- include/hx/atomic/AtomicInt.hpp | 7 +++- include/hx/atomic/AtomicObject.hpp | 7 +++- include/hx/thread/ConditionVariable.hpp | 7 +++- include/hx/thread/CountingSemaphore.hpp | 7 +++- include/hx/thread/RecursiveMutex.hpp | 7 +++- include/hx/thread/Scratch.hpp | 7 +++- include/hx/thread/Thread.hpp | 7 +++- include/hx/thread/ThreadLocal.hpp | 7 +++- include/hx/zip/Compress.hpp | 5 ++- include/hx/zip/Uncompress.hpp | 5 ++- include/hx/zip/Zip.hpp | 5 ++- src/hx/thread/ThreadImpl.hpp | 5 ++- src/hx/zip/zlib/ZLibCompress.hpp | 7 +++- src/hx/zip/zlib/ZLibUncompress.hpp | 5 ++- test/native/tests/marshalling/native/Base.hpp | 7 +++- .../native/tests/marshalling/native/Child.hpp | 7 +++- .../tests/marshalling/native/Managed.hpp | 7 +++- .../tests/marshalling/native/Numbers.hpp | 7 +++- .../tests/marshalling/native/Opaque.hpp | 7 +++- .../tests/marshalling/native/colour.hpp | 7 +++- test/native/tests/marshalling/native/ctx.hpp | 7 +++- .../tests/marshalling/native/holder.hpp | 7 +++- .../native/tests/marshalling/native/point.hpp | 7 +++- tools/hxcpp/Compiler.hx | 40 ++++++++++++------- 37 files changed, 198 insertions(+), 75 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index afb8e5e27..2ab783aec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,6 +25,12 @@ jobs: include name: Check public headers + - run: | + # clang loses track of #pragma once headers when it reuses a cached PCH whose headers have + # newer modification times (llvm/llvm-project#239569), so use include guards instead + ! grep --recursive --line-number --extended-regexp '^\s*#\s*pragma\s+once' include src test + name: Check for pragma once + Test: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository strategy: diff --git a/include/cpp/encoding/Ascii.hpp b/include/cpp/encoding/Ascii.hpp index 0d89fa63c..c84f0f2c5 100644 --- a/include/cpp/encoding/Ascii.hpp +++ b/include/cpp/encoding/Ascii.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_ENCODING_ASCII_HPP +#define CPP_ENCODING_ASCII_HPP namespace cpp { @@ -21,4 +22,6 @@ namespace cpp static String decode(cpp::marshal::View string); }; } -} \ No newline at end of file +} + +#endif diff --git a/include/cpp/encoding/Utf16.hpp b/include/cpp/encoding/Utf16.hpp index 6d851e14f..38ef7b6da 100644 --- a/include/cpp/encoding/Utf16.hpp +++ b/include/cpp/encoding/Utf16.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_ENCODING_UTF16_HPP +#define CPP_ENCODING_UTF16_HPP namespace cpp { @@ -25,3 +26,5 @@ namespace cpp }; } } + +#endif diff --git a/include/cpp/encoding/Utf8.hpp b/include/cpp/encoding/Utf8.hpp index 3ff12ba4b..203160133 100644 --- a/include/cpp/encoding/Utf8.hpp +++ b/include/cpp/encoding/Utf8.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_ENCODING_UTF8_HPP +#define CPP_ENCODING_UTF8_HPP namespace cpp { @@ -24,3 +25,5 @@ namespace cpp }; } } + +#endif diff --git a/include/cpp/marshal/Boxed.hpp b/include/cpp/marshal/Boxed.hpp index b92556609..8224ffa40 100644 --- a/include/cpp/marshal/Boxed.hpp +++ b/include/cpp/marshal/Boxed.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_MARSHAL_BOXED_HPP +#define CPP_MARSHAL_BOXED_HPP #include "Definitions.inc" @@ -36,4 +37,6 @@ template inline cpp::marshal::Boxed_obj::Boxed_obj(TArgs... args) : value(std::forward(args)...) { setFinaliser(std::is_destructible{}); -} \ No newline at end of file +} + +#endif diff --git a/include/cpp/marshal/Definitions.inc b/include/cpp/marshal/Definitions.inc index efeacce20..93c520567 100644 --- a/include/cpp/marshal/Definitions.inc +++ b/include/cpp/marshal/Definitions.inc @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_MARSHAL_DEFINITIONS_INC +#define CPP_MARSHAL_DEFINITIONS_INC #include @@ -304,3 +305,5 @@ inline cpp::Pointer::Pointer(const ::cpp::marshal::PointerReference ref) { ptr = *ref.ptr; } + +#endif diff --git a/include/cpp/marshal/Marshal.hpp b/include/cpp/marshal/Marshal.hpp index 6b69796a3..60d3b7a24 100644 --- a/include/cpp/marshal/Marshal.hpp +++ b/include/cpp/marshal/Marshal.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_MARSHAL_MARSHAL_HPP +#define CPP_MARSHAL_MARSHAL_HPP #include "Definitions.inc" #include @@ -518,4 +519,6 @@ inline void cpp::marshal::Marshal::writeBigEndianFloat64(const View& vi #else writeFloat64(view, value); #endif -} \ No newline at end of file +} + +#endif diff --git a/include/cpp/marshal/PointerReference.hpp b/include/cpp/marshal/PointerReference.hpp index f007abadd..3f348c6c6 100644 --- a/include/cpp/marshal/PointerReference.hpp +++ b/include/cpp/marshal/PointerReference.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_MARSHAL_POINTERREFERENCE_HPP +#define CPP_MARSHAL_POINTERREFERENCE_HPP #include "Definitions.inc" @@ -167,4 +168,6 @@ inline T* cpp::marshal::PointerReference::operator->() const } return *Super::ptr; -} \ No newline at end of file +} + +#endif diff --git a/include/cpp/marshal/PointerType.hpp b/include/cpp/marshal/PointerType.hpp index 7d75c1cf1..c3f4de735 100644 --- a/include/cpp/marshal/PointerType.hpp +++ b/include/cpp/marshal/PointerType.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_MARSHAL_POINTERTYPE_HPP +#define CPP_MARSHAL_POINTERTYPE_HPP #include "Definitions.inc" @@ -65,4 +66,6 @@ inline cpp::marshal::PointerType& cpp::marshal::PointerType::operator=(con value = nullptr; return *this; -} \ No newline at end of file +} + +#endif diff --git a/include/cpp/marshal/RootHandle.hpp b/include/cpp/marshal/RootHandle.hpp index fcdeb83e2..81e048177 100644 --- a/include/cpp/marshal/RootHandle.hpp +++ b/include/cpp/marshal/RootHandle.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_MARSHAL_ROOTHANDLE_HPP +#define CPP_MARSHAL_ROOTHANDLE_HPP #include "Definitions.inc" @@ -43,4 +44,6 @@ inline ::Dynamic cpp::marshal::RootHandle::getObject() inline cpp::Pointer cpp::marshal::RootHandle::toVoidPointer() { return object; -} \ No newline at end of file +} + +#endif diff --git a/include/cpp/marshal/ValueReference.hpp b/include/cpp/marshal/ValueReference.hpp index 53c2cf394..783e06db3 100644 --- a/include/cpp/marshal/ValueReference.hpp +++ b/include/cpp/marshal/ValueReference.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_MARSHAL_VALUEREFERENCE_HPP +#define CPP_MARSHAL_VALUEREFERENCE_HPP #include "Definitions.inc" @@ -137,4 +138,6 @@ inline T cpp::marshal::ValueReference::operator*() const } return *Super::ptr; -} \ No newline at end of file +} + +#endif diff --git a/include/cpp/marshal/ValueType.hpp b/include/cpp/marshal/ValueType.hpp index 70e530939..3352eefdb 100644 --- a/include/cpp/marshal/ValueType.hpp +++ b/include/cpp/marshal/ValueType.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_MARSHAL_VALUETYPE_HPP +#define CPP_MARSHAL_VALUETYPE_HPP #include "Definitions.inc" @@ -71,4 +72,6 @@ inline cpp::marshal::ValueType& cpp::marshal::ValueType::operator=(const n ::hx::NullReference("ValueType", true); return *this; -} \ No newline at end of file +} + +#endif diff --git a/include/cpp/marshal/View.hpp b/include/cpp/marshal/View.hpp index 6c06e6b84..981184d4d 100644 --- a/include/cpp/marshal/View.hpp +++ b/include/cpp/marshal/View.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef CPP_MARSHAL_VIEW_HPP +#define CPP_MARSHAL_VIEW_HPP #include #include @@ -165,3 +166,5 @@ inline T& cpp::marshal::View::operator[](int64_t index) const return ptr.ptr[index]; } + +#endif diff --git a/include/hx/atomic/AtomicInt.hpp b/include/hx/atomic/AtomicInt.hpp index f022c5321..7999bb071 100644 --- a/include/hx/atomic/AtomicInt.hpp +++ b/include/hx/atomic/AtomicInt.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_ATOMIC_ATOMICINT_HPP +#define HX_ATOMIC_ATOMICINT_HPP #ifndef HXCPP_H #include @@ -30,4 +31,6 @@ namespace hx Impl* impl; }; } -} \ No newline at end of file +} + +#endif diff --git a/include/hx/atomic/AtomicObject.hpp b/include/hx/atomic/AtomicObject.hpp index 50b864303..d5b796366 100644 --- a/include/hx/atomic/AtomicObject.hpp +++ b/include/hx/atomic/AtomicObject.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_ATOMIC_ATOMICOBJECT_HPP +#define HX_ATOMIC_ATOMICOBJECT_HPP #ifndef HXCPP_H #include @@ -30,4 +31,6 @@ namespace hx Impl* impl; }; } -} \ No newline at end of file +} + +#endif diff --git a/include/hx/thread/ConditionVariable.hpp b/include/hx/thread/ConditionVariable.hpp index d78937803..c27535a69 100644 --- a/include/hx/thread/ConditionVariable.hpp +++ b/include/hx/thread/ConditionVariable.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_THREAD_CONDITIONVARIABLE_HPP +#define HX_THREAD_CONDITIONVARIABLE_HPP #ifndef HXCPP_H #include @@ -28,4 +29,6 @@ namespace hx Impl* impl; }; } -} \ No newline at end of file +} + +#endif diff --git a/include/hx/thread/CountingSemaphore.hpp b/include/hx/thread/CountingSemaphore.hpp index 34deb5545..6d1891b12 100644 --- a/include/hx/thread/CountingSemaphore.hpp +++ b/include/hx/thread/CountingSemaphore.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_THREAD_COUNTINGSEMAPHORE_HPP +#define HX_THREAD_COUNTINGSEMAPHORE_HPP #ifndef HXCPP_H #include @@ -24,4 +25,6 @@ namespace hx Impl* impl; }; } -} \ No newline at end of file +} + +#endif diff --git a/include/hx/thread/RecursiveMutex.hpp b/include/hx/thread/RecursiveMutex.hpp index f2bac5c97..6e23a1703 100644 --- a/include/hx/thread/RecursiveMutex.hpp +++ b/include/hx/thread/RecursiveMutex.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_THREAD_RECURSIVEMUTEX_HPP +#define HX_THREAD_RECURSIVEMUTEX_HPP #ifndef HXCPP_H #include @@ -24,4 +25,6 @@ namespace hx Impl* impl; }; } -} \ No newline at end of file +} + +#endif diff --git a/include/hx/thread/Scratch.hpp b/include/hx/thread/Scratch.hpp index 946eada32..435470e2e 100644 --- a/include/hx/thread/Scratch.hpp +++ b/include/hx/thread/Scratch.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_THREAD_SCRATCH_HPP +#define HX_THREAD_SCRATCH_HPP #ifndef HXCPP_H #include @@ -30,4 +31,6 @@ namespace hx Scratch& operator=(const Scratch& other); }; } -} \ No newline at end of file +} + +#endif diff --git a/include/hx/thread/Thread.hpp b/include/hx/thread/Thread.hpp index ee857bd2a..f173f6719 100644 --- a/include/hx/thread/Thread.hpp +++ b/include/hx/thread/Thread.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_THREAD_THREAD_HPP +#define HX_THREAD_THREAD_HPP #ifndef HXCPP_H #include @@ -27,4 +28,6 @@ namespace hx virtual void setName(const String& name) = 0; }; } -} \ No newline at end of file +} + +#endif diff --git a/include/hx/thread/ThreadLocal.hpp b/include/hx/thread/ThreadLocal.hpp index 15ad7d6ba..c3b5ce26f 100644 --- a/include/hx/thread/ThreadLocal.hpp +++ b/include/hx/thread/ThreadLocal.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_THREAD_THREADLOCAL_HPP +#define HX_THREAD_THREADLOCAL_HPP #ifndef HXCPP_H #include @@ -25,4 +26,6 @@ namespace hx void set(Dynamic obj); }; } -} \ No newline at end of file +} + +#endif diff --git a/include/hx/zip/Compress.hpp b/include/hx/zip/Compress.hpp index 85a9ef8f3..c3e0e141f 100644 --- a/include/hx/zip/Compress.hpp +++ b/include/hx/zip/Compress.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_ZIP_COMPRESS_HPP +#define HX_ZIP_COMPRESS_HPP #include "Zip.hpp" @@ -17,3 +18,5 @@ namespace hx }; } } + +#endif diff --git a/include/hx/zip/Uncompress.hpp b/include/hx/zip/Uncompress.hpp index 2a67827d2..5ea63136b 100644 --- a/include/hx/zip/Uncompress.hpp +++ b/include/hx/zip/Uncompress.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_ZIP_UNCOMPRESS_HPP +#define HX_ZIP_UNCOMPRESS_HPP #include "Zip.hpp" @@ -15,3 +16,5 @@ namespace hx }; } } + +#endif diff --git a/include/hx/zip/Zip.hpp b/include/hx/zip/Zip.hpp index c5e7321c4..e8f2d697b 100644 --- a/include/hx/zip/Zip.hpp +++ b/include/hx/zip/Zip.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_ZIP_ZIP_HPP +#define HX_ZIP_ZIP_HPP #ifndef HXCPP_H #include @@ -36,3 +37,5 @@ namespace hx }; } } + +#endif diff --git a/src/hx/thread/ThreadImpl.hpp b/src/hx/thread/ThreadImpl.hpp index 767f84be7..6d2bed377 100644 --- a/src/hx/thread/ThreadImpl.hpp +++ b/src/hx/thread/ThreadImpl.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_THREAD_THREADIMPL_HPP +#define HX_THREAD_THREADIMPL_HPP #ifndef HXCPP_H #include @@ -58,3 +59,5 @@ namespace hx }; } } + +#endif diff --git a/src/hx/zip/zlib/ZLibCompress.hpp b/src/hx/zip/zlib/ZLibCompress.hpp index a77361826..3d0588ea5 100644 --- a/src/hx/zip/zlib/ZLibCompress.hpp +++ b/src/hx/zip/zlib/ZLibCompress.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_ZIP_ZLIB_ZLIBCOMPRESS_HPP +#define HX_ZIP_ZLIB_ZLIBCOMPRESS_HPP #include #include @@ -24,4 +25,6 @@ namespace hx }; } } -} \ No newline at end of file +} + +#endif diff --git a/src/hx/zip/zlib/ZLibUncompress.hpp b/src/hx/zip/zlib/ZLibUncompress.hpp index 65f51d557..1c3ffce12 100644 --- a/src/hx/zip/zlib/ZLibUncompress.hpp +++ b/src/hx/zip/zlib/ZLibUncompress.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef HX_ZIP_ZLIB_ZLIBUNCOMPRESS_HPP +#define HX_ZIP_ZLIB_ZLIBUNCOMPRESS_HPP #include #include @@ -24,3 +25,5 @@ namespace hx } } } + +#endif diff --git a/test/native/tests/marshalling/native/Base.hpp b/test/native/tests/marshalling/native/Base.hpp index 6aaa091dc..1c31a3b7d 100644 --- a/test/native/tests/marshalling/native/Base.hpp +++ b/test/native/tests/marshalling/native/Base.hpp @@ -1,5 +1,8 @@ -#pragma once +#ifndef MARSHALLING_NATIVE_BASE_HPP +#define MARSHALLING_NATIVE_BASE_HPP struct Base { virtual int foo(); -}; \ No newline at end of file +}; + +#endif diff --git a/test/native/tests/marshalling/native/Child.hpp b/test/native/tests/marshalling/native/Child.hpp index 8142518b3..4faf30758 100644 --- a/test/native/tests/marshalling/native/Child.hpp +++ b/test/native/tests/marshalling/native/Child.hpp @@ -1,8 +1,11 @@ -#pragma once +#ifndef MARSHALLING_NATIVE_CHILD_HPP +#define MARSHALLING_NATIVE_CHILD_HPP #include struct Child : public Base { int foo() override; int bar(); -}; \ No newline at end of file +}; + +#endif diff --git a/test/native/tests/marshalling/native/Managed.hpp b/test/native/tests/marshalling/native/Managed.hpp index a7a2886f2..3f189dae1 100644 --- a/test/native/tests/marshalling/native/Managed.hpp +++ b/test/native/tests/marshalling/native/Managed.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef MARSHALLING_NATIVE_MANAGED_HPP +#define MARSHALLING_NATIVE_MANAGED_HPP HX_DECLARE_CLASS2(foo,bar,standard_naming) @@ -27,4 +28,6 @@ namespace foo ::Dynamic ReturnSeven_dyn(); }; -} \ No newline at end of file +} + +#endif diff --git a/test/native/tests/marshalling/native/Numbers.hpp b/test/native/tests/marshalling/native/Numbers.hpp index ec2f68d77..cfce86b05 100644 --- a/test/native/tests/marshalling/native/Numbers.hpp +++ b/test/native/tests/marshalling/native/Numbers.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef MARSHALLING_NATIVE_NUMBERS_HPP +#define MARSHALLING_NATIVE_NUMBERS_HPP namespace foo { @@ -7,4 +8,6 @@ namespace foo Two = 5, Three }; -} \ No newline at end of file +} + +#endif diff --git a/test/native/tests/marshalling/native/Opaque.hpp b/test/native/tests/marshalling/native/Opaque.hpp index 535313fb2..380cc55b3 100644 --- a/test/native/tests/marshalling/native/Opaque.hpp +++ b/test/native/tests/marshalling/native/Opaque.hpp @@ -1,5 +1,8 @@ -#pragma once +#ifndef MARSHALLING_NATIVE_OPAQUE_HPP +#define MARSHALLING_NATIVE_OPAQUE_HPP struct Opaque; -Opaque* opaque_create(); \ No newline at end of file +Opaque* opaque_create(); + +#endif diff --git a/test/native/tests/marshalling/native/colour.hpp b/test/native/tests/marshalling/native/colour.hpp index 36b175950..47c5ee25c 100644 --- a/test/native/tests/marshalling/native/colour.hpp +++ b/test/native/tests/marshalling/native/colour.hpp @@ -1,7 +1,10 @@ -#pragma once +#ifndef MARSHALLING_NATIVE_COLOUR_HPP +#define MARSHALLING_NATIVE_COLOUR_HPP enum colour { red, green, blue -}; \ No newline at end of file +}; + +#endif diff --git a/test/native/tests/marshalling/native/ctx.hpp b/test/native/tests/marshalling/native/ctx.hpp index 089460d37..182a36335 100644 --- a/test/native/tests/marshalling/native/ctx.hpp +++ b/test/native/tests/marshalling/native/ctx.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef MARSHALLING_NATIVE_CTX_HPP +#define MARSHALLING_NATIVE_CTX_HPP struct ctx { int number; @@ -14,4 +15,6 @@ struct ctx { void ctx_ptr(ctx* pCtx); void ctx_ptr_ptr(ctx** ppCtx); void ctx_void_ptr(void* pCtx); -void ctx_void_ptr_ptr(void** ppCtx); \ No newline at end of file +void ctx_void_ptr_ptr(void** ppCtx); + +#endif diff --git a/test/native/tests/marshalling/native/holder.hpp b/test/native/tests/marshalling/native/holder.hpp index 60123b757..72d9367d9 100644 --- a/test/native/tests/marshalling/native/holder.hpp +++ b/test/native/tests/marshalling/native/holder.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef MARSHALLING_NATIVE_HOLDER_HPP +#define MARSHALLING_NATIVE_HOLDER_HPP #include @@ -16,4 +17,6 @@ class holder { ::hx::maths::point create(); ::hx::maths::point* get_static(); -}; \ No newline at end of file +}; + +#endif diff --git a/test/native/tests/marshalling/native/point.hpp b/test/native/tests/marshalling/native/point.hpp index 1feb3366d..e867bd08b 100644 --- a/test/native/tests/marshalling/native/point.hpp +++ b/test/native/tests/marshalling/native/point.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef MARSHALLING_NATIVE_POINT_HPP +#define MARSHALLING_NATIVE_POINT_HPP #include namespace hx { @@ -13,4 +14,6 @@ namespace hx { static void point_vec(::std::vector<::hx::maths::point>& v); }; } -} \ No newline at end of file +} + +#endif diff --git a/tools/hxcpp/Compiler.hx b/tools/hxcpp/Compiler.hx index eedadcb1f..85619f55a 100644 --- a/tools/hxcpp/Compiler.hx +++ b/tools/hxcpp/Compiler.hx @@ -71,6 +71,7 @@ class Compiler //testing... public var useCacheInPlace = true; + static inline var CLANG_PCH_CONTENT_CHECK = "-fpch-validate-input-files-content"; //public var useCacheInPlace = false; public function new(inID,inExe:String) @@ -283,6 +284,8 @@ class Compiler case "gcc": args.unshift("-I"+pchDir); case "clang": + if (usePchContentCheck(inFile.mGroup)) + args.push(CLANG_PCH_CONTENT_CHECK); args.push("-include-pch"); args.push(pchDir + "/" + inFile.mGroup.getPchName() + mPCHExt); } @@ -594,7 +597,28 @@ class Compiler for(flag in mFlags) flag.add(args,tags); - return args.concat( mCPPFlags ); + args = args.concat( mCPPFlags ); + // Allow clang to reuse a cached PCH when content matches, even if timestamp differs + if (usePchContentCheck(inGroup)) + args.push(CLANG_PCH_CONTENT_CHECK); + return args; + } + + function usePchContentCheck(inGroup:FileGroup) + { + return mPCH=="clang" && inGroup.isCached() && clangSupportsPchContentCheck(); + } + + // -fpch-validate-input-files-content was added in clang 10, which Apple ships as Apple clang 12. + // Without a recognisable version, leave it out. + function clangSupportsPchContentCheck() + { + var version = ~/(Apple )?clang version ([0-9]+)\./; + if (mCompilerVersionString==null || !version.match(mCompilerVersionString)) + return false; + var major = Std.parseInt(version.matched(2)); + var isApple = StringTools.startsWith(version.matched(0), "Apple"); + return major!=null && major >= (isApple ? 12 : 10); } public function getPchDir(inGroup:FileGroup) @@ -608,18 +632,6 @@ class Compiler return CompileCache.getPchDir(inGroup.getCacheProject(),md5); } - // clang rejects a PCH when one of its headers is newer than when the PCH was built. A cached - // PCH can come from another checkout with the same header contents, e.g. a fresh clone on CI - // with a restored cache, so build it again when the precompiled header itself is newer. - function isClangPchOutOfDate(inGroup:FileGroup, inPchName:String) - { - if (mPCH!="clang") - return false; - var header = inGroup.mPrecompiledHeaderDir + "/" + inGroup.mPrecompiledHeader + ".h"; - return FileSystem.exists(header) && - FileSystem.stat(header).mtime.getTime() > FileSystem.stat(inPchName).mtime.getTime(); - } - public function precompile(inGroup:FileGroup, inReuseIfPossible:Bool) { // header will be like "hxcpp" or "wx/wx" @@ -638,7 +650,7 @@ class Compiler { // 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)) && !isClangPchOutOfDate(inGroup, pch_name)) + if (FileSystem.exists(pch_name) && (obj==null || FileSystem.exists(obj)) ) return obj; }