Are you talking about incremental compilation in general (which should just work) or incremental compilation in ephemeral Docker containers? The latter was -- until recently -- a little bit harder because of an implementation detail in Docker which gives folders that get mapped into containers fresh inode numbers which invalidates the build cache.
If you're talking about Docker, the key to making it work is
RUN --mount=type=cache,target=/code/.build swift build -c release
The --mount=type=cache,target=/code/.build
will put SwiftPM's .build
folder into a cache volume which retains inode numbers, mtimes and everything else. With that, incremental compilation will just work