Skip to content

Commit 562e8fe

Browse files
lorenteyaciidgh
authored andcommitted
[PackageLoading] Make sure JSON-encoded rule keys are stable
JSONEncoder does not guarantee stable element ordering unless the keys are sorted.
1 parent 481c308 commit 562e8fe

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/SPMLLBuild/llbuild.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ private func fromBytes<T: Decodable>(_ bytes: [UInt8]) throws -> T {
197197
}
198198

199199
private func toBytes<T: Encodable>(_ value: T) throws -> [UInt8] {
200-
let encoded = try JSONEncoder().encode(value)
200+
let encoder = JSONEncoder()
201+
#if os(macOS)
202+
if #available(OSX 10.13, *) {
203+
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
204+
}
205+
#else
206+
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
207+
#endif
208+
let encoded = try encoder.encode(value)
201209
return [UInt8](encoded)
202210
}

0 commit comments

Comments
 (0)