Skip to content

Commit 7c8c5f9

Browse files
committed
[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 7c8c5f9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/SPMLLBuild/llbuild.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ 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+
encoder.outputFormatting = [.sortedKeys]
202+
let encoded = try encoder.encode(value)
201203
return [UInt8](encoded)
202204
}

0 commit comments

Comments
 (0)