Skip to content

Commit 6dfd5bf

Browse files
committed
Workaround for new XCFramework
1 parent 6cd9a7e commit 6dfd5bf

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

.github/workflows/xcframework-release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ jobs:
7474
-archive "Archives/P256K-watchOS.xcarchive" -framework P256K.framework \
7575
-archive "Archives/P256K-watchOS Simulator.xcarchive" -framework P256K.framework \
7676
-output P256K.xcframework
77+
78+
# Workaround for Swift issue SR-14195/GitHub #56573:
79+
# When a module has the same name as a type it contains (P256K in this case),
80+
# Swift generates invalid module interfaces with incorrect type qualifications.
81+
# This leads to imports failing with errors like:
82+
# "TypeName is not a member type of class ModuleName.ModuleName"
83+
#
84+
# This script fixes generated .swiftinterface files by:
85+
# 1. Removing double-qualification of the P256K type
86+
# 2. Fixing references to other types that don't need module qualification
87+
# See: https://github.com/swiftlang/swift/issues/56573
88+
find P256K.xcframework -name '*.swiftinterface' -print0 \
89+
| xargs -0 sed -i '' \
90+
-e 's/extension P256K\.P256K/extension P256K/g' \
91+
-e 's/P256K\.P256K\./P256K\./g' \
92+
-e 's/[[:<:]]P256K\.secp256k1Error[[:>:]]/secp256k1Error/g' \
93+
-e 's/[[:<:]]P256K\.Digest[[:>:]]/Digest/g' \
94+
-e 's/[[:<:]]P256K\.CryptoKitError[[:>:]]/CryptoKitError/g' \
95+
-e 's/[[:<:]]P256K\.CryptoKitASN1Error[[:>:]]/CryptoKitASN1Error/g' \
96+
-e 's/[[:<:]]P256K\.SHA256Digest[[:>:]]/SHA256Digest/g' \
97+
-e 's/[[:<:]]P256K\.XonlyKeyImplementation[[:>:]]/XonlyKeyImplementation/g' \
98+
-e 's/[[:<:]]P256K\.HashDigest[[:>:]]/HashDigest/g' \
99+
-e 's/[[:<:]]P256K\.SharedSecret[[:>:]]/SharedSecret/g' \
100+
-e 's/[[:<:]]P256K\.PublicKeyImplementation[[:>:]]/PublicKeyImplementation/g' \
101+
-e 's/[[:<:]]P256K\.PrivateKeyImplementation[[:>:]]/PrivateKeyImplementation/g'
77102
- name: 7z XCFramework
78103
run: |
79104
7z a -tzip -mx=9 P256K.xcframework.zip P256K.xcframework

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
dependencies: [
1515
// Dependencies used for package development
1616
.package(url: "https://github.com/csjones/lefthook-plugin.git", exact: "1.11.11"),
17-
.package(url: "https://github.com/21-DOT-DEV/swift-plugin-tuist.git", exact: "4.43.2"),
17+
.package(url: "https://github.com/21-DOT-DEV/swift-plugin-tuist.git", exact: "4.48.1"),
1818
.package(url: "https://github.com/nicklockwood/SwiftFormat.git", exact: "0.55.5"),
1919
.package(url: "https://github.com/realm/SwiftLint.git", exact: "0.59.1")
2020
],

Projects/Resources/P256K/Release.xcconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ VALIDATE_PRODUCT = YES
8080

8181
SKIP_INSTALL = NO
8282

83+
// Build Library for Distribution
84+
//
85+
// Enables Swift's Library Evolution mode, which generates .swiftinterface files.
86+
// This allows clients to use the library even when compiled with different Swift versions.
87+
88+
BUILD_LIBRARY_FOR_DISTRIBUTION = YES
89+
8390

8491
//********************************************//
8592
//* Apple Clang - Code Generation *//

Projects/Resources/P256K/Shared.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Debug.xcconfig
2+
// Shared.xcconfig
33
//
44
// Generated by BuildSettingExtractor on 1/22/25
55
// https://buildsettingextractor.com

Tests/XCFrameworkTests/XCFrameworkTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct XCFrameworkTestSuite {
1717
let expectedPrivateKey = "7da12cc39bb4189ac72d34fc2225df5cf36aaacdcac7e5a43963299bc8d888ed"
1818
let expectedPublicKey = "023521df7b94248ffdf0d37f738a4792cc3932b6b1b89ef71cddde8251383b26e7"
1919
let privateKeyBytes = try! expectedPrivateKey.bytes
20-
let privateKey = try! secp256k1.Signing.PrivateKey(dataRepresentation: privateKeyBytes)
20+
let privateKey = try! P256K.Signing.PrivateKey(dataRepresentation: privateKeyBytes)
2121

2222
#expect(String(bytes: privateKey.dataRepresentation) == expectedPrivateKey)
2323
#expect(String(bytes: privateKey.publicKey.dataRepresentation) == expectedPublicKey)

bitrise.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,31 @@ workflows:
158158
-archive "Archives/P256K-watchOS.xcarchive" -framework P256K.framework \
159159
-archive "Archives/P256K-watchOS Simulator.xcarchive" -framework P256K.framework \
160160
-output P256K.xcframework
161+
162+
# Workaround for Swift issue SR-14195/GitHub #56573:
163+
# When a module has the same name as a type it contains (P256K in this case),
164+
# Swift generates invalid module interfaces with incorrect type qualifications.
165+
# This leads to imports failing with errors like:
166+
# "TypeName is not a member type of class ModuleName.ModuleName"
167+
#
168+
# This script fixes generated .swiftinterface files by:
169+
# 1. Removing double-qualification of the P256K type
170+
# 2. Fixing references to other types that don't need module qualification
171+
# See: https://github.com/swiftlang/swift/issues/56573
172+
find P256K.xcframework -name '*.swiftinterface' -print0 \
173+
| xargs -0 sed -i '' \
174+
-e 's/extension P256K\.P256K/extension P256K/g' \
175+
-e 's/P256K\.P256K\./P256K\./g' \
176+
-e 's/[[:<:]]P256K\.secp256k1Error[[:>:]]/secp256k1Error/g' \
177+
-e 's/[[:<:]]P256K\.Digest[[:>:]]/Digest/g' \
178+
-e 's/[[:<:]]P256K\.CryptoKitError[[:>:]]/CryptoKitError/g' \
179+
-e 's/[[:<:]]P256K\.CryptoKitASN1Error[[:>:]]/CryptoKitASN1Error/g' \
180+
-e 's/[[:<:]]P256K\.SHA256Digest[[:>:]]/SHA256Digest/g' \
181+
-e 's/[[:<:]]P256K\.XonlyKeyImplementation[[:>:]]/XonlyKeyImplementation/g' \
182+
-e 's/[[:<:]]P256K\.HashDigest[[:>:]]/HashDigest/g' \
183+
-e 's/[[:<:]]P256K\.SharedSecret[[:>:]]/SharedSecret/g' \
184+
-e 's/[[:<:]]P256K\.PublicKeyImplementation[[:>:]]/PublicKeyImplementation/g' \
185+
-e 's/[[:<:]]P256K\.PrivateKeyImplementation[[:>:]]/PrivateKeyImplementation/g'
161186
- deploy-to-bitrise-io:
162187
inputs:
163188
- deploy_path: "$BITRISE_SOURCE_DIR/P256K.xcframework"

0 commit comments

Comments
 (0)