spotify / XCRemoteCache

Other
835 stars 52 forks source link

Switch to local PCH headers compilation #95

Closed polac24 closed 2 years ago

polac24 commented 2 years ago

To support PCH (precompilation of C headers) in ObjC headers, this PR always triggers the headers compilation locally. That step should be relatively quick so it will not contribute significantly to the total build time and caching it within Xcode process is not trivial. Xcode, contrary to the compilation processes, compiles .pch files to the project-wide location (by default PrecompiledHeaders/SharedPrecompiledHeaders) with a hashed directory name. It means that from a clang wrapper process (xccc) finding a location where a marker file (discriminator if we should stub the compilation step of compile locally) should adopt a different technique than the ".m" files do - looking for ../../.. of the "-MF" argument is not valid anymore.

As .d file of the compilation step (a file that lists all compilation dependencies) does not refer to the location of the compiled header but just the .pch file within a project, to not overengineer the PCH support, I suggest going with the simples solution and just fallback to the local compilation. In case that will not be enough, we can come up with a more optimized solution later.

Example of the Xcode PCH generation log:

ProcessPCH #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/PrecompiledHeaders/SharedPrecompiledHeaders/14267228059646731042/PrefixHeader.pch.gch #{Home}/#{Project}/DebugPrefix/PrefixHeader.pch normal arm64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'TargetObjCRoot' from project 'DebugPrefix') cd #{Home}/#{Project}/DebugPrefix Precompile of '#{Home}/#{Project}/DebugPrefix/PrefixHeader.pch' required by '#{Home}/#{Project}/DebugPrefix/TargetObjCRoot/TargetObjCRoot.m' /Applications/Xcode-1321.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c-header -target arm64-apple-ios15.2-simulator -fmessage-length\=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit\=0 -std\=gnu11 -fobjc-arc -fobjc-weak -fmodules -fmodules-cache-path\=#{Home}/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval\=86400 -fmodules-prune-after\=345600 -fbuild-session-file\=#{Home}/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror\=non-modular-include-in-framework-module -fmodule-name\=TargetObjCRoot -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror\=return-type -Wdocumentation -Wunreachable-code -Wquoted-include-in-framework-header -Wno-implicit-atomic-properties -Werror\=deprecated-objc-isa-usage -Wno-objc-interface-ivars -Werror\=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -DDEBUG\=1 -DOBJC_OLD_DISPATCH_PROTOTYPES\=0 -isysroot /Applications/Xcode-1321.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wno-semicolon-before-method-body -Wunguarded-availability -fobjc-abi-version\=2 -fobjc-legacy-dispatch -index-store-path #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Index/DataStore -iquote #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/TargetObjCRoot-generated-files.hmap -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/TargetObjCRoot-own-target-headers.hmap -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/TargetObjCRoot-all-non-framework-target-headers.hmap -ivfsoverlay #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/all-product-headers.yaml -iquote #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/TargetObjCRoot-project-headers.hmap -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Products/Debug-iphonesimulator/include -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/DerivedSources-normal/arm64 -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/DerivedSources/arm64 -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/DerivedSources -F#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Products/Debug-iphonesimulator -fdebug-prefix-map\=#{Home}/#{Project}/DebugPrefix\=/xxx -c #{Home}/#{Project}/DebugPrefix/PrefixHeader.pch -MD -MT dependencies -MF #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/PrecompiledHeaders/SharedPrecompiledHeaders/14267228059646731042/PrefixHeader.pch.d -iquote #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/TargetObjCRoot-generated-files.hmap -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/TargetObjCRoot-own-target-headers.hmap -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/TargetObjCRoot-all-non-framework-target-headers.hmap -ivfsoverlay #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/all-product-headers.yaml -iquote #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/TargetObjCRoot-project-headers.hmap -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Products/Debug-iphonesimulator/include -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/DerivedSources-normal/arm64 -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/DerivedSources/arm64 -I#{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/DebugPrefix.build/Debug-iphonesimulator/TargetObjCRoot.build/DerivedSources -o #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/PrecompiledHeaders/SharedPrecompiledHeaders/14267228059646731042/PrefixHeader.pch.gch --serialize-diagnostics #{Home}/Library/Developer/Xcode/DerivedData/DebugPrefix-fqvdsqxngtnuczfkdfgdcbjxvkpy/Build/Intermediates.noindex/PrecompiledHeaders/SharedPrecompiledHeaders/14267228059646731042/PrefixHeader.pch.dia

Fixes #37