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 8afdc4bbe..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)