Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var packageProductTypes: [String: ProjectDescription.Product] = [
"OpenSwiftUICore": ProjectDescription.Product.framework,
"OpenSwiftUI_SPI": ProjectDescription.Product.staticFramework,
"COpenSwiftUI": ProjectDescription.Product.staticFramework,
"OpenSwiftUIMacros": ProjectDescription.Product.macro,
"OpenSwiftUIMacrosPlugin": ProjectDescription.Product.macro,
"OpenSwiftUITestsSupport": ProjectDescription.Product.staticFramework,
"OpenSwiftUISymbolDualTestsSupport": ProjectDescription.Product.staticFramework,
"OpenAttributeGraphShims": ProjectDescription.Product.staticFramework,
Expand Down
4 changes: 4 additions & 0 deletions Macros/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.build
/Derived
/*.xcodeproj
/Package.resolved
41 changes: 41 additions & 0 deletions Macros/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// swift-tools-version: 6.2

import CompilerPluginSupport
import PackageDescription

let package = Package(
name: "OpenSwiftUIMacros",
platforms: [
.macOS(.v15),
],
products: [
.library(name: "OpenSwiftUIMacrosPlugin", targets: ["OpenSwiftUIMacros"]),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "603.0.0"),
],
targets: [
.macro(
name: "OpenSwiftUIMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
],
swiftSettings: [
.enableUpcomingFeature("InternalImportsByDefault"),
.swiftLanguageMode(.v5),
]
),
.testTarget(
name: "OpenSwiftUIMacrosTests",
dependencies: [
"OpenSwiftUIMacros",
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
],
swiftSettings: [
.enableUpcomingFeature("InternalImportsByDefault"),
.swiftLanguageMode(.v5),
]
),
]
)
31 changes: 5 additions & 26 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// swift-tools-version: 6.2

import CompilerPluginSupport
import Foundation
import PackageDescription

Expand Down Expand Up @@ -546,26 +545,6 @@ let openSwiftUISPITestTarget = Target.testTarget(
swiftSettings: sharedSwiftSettings
)

// MARK: - OpenSwiftUIMacros Target

let openSwiftUIMacrosTarget = Target.macro(
name: "OpenSwiftUIMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
],
swiftSettings: sharedSwiftSettings
)

let openSwiftUIMacrosTestTarget = Target.testTarget(
name: "OpenSwiftUIMacrosTests",
dependencies: [
"OpenSwiftUIMacros",
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
],
swiftSettings: sharedSwiftSettings
)

// MARK: - OpenSwiftUICore Target

// NOTE:
Expand All @@ -575,7 +554,7 @@ let openSwiftUICoreTarget = Target.target(
name: "OpenSwiftUICore",
dependencies: [
"OpenSwiftUI_SPI",
"OpenSwiftUIMacros",
.product(name: "OpenSwiftUIMacrosPlugin", package: "OpenSwiftUIMacros"),
.product(name: "OpenCoreGraphicsShims", package: "OpenCoreGraphics"),
.product(name: "OpenQuartzCoreShims", package: "OpenCoreGraphics"),
.product(name: "OpenAttributeGraphShims", package: "OpenAttributeGraph"),
Expand Down Expand Up @@ -777,11 +756,12 @@ let package = Package(
products: products,
dependencies: [
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.3"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "603.0.0"),
// Keep the host-only macro implementation outside this package so
// target-platform tests do not link it into their test bundles.
.package(name: "OpenSwiftUIMacros", path: "Macros"),
],
targets: [
openSwiftUISPITarget,
openSwiftUIMacrosTarget,
openSwiftUICoreTarget,
cOpenSwiftUITarget,
openSwiftUITarget,
Expand All @@ -808,7 +788,6 @@ if !compatibilityTestCondition {
package.targets += [
cOpenSwiftUITestTarget,
openSwiftUISPITestTarget,
openSwiftUIMacrosTestTarget,
openSwiftUICoreTestTarget,
openSwiftUITestTarget,
openSwiftUIBridgeTestTarget,
Expand Down Expand Up @@ -986,7 +965,7 @@ let packageSettings = PackageSettings(
"OpenSwiftUICore": ProjectDescription.Product.framework,
"OpenSwiftUI_SPI": ProjectDescription.Product.staticFramework,
"COpenSwiftUI": ProjectDescription.Product.staticFramework,
"OpenSwiftUIMacros": ProjectDescription.Product.macro,
"OpenSwiftUIMacrosPlugin": ProjectDescription.Product.macro,
"OpenSwiftUITestsSupport": ProjectDescription.Product.staticFramework,
"OpenSwiftUISymbolDualTestsSupport": ProjectDescription.Product.staticFramework,
"OpenAttributeGraphShims": ProjectDescription.Product.staticFramework,
Expand Down
2 changes: 1 addition & 1 deletion Renderer/Stdout/Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let packageProductTypes: [String: ProjectDescription.Product] = [
"OpenSwiftUICore": .staticFramework,
"OpenSwiftUI_SPI": .staticFramework,
"COpenSwiftUI": .staticFramework,
"OpenSwiftUIMacros": .macro,
"OpenSwiftUIMacrosPlugin": .macro,
"OpenSwiftUITestsSupport": .staticFramework,
"OpenSwiftUISymbolDualTestsSupport": .staticFramework,
"OpenAttributeGraphShims": .staticFramework,
Expand Down
12 changes: 6 additions & 6 deletions Scripts/build_xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,12 @@ puts "Removed #{macro_name} archive references from #{File.dirname(path)}"
RUBY
}

# The xcframework archive path sets OPENSWIFTUI_XCFRAMEWORK_BUILD, which expands
# macro usages inline where needed. Avoid forcing generated macro tool targets to
# archive for simulator SDKs, where Xcode can try to build them for the target
# platform instead of the host platform.
# Keep OpenObservation's same-package macro target out of archive builds. The
# OpenSwiftUIMacros target lives in a separate package and remains available to
# OpenSwiftUICore as a host-only compiler plugin.
remove_generated_macro_references "$PROJECT_ROOT/.build/tuist-derived/Projects/OpenObservation/OpenObservation.xcodeproj" "OpenObservation" "OpenObservationMacros"
remove_generated_macro_references "$PROJECT_ROOT/.build/tuist-derived/OpenObservation/OpenObservation.xcodeproj" "OpenObservation" "OpenObservationMacros"
remove_generated_macro_references "$PROJECT_ROOT/../OpenObservation/OpenObservation.xcodeproj" "OpenObservation" "OpenObservationMacros"
remove_generated_macro_references "$XCODEPROJ" "OpenSwiftUICore" "OpenSwiftUIMacros"
remove_generated_macro_references "$XCODEPROJ" "OpenSwiftUICore" "OpenObservationMacros"

echo "SDKs: ${SDKS[*]}"
Expand Down Expand Up @@ -473,7 +471,9 @@ build_framework() {
-scheme "$scheme"
-configuration Release
-archivePath "$archive_path"
-sdk "$sdk"
# A global -sdk overrides host-only macro targets and makes Xcode archive
# them for the destination platform. The destination selects the SDK for
# framework targets while macro executables retain their host platform.
-destination "$destination"
-derivedDataPath "$DERIVED_DATA_PATH"
-skipPackagePluginValidation
Expand Down
1 change: 1 addition & 0 deletions Scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ if [[ "$(uname)" == "Linux" ]] && command -v swiftly &> /dev/null && [[ -z "$OPE
fi

swift test
swift test --package-path Macros
16 changes: 0 additions & 16 deletions Sources/OpenSwiftUICore/View/Text/Text/Text+LayoutShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,6 @@ package struct TextShape: Equatable {
}
}

// Workaround: xcodebuild builds SPM macro targets for the target SDK platform
// instead of the host platform, causing "malformed response" errors on non-macOS
// SDKs (eg. iphonesimulator). Expand @Entry macro inline for xcframework builds.
// See https://forums.swift.org/t/xcodebuild-attempts-to-build-macro-package-with-wrong-arch/76340
#if OPENSWIFTUI_XCFRAMEWORK_BUILD
extension EnvironmentValues {
var textShape: TextShape {
get { self[__Key_textShape.self] }
set { self[__Key_textShape.self] = newValue }
}
private struct __Key_textShape: EnvironmentKey {
static var defaultValue: TextShape { .bounds }
}
}
#else
extension EnvironmentValues {
@Entry var textShape: TextShape = .bounds
}
#endif
Loading