From 42ca7048ec4e80d27ac732891fe78c7536b2b1fc Mon Sep 17 00:00:00 2001 From: Adin Date: Wed, 29 Jul 2026 13:09:03 +0800 Subject: [PATCH 1/4] fix: use pure-swift cg geometry on wasi/linux/android --- Source/CoreGraphicsPolyfill.swift | 11 ++--------- Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift | 9 --------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/Source/CoreGraphicsPolyfill.swift b/Source/CoreGraphicsPolyfill.swift index cb9121d..ea090ce 100644 --- a/Source/CoreGraphicsPolyfill.swift +++ b/Source/CoreGraphicsPolyfill.swift @@ -5,9 +5,7 @@ // Created by khoi on 10/5/25. // -#if os(Linux) || os(WASI) || os(Android) -import Foundation -#elseif canImport(FoundationEssentials) +#if canImport(FoundationEssentials) import FoundationEssentials #else import Foundation @@ -21,12 +19,7 @@ import Android import Glibc #endif -#if os(Linux) || os(WASI) || os(Android) -public typealias CGFloat = Foundation.CGFloat -public typealias CGPoint = Foundation.CGPoint -public typealias CGSize = Foundation.CGSize -public typealias CGRect = Foundation.CGRect -#elseif !canImport(CoreGraphics) +#if !canImport(CoreGraphics) public typealias CGFloat = Double public struct CGPoint: Equatable { diff --git a/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift b/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift index 65ea17e..43466e4 100644 --- a/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift +++ b/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift @@ -25,15 +25,6 @@ final class PolyfillTests: XCTestCase { #if os(WASI) || os(Linux) || os(Android) - func testGeometryTypesMatchFoundation() { - let scalar: Foundation.CGFloat = CGFloat(1) - let point: Foundation.CGPoint = CGPoint(x: scalar, y: scalar) - let size: Foundation.CGSize = CGSize(width: scalar, height: scalar) - let rect: Foundation.CGRect = CGRect(origin: point, size: size) - - XCTAssertEqual(rect, Foundation.CGRect(x: 1, y: 1, width: 1, height: 1)) - } - func testDoubleSerialization() { XCTAssertEqual(Double(1).serialize(), "1") } From 4cbe9934e762c0ebe66446b6321a8b250285e6d9 Mon Sep 17 00:00:00 2001 From: Adin Date: Wed, 29 Jul 2026 13:33:17 +0800 Subject: [PATCH 2/4] fix: remove redundant double serializableatom conformance --- Source/Serialization/Serializations.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Serialization/Serializations.swift b/Source/Serialization/Serializations.swift index e538548..19259d2 100644 --- a/Source/Serialization/Serializations.swift +++ b/Source/Serialization/Serializations.swift @@ -49,7 +49,7 @@ extension CGFloat: SerializableAtom { } -#if canImport(CoreGraphics) || os(Linux) || os(WASI) || os(Android) +#if canImport(CoreGraphics) extension Double: SerializableAtom { func serialize() -> String { From 37ffda61922195b29bf9ee5ef7ae7d472232152d Mon Sep 17 00:00:00 2001 From: Adin Date: Wed, 29 Jul 2026 13:38:17 +0800 Subject: [PATCH 3/4] fix: avoid foundation cg type ambiguity in polyfill tests --- Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift b/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift index 43466e4..584df0c 100644 --- a/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift +++ b/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift @@ -16,7 +16,20 @@ // since the polyfill types are aliases to the native CoreGraphics types. // +#if canImport(FoundationEssentials) +import FoundationEssentials +#else import Foundation +#endif + +#if os(WASI) +import WASILibc +#elseif canImport(Android) +import Android +#elseif canImport(Glibc) +import Glibc +#endif + import XCTest @testable import SVGView From d5c9767c1b9003ffd67377831f66e43836f36045 Mon Sep 17 00:00:00 2001 From: Adin Date: Wed, 29 Jul 2026 13:41:24 +0800 Subject: [PATCH 4/4] fix: shadow foundation cg types leaked via xctest on linux --- Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift b/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift index 584df0c..d2ef2cf 100644 --- a/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift +++ b/Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift @@ -35,9 +35,14 @@ import XCTest @testable import SVGView final class PolyfillTests: XCTestCase { - + #if os(WASI) || os(Linux) || os(Android) + private typealias CGFloat = SVGView.CGFloat + private typealias CGPoint = SVGView.CGPoint + private typealias CGSize = SVGView.CGSize + private typealias CGRect = SVGView.CGRect + func testDoubleSerialization() { XCTAssertEqual(Double(1).serialize(), "1") }