Skip to content

Commit 8eb03b6

Browse files
authored
Add OPENSWIFTUI_BUILD_FOR_DARWIN_PLATFORM support (#290)
1 parent 379da41 commit 8eb03b6

File tree

2 files changed

+17
-50
lines changed

2 files changed

+17
-50
lines changed

Package.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"originHash" : "1df077467751f44b627f08159392681d925d1fefdccc1e49aa5e0006d811e9ff",
2+
"originHash" : "669d1f5a7baa4f6093075d288ac99f536ebb7801497e931b763050191ecbf7d0",
33
"pins" : [
44
{
55
"identity" : "darwinprivateframeworks",

Package.swift

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
1717
}
1818
}
1919

20+
#if os(macOS)
21+
// NOTE: #if os(macOS) check is not accurate if we are cross compiling for Linux platform. So we add an env key to specify it.
22+
let buildForDarwinPlatform = envEnable("OPENSWIFTUI_BUILD_FOR_DARWIN_PLATFORM", default: true)
23+
#else
24+
let buildForDarwinPlatform = envEnable("OPENSWIFTUI_BUILD_FOR_DARWIN_PLATFORM")
25+
#endif
26+
2027
// MARK: - Env and Config
2128

2229
let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
@@ -72,11 +79,7 @@ if development {
7279

7380
// MARK: - [env] OPENSWIFTUI_LINK_COREUI
7481

75-
#if os(macOS)
76-
let linkCoreUI = envEnable("OPENSWIFTUI_LINK_COREUI", default: true)
77-
#else
78-
let linkCoreUI = envEnable("OPENSWIFTUI_LINK_COREUI")
79-
#endif
82+
let linkCoreUI = envEnable("OPENSWIFTUI_LINK_COREUI", default: buildForDarwinPlatform)
8083

8184
if linkCoreUI {
8285
sharedCSettings.append(
@@ -92,20 +95,11 @@ if linkCoreUI {
9295

9396
// MARK: - [env] OPENGSWIFTUI_SYMBOL_LOCATOR
9497

95-
#if os(macOS)
96-
let symbolLocatorCondition = envEnable("OPENGSWIFTUI_SYMBOL_LOCATOR", default: true)
97-
#else
98-
let symbolLocatorCondition = envEnable("OPENGSWIFTUI_SYMBOL_LOCATOR")
99-
#endif
98+
let symbolLocatorCondition = envEnable("OPENGSWIFTUI_SYMBOL_LOCATOR", default: buildForDarwinPlatform)
10099

101100
// MARK: - [env] OPENGSWIFTUI_SWIFTUI_RENDER
102101

103-
#if os(macOS)
104-
let swiftUIRenderCondition = envEnable("OPENSWIFTUI_SWIFTUI_RENDER", default: true)
105-
#else
106-
let swiftUIRenderCondition = envEnable("OPENSWIFTUI_SWIFTUI_RENDER")
107-
#endif
108-
102+
let swiftUIRenderCondition = envEnable("OPENSWIFTUI_SWIFTUI_RENDER", default: buildForDarwinPlatform)
109103
if swiftUIRenderCondition {
110104
sharedCSettings.append(.define("_OPENSWIFTUI_SWIFTUI_RENDER"))
111105
sharedCxxSettings.append(.define("_OPENSWIFTUI_SWIFTUI_RENDER"))
@@ -132,12 +126,7 @@ if warningsAsErrorsCondition {
132126

133127
// MARK: - [env] OPENSWIFTUI_LIBRARY_EVOLUTION
134128

135-
#if os(macOS)
136-
let libraryEvolutionCondition = envEnable("OPENSWIFTUI_LIBRARY_EVOLUTION", default: true)
137-
#else
138-
let libraryEvolutionCondition = envEnable("OPENSWIFTUI_LIBRARY_EVOLUTION")
139-
#endif
140-
129+
let libraryEvolutionCondition = envEnable("OPENSWIFTUI_LIBRARY_EVOLUTION", default: buildForDarwinPlatform)
141130
if libraryEvolutionCondition {
142131
// NOTE: -enable-library-evolution will cause module verify failure for `swift build`.
143132
// Either set OPENSWIFTUI_LIBRARY_EVOLUTION=0 or add `-Xswiftc -no-verify-emitted-module-interface` after `swift build`
@@ -457,12 +446,7 @@ extension Target {
457446

458447
let useLocalDeps = envEnable("OPENSWIFTUI_USE_LOCAL_DEPS")
459448

460-
#if os(macOS)
461-
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true)
462-
#else
463-
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH")
464-
#endif
465-
449+
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: buildForDarwinPlatform)
466450
if attributeGraphCondition {
467451
openSwiftUICoreTarget.addAGSettings()
468452
openSwiftUITarget.addAGSettings()
@@ -474,12 +458,7 @@ if attributeGraphCondition {
474458
openSwiftUIBridgeTestTarget.addAGSettings()
475459
}
476460

477-
#if os(macOS)
478-
let renderBoxCondition = envEnable("OPENBOX_RENDERBOX", default: true)
479-
#else
480-
let renderBoxCondition = envEnable("OPENBOX_RENDERBOX")
481-
#endif
482-
461+
let renderBoxCondition = envEnable("OPENBOX_RENDERBOX", default: buildForDarwinPlatform)
483462
if renderBoxCondition {
484463
openSwiftUICoreTarget.addRBSettings()
485464
openSwiftUITarget.addRBSettings()
@@ -525,11 +504,7 @@ if useLocalDeps {
525504
package.dependencies += dependencies
526505
}
527506

528-
#if os(macOS)
529-
let openCombineCondition = envEnable("OPENSWIFTUI_OPENCOMBINE")
530-
#else
531-
let openCombineCondition = envEnable("OPENSWIFTUI_OPENCOMBINE", default: true)
532-
#endif
507+
let openCombineCondition = envEnable("OPENSWIFTUI_OPENCOMBINE", default: !buildForDarwinPlatform)
533508
if openCombineCondition {
534509
package.dependencies.append(
535510
.package(url: "https://github.com/OpenSwiftUIProject/OpenCombine.git", from: "0.15.0")
@@ -538,11 +513,7 @@ if openCombineCondition {
538513
openSwiftUITarget.addOpenCombineSettings()
539514
}
540515

541-
#if os(macOS)
542-
let swiftLogCondition = envEnable("OPENSWIFTUI_SWIFT_LOG")
543-
#else
544-
let swiftLogCondition = envEnable("OPENSWIFTUI_SWIFT_LOG", default: true)
545-
#endif
516+
let swiftLogCondition = envEnable("OPENSWIFTUI_SWIFT_LOG", default: !buildForDarwinPlatform)
546517
if swiftLogCondition {
547518
package.dependencies.append(
548519
.package(url: "https://github.com/apple/swift-log", from: "1.5.3")
@@ -551,11 +522,7 @@ if swiftLogCondition {
551522
openSwiftUITarget.addSwiftLogSettings()
552523
}
553524

554-
#if os(macOS)
555-
let swiftCryptoCondition = envEnable("OPENSWIFTUI_SWIFT_CRYPTO")
556-
#else
557-
let swiftCryptoCondition = envEnable("OPENSWIFTUI_SWIFT_CRYPTO", default: true)
558-
#endif
525+
let swiftCryptoCondition = envEnable("OPENSWIFTUI_SWIFT_CRYPTO", default: !buildForDarwinPlatform)
559526
if swiftCryptoCondition {
560527
package.dependencies.append(
561528
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.8.0")

0 commit comments

Comments
 (0)