Skip to content

Commit f77911a

Browse files
[wasm] Fix WASI build around TimeZone (#984)
#975 started to restrict the fallback value for `TZDIR` and it revealed that WASI platform implicitly depends on TZDIR even though it won't have such directory. This patch explicitly handles the case for WASI platform for timezone operations.
1 parent 595b06e commit f77911a

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Sources/FoundationEssentials/TimeZone/TimeZone.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ extension TimeZone {
390390

391391
extension TimeZone {
392392
internal static func dataFromTZFile(_ name: String) -> Data {
393-
#if NO_TZFILE || os(Windows)
393+
#if NO_TZFILE || os(Windows) || os(WASI)
394394
return Data()
395395
#else
396396
let path = TZDIR + "/" + name

Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ struct TimeZoneCache : Sendable, ~Copyable {
131131
return TimeZone(inner: result)
132132
}
133133
}
134+
#elseif os(WASI)
135+
// WASI doesn't provide a way to get the current timezone for now, so
136+
// just return the default GMT timezone.
134137
#else
135138
let buffer = UnsafeMutableBufferPointer<CChar>.allocate(capacity: Int(PATH_MAX + 1))
136139
defer { buffer.deallocate() }

0 commit comments

Comments
 (0)