Skip to content

Commit fbf68cc

Browse files
authoredOct 9, 2024··
Fix WASI build issue (#142)
* Fix WASI build issue * Fix PropertyListEncoder and BitwiseCopyable on WASI
1 parent cc6524d commit fbf68cc

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
 

‎Sources/OpenSwiftUICore/Data/Protobuf/ProtobufEncoder.swift

+18
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,14 @@ extension ProtobufEncoder {
291291
}
292292

293293
func binaryPlistData<T>(for value: T) throws -> Data where T: Encodable {
294+
#if os(WASI)
295+
fatalError("PropertyListEncoder is not avaiable on WASI")
296+
#else
294297
let encoder = PropertyListEncoder()
295298
encoder.outputFormat = .binary
296299
encoder.userInfo = userInfo
297300
return try encoder.encode([value])
301+
#endif
298302
}
299303

300304
@inline(__always)
@@ -467,6 +471,7 @@ extension ProtobufEncoder {
467471
encodeVarintZZ(Int(value))
468472
}
469473

474+
#if compiler(>=6.0)
470475
@inline(__always)
471476
private mutating func encodeBitwiseCopyable<T>(_ value: T) where T: BitwiseCopyable {
472477
let oldSize = size
@@ -478,6 +483,19 @@ extension ProtobufEncoder {
478483
buffer.advanced(by: oldSize).storeBytes(of: value, as: T.self)
479484
}
480485
}
486+
#else // FIXME: Remove this after we drop WASI 5.10 support
487+
@inline(__always)
488+
private mutating func encodeBitwiseCopyable<T>(_ value: T) {
489+
let oldSize = size
490+
let newSize = oldSize + MemoryLayout<T>.size
491+
if capacity < newSize {
492+
growBufferSlow(to: newSize).storeBytes(of: value, as: T.self)
493+
} else {
494+
size = newSize
495+
buffer.advanced(by: oldSize).storeBytes(of: value, as: T.self)
496+
}
497+
}
498+
#endif
481499

482500
package mutating func encodeBool(_ value: Bool) {
483501
encodeBitwiseCopyable(value)

‎Sources/OpenSwiftUICore/Util/UnsafePointer+Extension.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension UnsafePointer {
1515

1616
@_transparent
1717
package static var null: UnsafePointer<Pointee> {
18-
UnsafePointer(bitPattern: Int(bitPattern: 0xffff_ffff_ffff_ff00) | (-MemoryLayout<Pointee>.alignment))!
18+
UnsafePointer(bitPattern: Int(bitPattern: UInt.max - 0xff) | (-MemoryLayout<Pointee>.alignment))!
1919
}
2020
}
2121

@@ -29,7 +29,7 @@ extension UnsafeMutablePointer {
2929

3030
@_transparent
3131
package static var null: UnsafeMutablePointer<Pointee> {
32-
UnsafeMutablePointer(bitPattern: Int(bitPattern: 0xffff_ffff_ffff_ff00) | (-MemoryLayout<Pointee>.alignment))!
32+
UnsafeMutablePointer(bitPattern: Int(bitPattern: UInt.max - 0xff) | (-MemoryLayout<Pointee>.alignment))!
3333
}
3434
}
3535

0 commit comments

Comments
 (0)
Please sign in to comment.