Repository navigation
refactor: organize native sources and header exports #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| 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: "module OpenRenderBox.C {", with: "module OpenRenderBox.C {\n header \"ORBConfiguration.h\"") | ||
| .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 | ||
| ) | ||
|
|
||
| // Consumers must use the same backend as the framework binary. | ||
| let frameworkConfiguration = """ | ||
| #pragma once | ||
|
|
||
| #if defined(OPENRENDERBOX_CF_CGTYPES) && OPENRENDERBOX_CF_CGTYPES != 1 | ||
| #error "This OpenRenderBox framework requires OPENRENDERBOX_CF_CGTYPES=1." | ||
| #endif | ||
| #ifndef OPENRENDERBOX_CF_CGTYPES | ||
| #define OPENRENDERBOX_CF_CGTYPES 1 | ||
| #endif | ||
|
|
||
| """ | ||
|
|
||
| // 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 | ||
| mkdir -p "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}" | ||
| cat > "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/ORBConfiguration.h" <<'EOF' | ||
| \(frameworkConfiguration) | ||
| EOF | ||
| \(headerCopyCommands) | ||
| """, | ||
| name: "Export module headers", | ||
| inputPaths: internalHeaders.map { .glob(.path("\(sourceRoot)/\($0)")) }, | ||
| outputPaths: [.path("$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/ORBConfiguration.h")] | ||
| + 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", | ||
| "GCC_PREPROCESSOR_DEFINITIONS": ["$(inherited)", "OPENRENDERBOX_CF_CGTYPES"], | ||
| "SWIFT_ACTIVE_COMPILATION_CONDITIONS": ["$(inherited)", "OPENRENDERBOX_CF_CGTYPES"], | ||
| "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": "", | ||
| ]) | ||
| ), | ||
| ] | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For standalone framework consumers, these project-level definitions are not propagated when importing the copied bundle. The exported
ORBPath.h,ORBPathCallbacks.h, andORBPathStorage.hall guard their declarations with#if OPENRENDERBOX_CF_CGTYPES, but neither the exported headers nor the generated framework module map defines that macro. Consequently, the framework builds its native path implementation while ordinary C and Swift consumers cannot see its path API unless they manually supply an undocumented build flag. Encode the framework's fixed backend configuration in its exported headers so clients see the same API that was built; the current framework client test only exercises color and animation APIs and misses this mismatch.Useful? React with 👍 / 👎.