|
| 1 | +From 904db472e5db7bf77aed8f36f84f761fbd471cda Mon Sep 17 00:00:00 2001 |
| 2 | +From: Yuta Saito < [email protected]> |
| 3 | +Date: Wed, 16 Oct 2024 05:12:44 +0000 |
| 4 | +Subject: [PATCH] [wasm] Fix WASI build around TimeZone |
| 5 | + |
| 6 | +https://github.com/swiftlang/swift-foundation/pull/975 started to |
| 7 | +restrict the fallback value for `TZDIR` and it revealed that WASI |
| 8 | +platform implicitly depends on TZDIR even though it won't have such |
| 9 | +directory. This patch explicitly handles the case for WASI platform for |
| 10 | +timezone operations. |
| 11 | +--- |
| 12 | + Sources/FoundationEssentials/TimeZone/TimeZone.swift | 2 +- |
| 13 | + Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift | 3 +++ |
| 14 | + 2 files changed, 4 insertions(+), 1 deletion(-) |
| 15 | + |
| 16 | +diff --git a/Sources/FoundationEssentials/TimeZone/TimeZone.swift b/Sources/FoundationEssentials/TimeZone/TimeZone.swift |
| 17 | +index 9be9de09..fa26a8c7 100644 |
| 18 | +--- a/Sources/FoundationEssentials/TimeZone/TimeZone.swift |
| 19 | ++++ b/Sources/FoundationEssentials/TimeZone/TimeZone.swift |
| 20 | +@@ -390,7 +390,7 @@ extension TimeZone { |
| 21 | + |
| 22 | + extension TimeZone { |
| 23 | + internal static func dataFromTZFile(_ name: String) -> Data { |
| 24 | +-#if NO_TZFILE || os(Windows) |
| 25 | ++#if NO_TZFILE || os(Windows) || os(WASI) |
| 26 | + return Data() |
| 27 | + #else |
| 28 | + let path = TZDIR + "/" + name |
| 29 | +diff --git a/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift b/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift |
| 30 | +index b4c84d71..ccbb69aa 100644 |
| 31 | +--- a/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift |
| 32 | ++++ b/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift |
| 33 | +@@ -131,6 +131,9 @@ struct TimeZoneCache : Sendable, ~Copyable { |
| 34 | + return TimeZone(inner: result) |
| 35 | + } |
| 36 | + } |
| 37 | ++#elseif os(WASI) |
| 38 | ++ // WASI doesn't provide a way to get the current timezone for now, so |
| 39 | ++ // just return the default GMT timezone. |
| 40 | + #else |
| 41 | + let buffer = UnsafeMutableBufferPointer<CChar>.allocate(capacity: Int(PATH_MAX + 1)) |
| 42 | + defer { buffer.deallocate() } |
0 commit comments