Repository navigation
Expand file tree
/
Copy pathPackage.swift
More file actions
94 lines (89 loc) · 4.48 KB
/
Copy pathPackage.swift
File metadata and controls
94 lines (89 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// swift-tools-version: 6.0
import Foundation
import PackageDescription
// React Native evaluates this package through build/generated/autolinking/libs/.
let reactHeaders: [Target.Dependency] = [
.product(name: "ReactHeaders", package: "ReactNative"),
.product(name: "ReactNativeHeaders", package: "ReactNative"),
.product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
.product(name: "ReactAppHeaders", package: "React-GeneratedCode"),
]
// The Swift import shim lives outside ios/. Keep unrelated repository and npm
// package contents out of SwiftPM's resource discovery.
let usedRootEntries: Set<String> = ["ios", "spm-support", "spm-headers", "Package.swift"]
// `try?` rather than `try!`: a manifest that traps reports a Swift fatal error
// instead of a SwiftPM diagnostic, which is a miserable thing to debug.
let unusedRootEntries = ((try? FileManager.default.contentsOfDirectory(atPath: Context.packageDirectory)) ?? [])
.filter { !usedRootEntries.contains($0) }
.sorted()
// Discover sources as folders, splitting the podspec's native and Swift files.
// Exclude projects and non-source files from both targets.
let iosDirectory = URL(fileURLWithPath: Context.packageDirectory).appendingPathComponent("ios")
let iosEntries = ((try? FileManager.default.subpathsOfDirectory(atPath: iosDirectory.path)) ?? [])
.filter { !$0.contains(".xcodeproj/") }
func unusedIosEntries(sourceExtensions: Set<String>) -> [String] {
iosEntries.filter { entry in
let url = iosDirectory.appendingPathComponent(entry)
if url.pathExtension == "xcodeproj" { return true }
// An entry that cannot be stat'd -- a dangling symlink, say -- counts as
// a file so it stays excludable. Excluding a directory would drop
// everything inside it.
let isDirectory = (try? url.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false
return !isDirectory && (!sourceExtensions.contains(url.pathExtension)
|| entry == "Menu-Bridging-Header.h")
}
.map { "ios/" + $0 }
.sorted()
}
let unusedSwiftIosEntries = unusedIosEntries(sourceExtensions: ["swift"])
let unusedObjCIosEntries = unusedIosEntries(sourceExtensions: ["h", "m", "mm"])
let package = Package(
name: "react_native_menu",
platforms: [.iOS("15.1")],
products: [
.library(name: "react_native_menu", targets: ["react_native_menu", "ReactNativeMenuObjC"]),
],
dependencies: [
.package(name: "ReactNative", path: "../../../../xcframeworks"),
.package(name: "React-GeneratedCode", path: "../../../ios"),
],
targets: [
// Preserve the CocoaPods Swift module name. Swift depends on React only;
// the Fabric adapter below depends on Swift, avoiding a target cycle.
.target(
name: "react_native_menu",
dependencies: reactHeaders,
path: ".",
exclude: unusedRootEntries + ["spm-headers"] + unusedSwiftIosEntries,
sources: ["ios/Shared", "ios/OldArch", "ios/NewArch", "spm-support"]
),
.target(
name: "ReactNativeMenuObjC",
dependencies: [.target(name: "react_native_menu")] + reactHeaders,
// Root the target here so its empty public module stays outside ios/.
path: ".",
exclude: unusedRootEntries + ["spm-support"] + unusedObjCIosEntries,
// Name the source directories rather than all of ios/: a stray .h,
// .m or .mm anywhere under ios/ (stale codegen output under
// ios/build/, say, in a consumer using this as a path dependency)
// would otherwise be compiled into this target.
sources: ["ios/MenuViewManager.mm", "ios/Shared", "ios/OldArch", "ios/NewArch"],
// Required: without it SwiftPM looks for a default include/ folder, which this target does not have.
publicHeadersPath: "spm-headers/public",
cSettings: [
.define("RCT_NEW_ARCH_ENABLED", to: "1"),
.headerSearchPath("ios/NewArch"),
.headerSearchPath("spm-headers"),
],
cxxSettings: [
.define("RCT_NEW_ARCH_ENABLED", to: "1"),
.define("DEBUG", .when(configuration: .debug)),
.define("NDEBUG", .when(configuration: .release)),
.headerSearchPath("ios/NewArch"),
.headerSearchPath("spm-headers"),
]
),
],
swiftLanguageModes: [.v5],
cxxLanguageStandard: .cxx20
)