From 9dc6259834522e4427947b812bab8d0e17ece32b Mon Sep 17 00:00:00 2001
From: "Devran \"Cosmo\" Uenal" <maccosmo@gmail.com>
Date: Mon, 13 Jan 2020 22:31:32 +0100
Subject: [PATCH 1/3] Import shim

---
 Sources/OpenSwiftUI/Layout/Alignment.swift          | 4 ++++
 Sources/OpenSwiftUI/Layout/EdgeInsets.swift         | 4 ++++
 Sources/OpenSwiftUI/Layout/ViewDimensions.swift     | 4 ++++
 Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift | 4 ++++
 Sources/OpenSwiftUI/Views/Color.swift               | 4 ++++
 Sources/OpenSwiftUI/Views/Font.swift                | 4 ++++
 Sources/OpenSwiftUI/Views/HStack.swift              | 4 ++++
 Sources/OpenSwiftUI/Views/HStackLayout.swift        | 4 ++++
 Sources/OpenSwiftUI/Views/Image.swift               | 4 ++++
 Sources/OpenSwiftUI/Views/Picker.swift              | 4 ++++
 Sources/OpenSwiftUI/Views/Shape.swift               | 4 ++++
 Sources/OpenSwiftUI/Views/ShapeView.swift           | 4 ++++
 Sources/OpenSwiftUI/Views/Shapes/Angle.swift        | 4 ++++
 Sources/OpenSwiftUI/Views/Shapes/Circle.swift       | 4 ++++
 Sources/OpenSwiftUI/Views/Shapes/Path.swift         | 5 ++---
 Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift    | 4 ++++
 Sources/OpenSwiftUI/Views/Text.swift                | 4 ++++
 Sources/OpenSwiftUI/Views/VStack.swift              | 4 ++++
 Sources/OpenSwiftUI/Views/VStackLayout.swift        | 4 ++++
 19 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/Sources/OpenSwiftUI/Layout/Alignment.swift b/Sources/OpenSwiftUI/Layout/Alignment.swift
index 5246970..69770bc 100644
--- a/Sources/OpenSwiftUI/Layout/Alignment.swift
+++ b/Sources/OpenSwiftUI/Layout/Alignment.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct Alignment {
     public var horizontal: HorizontalAlignment
diff --git a/Sources/OpenSwiftUI/Layout/EdgeInsets.swift b/Sources/OpenSwiftUI/Layout/EdgeInsets.swift
index ba39327..62617f7 100644
--- a/Sources/OpenSwiftUI/Layout/EdgeInsets.swift
+++ b/Sources/OpenSwiftUI/Layout/EdgeInsets.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct EdgeInsets: Equatable {
     public var top: CGFloat
diff --git a/Sources/OpenSwiftUI/Layout/ViewDimensions.swift b/Sources/OpenSwiftUI/Layout/ViewDimensions.swift
index e5a037d..4f6fc98 100644
--- a/Sources/OpenSwiftUI/Layout/ViewDimensions.swift
+++ b/Sources/OpenSwiftUI/Layout/ViewDimensions.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct ViewDimensions {
     public var width: CGFloat {
diff --git a/Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift b/Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift
index f316058..711b7b5 100644
--- a/Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift
+++ b/Sources/OpenSwiftUI/Modifiers/PaddingModifier.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct PaddingModifier: ViewModifier {
     static let defaultPadding: CGFloat = 8
diff --git a/Sources/OpenSwiftUI/Views/Color.swift b/Sources/OpenSwiftUI/Views/Color.swift
index 1c1d4c2..172cd77 100644
--- a/Sources/OpenSwiftUI/Views/Color.swift
+++ b/Sources/OpenSwiftUI/Views/Color.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public class AnyColorBox {
 }
diff --git a/Sources/OpenSwiftUI/Views/Font.swift b/Sources/OpenSwiftUI/Views/Font.swift
index 3de6045..56b7bc4 100644
--- a/Sources/OpenSwiftUI/Views/Font.swift
+++ b/Sources/OpenSwiftUI/Views/Font.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 extension View {
     public func font(_ font: Font?) -> some View {
diff --git a/Sources/OpenSwiftUI/Views/HStack.swift b/Sources/OpenSwiftUI/Views/HStack.swift
index fa4dddb..8692146 100644
--- a/Sources/OpenSwiftUI/Views/HStack.swift
+++ b/Sources/OpenSwiftUI/Views/HStack.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct HStack<Content>: View where Content: View {
     public typealias Body = Never
diff --git a/Sources/OpenSwiftUI/Views/HStackLayout.swift b/Sources/OpenSwiftUI/Views/HStackLayout.swift
index 17bfc92..63441f6 100644
--- a/Sources/OpenSwiftUI/Views/HStackLayout.swift
+++ b/Sources/OpenSwiftUI/Views/HStackLayout.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct _HStackLayout {
     public var alignment: VerticalAlignment
diff --git a/Sources/OpenSwiftUI/Views/Image.swift b/Sources/OpenSwiftUI/Views/Image.swift
index 5022288..e4aca6b 100644
--- a/Sources/OpenSwiftUI/Views/Image.swift
+++ b/Sources/OpenSwiftUI/Views/Image.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct Image: Equatable {
     public var _provider: AnyImageProviderBox
diff --git a/Sources/OpenSwiftUI/Views/Picker.swift b/Sources/OpenSwiftUI/Views/Picker.swift
index bc4a99c..1af2e5e 100644
--- a/Sources/OpenSwiftUI/Views/Picker.swift
+++ b/Sources/OpenSwiftUI/Views/Picker.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public protocol PickerStyle {
     static func _makeView<SelectionValue>(value: _GraphValue<_PickerValue<Self, SelectionValue>>, inputs: _ViewInputs) -> _ViewOutputs where SelectionValue: Hashable
diff --git a/Sources/OpenSwiftUI/Views/Shape.swift b/Sources/OpenSwiftUI/Views/Shape.swift
index d3205e1..9b57efa 100644
--- a/Sources/OpenSwiftUI/Views/Shape.swift
+++ b/Sources/OpenSwiftUI/Views/Shape.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public protocol Shape: Animatable, View {
     func path(in rect: CGRect) -> Path
diff --git a/Sources/OpenSwiftUI/Views/ShapeView.swift b/Sources/OpenSwiftUI/Views/ShapeView.swift
index ce1ce60..fc80892 100644
--- a/Sources/OpenSwiftUI/Views/ShapeView.swift
+++ b/Sources/OpenSwiftUI/Views/ShapeView.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct _ShapeView<Content, Style>: View where Content: Shape, Style: ShapeStyle {
     public var body: Never {
diff --git a/Sources/OpenSwiftUI/Views/Shapes/Angle.swift b/Sources/OpenSwiftUI/Views/Shapes/Angle.swift
index 7c40717..ad4bfd5 100644
--- a/Sources/OpenSwiftUI/Views/Shapes/Angle.swift
+++ b/Sources/OpenSwiftUI/Views/Shapes/Angle.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct Angle {
     public var radians: Double
diff --git a/Sources/OpenSwiftUI/Views/Shapes/Circle.swift b/Sources/OpenSwiftUI/Views/Shapes/Circle.swift
index 4cba5b4..2e7d55d 100644
--- a/Sources/OpenSwiftUI/Views/Shapes/Circle.swift
+++ b/Sources/OpenSwiftUI/Views/Shapes/Circle.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct Circle: Shape {
     public func path(in rect: CGRect) -> Path {
diff --git a/Sources/OpenSwiftUI/Views/Shapes/Path.swift b/Sources/OpenSwiftUI/Views/Shapes/Path.swift
index fdecc16..d798846 100644
--- a/Sources/OpenSwiftUI/Views/Shapes/Path.swift
+++ b/Sources/OpenSwiftUI/Views/Shapes/Path.swift
@@ -1,8 +1,7 @@
+#if canImport(Foundation)
 import Foundation
-#if os(Linux)
-import CoreGraphicsShim
 #else
-import CoreGraphics
+import CoreGraphicsShim
 #endif
 
 internal struct FixedRoundedRect: Equatable {
diff --git a/Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift b/Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift
index 093e870..59029fa 100644
--- a/Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift
+++ b/Sources/OpenSwiftUI/Views/Shapes/Rectangle.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct Rectangle: Shape {
     public func path(in rect: CGRect) -> Path {
diff --git a/Sources/OpenSwiftUI/Views/Text.swift b/Sources/OpenSwiftUI/Views/Text.swift
index 5459325..d413a7c 100644
--- a/Sources/OpenSwiftUI/Views/Text.swift
+++ b/Sources/OpenSwiftUI/Views/Text.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public class AnyTextStorage<Storage: StringProtocol> {
     public var storage: Storage
diff --git a/Sources/OpenSwiftUI/Views/VStack.swift b/Sources/OpenSwiftUI/Views/VStack.swift
index 3c8be84..21ccb30 100644
--- a/Sources/OpenSwiftUI/Views/VStack.swift
+++ b/Sources/OpenSwiftUI/Views/VStack.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct VStack<Content>: View where Content: View {
     public typealias Body = Never
diff --git a/Sources/OpenSwiftUI/Views/VStackLayout.swift b/Sources/OpenSwiftUI/Views/VStackLayout.swift
index c047497..dd123dd 100644
--- a/Sources/OpenSwiftUI/Views/VStackLayout.swift
+++ b/Sources/OpenSwiftUI/Views/VStackLayout.swift
@@ -1,4 +1,8 @@
+#if canImport(Foundation)
 import Foundation
+#else
+import CoreGraphicsShim
+#endif
 
 public struct _VStackLayout {
     public var alignment: HorizontalAlignment

From b3745b4e91d2fb4b6d2af3209da34d2f6d81e633 Mon Sep 17 00:00:00 2001
From: "Devran \"Cosmo\" Uenal" <maccosmo@gmail.com>
Date: Tue, 14 Jan 2020 00:59:36 +0100
Subject: [PATCH 2/3] Disable methods that require Foundation / Bundle

---
 Sources/OpenSwiftUI/LocalizedStringKey.swift | 2 ++
 Sources/OpenSwiftUI/Views/Color.swift        | 4 ++++
 Sources/OpenSwiftUI/Views/Image.swift        | 2 ++
 Sources/OpenSwiftUI/Views/Picker.swift       | 2 ++
 Sources/OpenSwiftUI/Views/Stepper.swift      | 6 ++++++
 Sources/OpenSwiftUI/Views/Text.swift         | 2 ++
 Sources/OpenSwiftUI/Views/Toggle.swift       | 2 ++
 7 files changed, 20 insertions(+)

diff --git a/Sources/OpenSwiftUI/LocalizedStringKey.swift b/Sources/OpenSwiftUI/LocalizedStringKey.swift
index a744aa5..a7473b2 100644
--- a/Sources/OpenSwiftUI/LocalizedStringKey.swift
+++ b/Sources/OpenSwiftUI/LocalizedStringKey.swift
@@ -1,3 +1,4 @@
+#if canImport(Foundation)
 public struct LocalizedStringKey {
     internal var key: String
     private var hasFormatting: Bool = false
@@ -10,3 +11,4 @@ public struct LocalizedStringKey {
         self.key = value
     }
 }
+#endif
diff --git a/Sources/OpenSwiftUI/Views/Color.swift b/Sources/OpenSwiftUI/Views/Color.swift
index 172cd77..22b4ab6 100644
--- a/Sources/OpenSwiftUI/Views/Color.swift
+++ b/Sources/OpenSwiftUI/Views/Color.swift
@@ -64,7 +64,11 @@ public class DisplayP3: AnyColorBox {
 
 extension Double {
     fileprivate var hexString: String {
+        #if canImport(Foundation)
         return String(format: "%02X", Int((self * 255).rounded()))
+        #else
+        fatalError("Not Implemented.")
+        #endif
     }
 }
 
diff --git a/Sources/OpenSwiftUI/Views/Image.swift b/Sources/OpenSwiftUI/Views/Image.swift
index e4aca6b..cb98499 100644
--- a/Sources/OpenSwiftUI/Views/Image.swift
+++ b/Sources/OpenSwiftUI/Views/Image.swift
@@ -30,6 +30,7 @@ extension Image: View {
     }
 }
 
+#if canImport(Foundation)
 extension Image {
     public init(_ name: String, bundle: Foundation.Bundle? = nil) {
         fatalError()
@@ -44,3 +45,4 @@ extension Image {
         fatalError()
     }
 }
+#endif
diff --git a/Sources/OpenSwiftUI/Views/Picker.swift b/Sources/OpenSwiftUI/Views/Picker.swift
index 1af2e5e..2368356 100644
--- a/Sources/OpenSwiftUI/Views/Picker.swift
+++ b/Sources/OpenSwiftUI/Views/Picker.swift
@@ -73,11 +73,13 @@ public struct Picker<Label, SelectionValue, Content>: View where Label: View, Se
 }
 
 extension Picker where Label == Text {
+    #if canImport(Foundation)
     public init(_ titleKey: LocalizedStringKey, selection: Binding<SelectionValue>, @ViewBuilder content: () -> Content) {
         self.selection = selection
         self.label = Text(titleKey)
         self.content = content()
     }
+    #endif
     
     public init<S>(_ title: S, selection: Binding<SelectionValue>, @ViewBuilder content: () -> Content) where S: StringProtocol {
         self.selection = selection
diff --git a/Sources/OpenSwiftUI/Views/Stepper.swift b/Sources/OpenSwiftUI/Views/Stepper.swift
index e9d7d2e..63e84a0 100644
--- a/Sources/OpenSwiftUI/Views/Stepper.swift
+++ b/Sources/OpenSwiftUI/Views/Stepper.swift
@@ -30,12 +30,14 @@ extension Stepper {
 }
 
 extension Stepper where Label == Text {
+    #if canImport(Foundation)
     public init(_ titleKey: LocalizedStringKey, onIncrement: (() -> Void)?, onDecrement: (() -> Void)?, onEditingChanged: @escaping (Bool) -> Void = { _ in }) {
         self.label = Text(titleKey)
         self.onIncrement = onIncrement
         self.onDecrement = onDecrement
         self.onEditingChanged = onEditingChanged
     }
+    #endif
     
     @_disfavoredOverload public init<S>(_ title: S, onIncrement: (() -> Void)?, onDecrement: (() -> Void)?, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where S: StringProtocol {
         self.label = Text(title)
@@ -44,20 +46,24 @@ extension Stepper where Label == Text {
         self.onEditingChanged = onEditingChanged
     }
     
+    #if canImport(Foundation)
     public init<V>(_ titleKey: LocalizedStringKey, value: Binding<V>, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V: Strideable {
         self.label = Text(titleKey)
         self.onEditingChanged = onEditingChanged
     }
+    #endif
     
     @_disfavoredOverload public init<S, V>(_ title: S, value: Binding<V>, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where S: StringProtocol, V: Strideable {
         self.label = Text(title)
         self.onEditingChanged = onEditingChanged
     }
     
+    #if canImport(Foundation)
     public init<V>(_ titleKey: LocalizedStringKey, value: Binding<V>, in bounds: ClosedRange<V>, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V: Strideable {
         self.label = Text(titleKey)
         self.onEditingChanged = onEditingChanged
     }
+    #endif
     
     @_disfavoredOverload public init<S, V>(_ title: S, value: Binding<V>, in bounds: ClosedRange<V>, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where S: StringProtocol, V: Strideable {
         self.label = Text(title)
diff --git a/Sources/OpenSwiftUI/Views/Text.swift b/Sources/OpenSwiftUI/Views/Text.swift
index d413a7c..e8b7aa2 100644
--- a/Sources/OpenSwiftUI/Views/Text.swift
+++ b/Sources/OpenSwiftUI/Views/Text.swift
@@ -68,9 +68,11 @@ public struct Text: View, Equatable {
         self._storage = .anyTextStorage(AnyTextStorage<String>(storage: String(content)))
     }
     
+    #if canImport(Foundation)
     public init(_ key: LocalizedStringKey, tableName: String? = nil, bundle: Bundle? = nil, comment: StaticString? = nil) {
         self._storage = .anyTextStorage(AnyTextStorage<String>(storage: key.key))
     }
+    #endif
     
     private init(verbatim content: String, modifiers: [Modifier] = []) {
         self._storage = .verbatim(content)
diff --git a/Sources/OpenSwiftUI/Views/Toggle.swift b/Sources/OpenSwiftUI/Views/Toggle.swift
index ced4a3e..9623031 100644
--- a/Sources/OpenSwiftUI/Views/Toggle.swift
+++ b/Sources/OpenSwiftUI/Views/Toggle.swift
@@ -20,9 +20,11 @@ extension Toggle where Label == ToggleStyleConfiguration.Label {
 }
 
 extension Toggle where Label == Text {
+    #if canImport(Foundation)
     public init(_ titleKey: LocalizedStringKey, isOn: Binding<Bool>) {
         fatalError()
     }
+    #endif
     
     public init<S>(_ title: S, isOn: Binding<Bool>) where S: StringProtocol {
         fatalError()

From 634e750739003b18fca438914064aa64a095aa68 Mon Sep 17 00:00:00 2001
From: Roman Kerimov <roma.kerimov@icloud.com>
Date: Mon, 9 Mar 2020 02:28:51 +0300
Subject: [PATCH 3/3] Fix building for Mac in Xcode

---
 Tests/OpenSwiftUITests/OpenSwiftUITests.swift | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Tests/OpenSwiftUITests/OpenSwiftUITests.swift b/Tests/OpenSwiftUITests/OpenSwiftUITests.swift
index 0658af0..8d70a71 100644
--- a/Tests/OpenSwiftUITests/OpenSwiftUITests.swift
+++ b/Tests/OpenSwiftUITests/OpenSwiftUITests.swift
@@ -3,12 +3,12 @@ import XCTest
 
 final class OpenSwiftUITests: XCTestCase {
     func testExample() {
-        let body = VStack {
+        let _ = VStack {
             Text("Hello")
             Text("World")
         }
         
-        let body = HStack {
+        let _ = HStack {
             if true {
                 Text("Hello")
             }