Repository navigation
Expand file tree
/
Copy pathProject.swift
More file actions
109 lines (104 loc) · 4.98 KB
/
Copy pathProject.swift
File metadata and controls
109 lines (104 loc) · 4.98 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import Foundation
import ProjectDescription
let sourceRoot = "Sources/OpenRenderBoxCxx"
let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
let sourceModuleMap = try String(
contentsOf: root.appendingPathComponent("\(sourceRoot)/include/module.modulemap"),
encoding: .utf8
)
let moduleHeaders = sourceModuleMap.components(separatedBy: .newlines).compactMap { line -> String? in
guard line.contains("header \"") else { return nil }
return line.components(separatedBy: "\"")[1]
}
// Use the same module declarations for SwiftPM and the framework.
let frameworkModuleMap = "framework " + sourceModuleMap
.replacingOccurrences(of: "module OpenRenderBoxCxx", with: "module OpenRenderBox")
.replacingOccurrences(of: "header \"OpenRenderBox/", with: "header \"")
.replacingOccurrences(of: "header \"../", with: "header \"")
let moduleMapDirectory = root.appendingPathComponent("Derived/ModuleMaps")
try FileManager.default.createDirectory(at: moduleMapDirectory, withIntermediateDirectories: true)
try frameworkModuleMap.write(
to: moduleMapDirectory.appendingPathComponent("OpenRenderBox.modulemap"),
atomically: true,
encoding: .utf8
)
// Preserve feature paths for the C++ and Objective-C submodules.
let internalHeaders = moduleHeaders.filter { $0.hasPrefix("../") }.map { String($0.dropFirst(3)) }
// Tuist otherwise treats template headers as resources and adds a resource bundle.
let templateHeaders = internalHeaders.filter { $0.hasSuffix(".tpp") }
let headerCopyCommands = internalHeaders.map { header in
let directory = (header as NSString).deletingLastPathComponent
return """
mkdir -p "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/\(directory)"
cp "${SRCROOT}/\(sourceRoot)/\(header)" "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/\(header)"
"""
}.joined(separator: "\n")
let exportModuleHeaders = TargetScript.pre(
script: """
set -eu
\(headerCopyCommands)
""",
name: "Export module headers",
inputPaths: internalHeaders.map { .glob(.path("\(sourceRoot)/\($0)")) },
outputPaths: internalHeaders.map { .path("$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/\($0)") },
basedOnDependencyAnalysis: true
)
let destinations: Destinations = [.mac, .iPhone, .iPad, .macCatalyst, .appleTv, .appleWatch, .appleVision]
let deploymentTargets = DeploymentTargets.multiplatform(
iOS: "18.0", macOS: "15.0", watchOS: "10.0", tvOS: "18.0", visionOS: "2.0"
)
let project = Project(
name: "OpenRenderBox",
settings: .settings(base: [
"CLANG_CXX_LANGUAGE_STANDARD": "c++20",
"SWIFT_VERSION": "5.0",
]),
targets: [
.target(
name: "OpenRenderBoxCxx",
destinations: destinations,
product: .staticLibrary,
bundleId: "org.openswiftui.OpenRenderBoxCxx",
deploymentTargets: deploymentTargets,
infoPlist: nil,
buildableFolders: [
.folder(.path(sourceRoot), exceptions: [.exception(excluded: ["include/module.modulemap"] + templateHeaders)])
],
settings: .settings(base: [
"HEADER_SEARCH_PATHS": ["$(SRCROOT)/\(sourceRoot)", "$(SRCROOT)/\(sourceRoot)/include"],
// Match SwiftPM while path operations still have incomplete implementations.
"GCC_WARN_ABOUT_RETURN_TYPE": "YES",
"SKIP_INSTALL": "YES",
])
),
.target(
name: "OpenRenderBox",
destinations: destinations,
product: .framework,
bundleId: "org.openswiftui.OpenRenderBox",
deploymentTargets: deploymentTargets,
buildableFolders: ["Sources/OpenRenderBox"],
headers: .headers(public: .list([.glob(.path("\(sourceRoot)/include/OpenRenderBox/*.h"))])),
scripts: [exportModuleHeaders],
dependencies: [
.target(name: "OpenRenderBoxCxx"),
.sdk(name: "Foundation", type: .framework),
.sdk(name: "CoreGraphics", type: .framework),
.sdk(name: "QuartzCore", type: .framework),
.sdk(name: "Metal", type: .framework),
.sdk(name: "c++", type: .library),
],
settings: .settings(base: [
"BUILD_LIBRARY_FOR_DISTRIBUTION": "YES",
// Keep Xcode responsible for installing the framework module map.
"MODULEMAP_FILE[sdk=*]": "$(SRCROOT)/Derived/ModuleMaps/OpenRenderBox.modulemap",
// The Swift target does not reference every exported C or Objective-C symbol.
"OTHER_LDFLAGS": ["$(inherited)", "-force_load", "$(BUILT_PRODUCTS_DIR)/libOpenRenderBoxCxx.a"],
"OTHER_SWIFT_FLAGS": ["$(inherited)", "-package-name", "OpenRenderBox", "-enable-upcoming-feature", "InternalImportsByDefault"],
"SKIP_INSTALL": "NO",
// ORBVersion.c defines the framework version symbols.
"VERSIONING_SYSTEM": "",
])
),
]
)