In our build, we are seeing variability in the contents of generated
.swiftmodules, which causes some problems. I would like to figure out what changes to make, either in our setup (if possible), or to the compiler, to ensure reproducible swiftmodules.
Two example cases:
- We have recently started using a remote build cache, and this has stressed the importance reproducible
.swiftmodules for us. The surprise to me was a whitespace-only change resulting in a non-identical swiftmodule (local compared remote cache), which caused all transitive dependencies to be rebuilt. (We have hundreds of modules in the build graphs of our apps.)
- We have two CI jobs (one per app) that populated the cache. These jobs are built using identical code from the same git sha. However, in these two builds we see that modules shared between the two apps can end up with different swiftmodule contents. Whichever job finishes first is the one that populates the cache.
- We use Bazel for our build
- These are debug builds
- Builds are not clean builds (for speed)
The last two facts are what we initially suspect is the cause. Incremental builds from the same git sha can start from different states, depending what the previous build was on that machine.
llvm-bcanalyzer -dump to compare
.swiftmodule contents. In most cases, the stats displayed were the same, seemingly only order of records within blocks looked different. However one case had different stats too, so more than record order issues, there were somehow more or less decls, or something. Does this indicate a deeper problem somewhere? A problem with our build? I'm not sure. I didn't keep the specific swiftmodules files for this one case.
Next, I'll see if I can figure out a reproducible test showing non-reproducible modules. But I wanted to ask the forum for any advice. Is there anything we should log or files to preserve from the build (swiftdeps maybe?) in order to solve this? Are there any tools we can use to compare better? Are there known causes of non-reproducible swiftmodules that we can avoid?