Skip to content

Conversation

@artemcm
Copy link
Contributor

@artemcm artemcm commented Nov 12, 2020

When generating build jobs for explicit module dependencies, we must distinguish multiple versions of the same Clang module/pcm by encoding the arguments used to build it (e.g. target triple) into the pcm filename.

So far, we have been using an unstable hash, which means that these filenames were not stable across invocations and were being needlessly re-built in some scenarios (e.g. many-target builds).

Switching to a stable hash (SHA256) ensures that the same Clang module, built with the same command line, will produce the same .pcm filename. This will allow the client build system (e.g. SwiftPM) to deduplicate identical compilation jobs because their output filenames will now also match.

@artemcm
Copy link
Contributor Author

artemcm commented Nov 12, 2020

@swift-ci please test

@artemcm
Copy link
Contributor Author

artemcm commented Nov 12, 2020

😬 Linux build failing with:
Fatal error: not supported on this platform: file TSCBasic/HashAlgorithms.swift, line 189

Comment on lines +454 to +456
if #available(macOS 10.15, iOS 13, *) {
hashedArguments = CryptoKitSHA256().hash(hashInput).hexadecimalRepresentation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is failing on Linux because the true branch of the #available condition is taken. I'm not sure if there's a better way to write this than something like:

#if os(macOS)
if #available(macOS 10.15, iOS 13, *) {
        hashedArguments = CryptoKitSHA256().hash(hashInput).hexadecimalRepresentation
} else {
       hashedArguments = SHA256().hash(hashInput).hexadecimalRepresentation
}
#else 
hashedArguments = SHA256().hash(hashInput).hexadecimalRepresentation
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the wildcard...
I can't think of a better way either.
Thanks, @owenv.

…into PCM filenames

When generating build jobs for explicit module dependencies, we must distinguish multiple versions of the same Clang module/pcm by encoding the arguments used to build it (e.g. target triple) into the pcm filename.

So far, we have been using an unstable hash, which means that these filenames were not stable across invocations and were being needlessly re-built in some scenarios (e.g. many-target builds).

Switching to a stable hash (SHA256 in this instance) ensures that the same Clang module, built with the same command line, will produce the same .pcm filename. This will allow the client build system (such as SwiftPM) to deduplicate identical compilation jobs because their output filenames will now also match.
@artemcm artemcm force-pushed the StablePCMFilenameHash branch from 65bdda6 to 66c1f14 Compare November 13, 2020 17:53
@artemcm
Copy link
Contributor Author

artemcm commented Nov 13, 2020

@swift-ci please test

1 similar comment
@artemcm
Copy link
Contributor Author

artemcm commented Nov 13, 2020

@swift-ci please test

@artemcm
Copy link
Contributor Author

artemcm commented Nov 16, 2020

@swift-ci please test

@artemcm artemcm merged commit 344e49d into swiftlang:main Nov 16, 2020
@artemcm artemcm deleted the StablePCMFilenameHash branch January 20, 2021 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants