Skip to content
Open
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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ jobs:
run: yarn && yarn bootstrap
- name: Build Android Example App and Library
run: cd example/android && ./gradlew clean assembleDebug
spm:
name: SwiftPM package
runs-on: macos-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 22
# No `yarn install`: the script uses node builtins, `git` and the Swift
# toolchain the runner already ships. It does not build the package --
# see the comment at the top of the script for why that is not possible
# until React Native's SwiftPM autolinking lands here.
- name: Check SwiftPM package
run: node scripts/check-spm.mjs
ios:
runs-on: macos-latest
strategy:
Expand Down
19 changes: 14 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,26 @@ let reactHeaders: [Target.Dependency] = [
// 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"]
let unusedRootEntries = try! FileManager.default.contentsOfDirectory(atPath: Context.packageDirectory)
// `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)
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 }
let isFile = try! url.resourceValues(forKeys: [.isRegularFileKey]).isRegularFile == true
return isFile && (!sourceExtensions.contains(url.pathExtension)
// 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 }
Expand Down Expand Up @@ -63,7 +68,11 @@ let package = Package(
// Root the target here so its empty public module stays outside ios/.
path: ".",
exclude: unusedRootEntries + ["spm-support"] + unusedObjCIosEntries,
sources: ["ios"],
// 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: [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"pods": "cd example && pod-install --quiet",
"prepare": "bob build",
"release": "release-it",
"spm:check": "node scripts/check-spm.mjs",
"start": "react-native start",
"test": "jest",
"typescript": "tsc --noEmit",
Expand Down
Loading
Loading