Hey :wave:,
So I currently build my aws lambdas using swift on aws codebuild within a CI/CD pipeline. Works great so far. Now I'd like to add caching to codebuild to reduce the build times.
I configured codebuild to use an S3 bucket for caching the .build folder. Every new build runs on a entirely new machine and therefore the paths are different. I get the following error:

swift build --product LambdaName -c release --build-path /codebuild/output/src409372700/src/.build/build-LambdaName
33  [1/863] Compiling CSotoExpat xmltok_impl.c
34  [2/863] Compiling CSotoExpat xmltok_ns.c
35  [3/865] Compiling INIParser INIParser.swift
36  <unknown>:0: error: PCH was compiled with module cache path '.build/build-LambdaName/x86_64-unknown-linux-gnu/release/ModuleCache/1LD7OVICEM9JB', but the path is currently '/codebuild/output/src409372700/src/.build/build-LambdaName/x86_64-unknown-linux-gnu/release/ModuleCache/1LD7OVICEM9JB'
37  <unknown>:0: error: missing required module 'SwiftShims'
38  [4/865] Compiling Logging Locks.swift
39  <unknown>:0: error: PCH was compiled with module cache path '.build/build-LambdaName/x86_64-unknown-linux-gnu/release/ModuleCache/1LD7OVICEM9JB', but the path is currently '/codebuild/output/src409372700/src/.build/build-LambdaName/x86_64-unknown-linux-gnu/release/ModuleCache/1LD7OVICEM9JB'
40  <unknown>:0: error: missing required module 'SwiftShims'
36  <unknown>:0: error: PCH was compiled with module cache path '.build/build-LambdaName/x86_64-unknown-linux-gnu/release/ModuleCache/1LD7OVICEM9JB', but the path is currently '/codebuild/output/src409372700/src/.build/build-LambdaName/x86_64-unknown-linux-gnu/release/ModuleCache/1LD7OVICEM9JB'

All google results on that topic suggest cleaning the derrived data folder of Xcode which is obviously not the case here.
How can I run swift build with changing paths to make use of the cache to reduce build times. Especially when the code did not change much.

Any help us much appreciated!
Thanks!

1 Like

Moved this to 'Using Swift' since it's not about working on the toolchain but about how to use the existing tooling to get the desired behavior.