Skip to content

Commit 2224a80

Browse files
committed
SwiftUsd:
Made MethodsReturningReferences be borrowing by default Build system: Add support for iOS/visionOS simulator builds of SwiftUsd/OpenUSD Cherry pick PixarAnimationStudios/OpenUSD#3707 to add support for compiling for iOS/visionOS simulator Add support for Intel and macOS Universal binaries Scripts: Add a `--force` flag to make-swift-package. Now, it will abort if you try to run it and the `generatedPackageDir` already exists unless you use `--force`. Change how ShellUtil.runCommandAndGetOutput works to avoid swiftlang/swift#57827
1 parent 83df043 commit 2224a80

10 files changed

Lines changed: 330 additions & 110 deletions

File tree

Examples/HelloSwiftUsd_CLI_SPM/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let package = Package(
2525
name: "HelloSwiftUsd_SPM",
2626
platforms: [.macOS(.v15)],
2727
dependencies: [
28-
.package(url: "https://github.com/apple/SwiftUsd", from: "5.0.2"),
28+
.package(url: "https://github.com/apple/SwiftUsd", from: "5.2.0"),
2929
],
3030
targets: [
3131
.executableTarget(

SwiftUsd.docc/AboutThisRepo/ReleaseChecklist.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Checklist for releasing new versions of SwiftUsd
4949
1. [Getting Started, "Swift Package"](<doc:GettingStarted#Swift-Package>)
5050
1. make-spm-tests.py in SwiftUsdTests
5151
1. project.pbxproj in SwiftUsdTests
52+
1. project.pbxproj for each Xcode project in Examples
5253
1. If files have been added or removed, update [Miscellaneous, "Repo structure"](<doc:Miscellaneous#Repo-structure>)
5354
1. Update [Ongoing Work](<doc:OngoingWork>)
5455
1. Update the [Change Log](<doc:ChangeLog>)

SwiftUsd.docc/TechnicalDetails/ChangesToOpenUSD.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ These changes fix bugs or add features to Usd that aren't part of vanilla OpenUS
1414
- Cherry pick 4cf5fee816332f98af626f44a5cd852e06093e08 to avoid increasing memory footprint when using UsdImagingGLEngine on macOS:
1515
- Modified: `pxr/imaging/hdx/taskControllerSceneIndex.cpp`
1616

17+
- Cherry pick https://github.com/PixarAnimationStudios/OpenUSD/pull/3707 to add support for compiling for iOS simulator:
18+
- Modified: `build_scripts/apple_utils.py`
19+
- Modified: `build_scripts/build_usd.py`
20+
1721
#### Swift-specific changes to OpenUSD before building
1822
These changes work around Swift-specific issues in vanilla OpenUSD, add Swift-specific features, and work around issues in the Swift compiler.
1923
- Header modularization fixes:

openusd-patch.patch

Lines changed: 218 additions & 45 deletions
Large diffs are not rendered by default.

scripts/make-swift-package/Sources/CLIArgs.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ struct CLIArgs: AsyncParsableCommand {
8888
""")
8989
var artifactsHostingURL: String?
9090

91-
91+
@Flag(help: """
92+
If `generatedPackageDir` already exists, make-swift-package will exit to avoid overwriting it
93+
unless --force is passed
94+
""")
95+
var force: Bool = false
9296

9397

9498

scripts/make-swift-package/Sources/FileSystemInfo.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,19 @@ struct FileSystemInfo {
138138
switch $0.lastPathComponent {
139139
case "ios-arm64": return ".iOS"
140140
case "macos-arm64": return ".macOS"
141+
case "macos-x86_64": return ".macOS"
142+
case "macos-arm64_x86_64": return ".macOS"
143+
case "ios-arm64-simulator": return ".iOS"
144+
case "xros-arm64": return ".visionOS"
145+
case "xros-arm64-simulator": return ".visionOS"
141146
case "Info.plist": return nil
142147
default:
143148
print("Warning: Unknown xcframework platform subdirectory: \($0.lastPathComponent)")
144149
return $0.lastPathComponent
145150
}
146151
}
147152

148-
return ".when(platforms: [\(subdirNames.joined(separator: ", "))])"
153+
return ".when(platforms: [\(Set(subdirNames).sorted().joined(separator: ", "))])"
149154
}
150155

151156
}
@@ -414,7 +419,6 @@ fileprivate func _getSwiftUsdRepoURL() -> URL {
414419
fileprivate func getPlatformNameForDylib(_ dylib: URL) async throws -> String {
415420
#if canImport(Darwin)
416421
let vtoolOutput = try await ShellUtil.runCommandAndGetOutput(arguments: ["vtool", "-show-build", dylib])
417-
.reduce([]) { $0 + [$1] }
418422
guard let platformLine = vtoolOutput.first(where: { $0.trimmingCharacters(in: .whitespaces).starts(with: "platform")} ) else {
419423
throw ValidationError("vtool -show-build parsing failure")
420424
}
@@ -424,6 +428,9 @@ fileprivate func getPlatformNameForDylib(_ dylib: URL) async throws -> String {
424428
switch platform {
425429
case "MACOS": return "macOS"
426430
case "IOS": return "iOS"
431+
case "IOSSIMULATOR": return "iOSSimulator"
432+
case "VISIONOS": return "visionOS"
433+
case "VISIONOSSIMULATOR": return "visionOSSimulator"
427434
default:
428435
print("Warning! Unknown vtool platform \(platform)")
429436
return platform

scripts/make-swift-package/Sources/Framework.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ struct Framework: Sendable {
240240
/// Greps for `cmd` in the load commands of the dylib,
241241
/// returning the path associated with the command
242242
private func grepOtool(_ cmd: String) async -> [String] {
243-
let otoolOutput = try! await ShellUtil.runCommandAndGetOutput(arguments: ["otool", "-l", fsInfo.dylib]).reduce([]) { $0 + [$1] }
243+
let otoolOutput = try! await ShellUtil.runCommandAndGetOutput(arguments: ["otool", "-l", fsInfo.dylib])
244244

245245
var result = [String]()
246246

@@ -402,15 +402,15 @@ struct Framework: Sendable {
402402
var result = [URL]()
403403
do {
404404
// Just use `otool` and extract the `@rpath` dylibs, relative to the `lib_dir`
405-
for try await line in try! ShellUtil.runCommandAndGetOutput(arguments: ["otool", "-L", dylib]) {
405+
for line in try! await ShellUtil.runCommandAndGetOutput(arguments: ["otool", "-L", dylib]) {
406406
let pattern = #/\s*@rpath/(.*\.dylib) \(compatibility version .*, current version .*\)/#
407407
if let match = line.wholeMatch(of: pattern)?.output.1 {
408408
let toAppend = usdInstall.libDir.appending(path: match)
409409
if !FileManager.default.fileExists(at: toAppend) {
410410
// otool -L told us about an rpath dependency we can't find.
411411
// if this happens because the dependency is itself, that's okay.
412412
// (otool -L outputs the shared library ID when ran on a shared library)
413-
let sharedLibraryId = (try! await ShellUtil.runCommandAndGetOutput(arguments: ["otool", "-D", dylib]).reduce([]) { $0 + [$1] })[1]
413+
let sharedLibraryId = (try! await ShellUtil.runCommandAndGetOutput(arguments: ["otool", "-D", dylib]))[1]
414414
if sharedLibraryId.wholeMatch(of: #/@rpath/(.*\.dylib)/#)?.output.1 == match {
415415
continue
416416
} else {
@@ -435,8 +435,6 @@ struct Framework: Sendable {
435435
print("Did you mean to use `--ignore-paths` or `--ignore-homebrew` when building OpenUSD?")
436436
}
437437
}
438-
} catch {
439-
fatalError(String(describing: error))
440438
}
441439

442440
return result

scripts/make-swift-package/Sources/SwiftPackage.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ struct SwiftPackage {
6565
}
6666

6767
private func setupDirectoryStructure() async throws {
68+
if fm.fileExists(atPath: fsInfo.swiftUsdPackage.generatedSwiftPackageDir.path(percentEncoded: false)) {
69+
if cliArgs.force {
70+
try! fm.removeItem(at: fsInfo.swiftUsdPackage.generatedSwiftPackageDir)
71+
} else {
72+
print("Error: \(fsInfo.swiftUsdPackage.generatedSwiftPackageDir.relativePath) already exists.")
73+
print("Choose another destination, or pass `--force` to overwrite it.")
74+
throw ValidationError("\(fsInfo.swiftUsdPackage.generatedSwiftPackageDir.relativePath) already exists but `--force` wasn't passed")
75+
}
76+
}
6877
try! fm.createDirectory(at: fsInfo.swiftUsdPackage.generatedSwiftPackageDir, withIntermediateDirectories: true)
6978
try! fsInfo.packageConfigInfo.write(to: fsInfo.packageConfigInfoUrl, atomically: true, encoding: .utf8)
7079
try! fm.createDirectory(at: fsInfo.swiftUsdPackage.tmpDir, withIntermediateDirectories: true)
@@ -132,7 +141,7 @@ struct SwiftPackage {
132141
let dest = cliArgs.checksummedArtifactsDir!.appending(path: "\(src.lastPathComponent).zip")
133142
try await ShellUtil.runCommandAndWait(arguments: ["ditto", "-c", "-k", "--sequesterRsrc", src, dest])
134143

135-
let opensslOutput = try await ShellUtil.runCommandAndGetOutput(arguments: ["openssl", "dgst", "-sha256", dest]).reduce([]) { $0 + [$1] }
144+
let opensslOutput = try await ShellUtil.runCommandAndGetOutput(arguments: ["openssl", "dgst", "-sha256", dest])
136145
guard let checksum = opensslOutput[0].wholeMatch(of: #/SHA256\(.*\.xcframework\.zip\)= ([0-9a-f]*)/#)?.output.1 else {
137146
throw ValidationError("openssl checksumming error! Got \(opensslOutput)")
138147
}
@@ -311,6 +320,7 @@ struct SwiftPackage {
311320
"module \(moduleName) {",
312321
" // \(shortName) is not available on embedded platforms",
313322
" requires !ios",
323+
" requires !xros",
314324
"}"
315325
]
316326
} else {

scripts/make-swift-package/Sources/Util.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ extension ShellUtil {
196196
}
197197
}
198198
#endif
199-
200-
public static func runCommandAndGetOutput(arguments: [any Argument], exitOnSigint: Bool = true) throws -> ShellUtilCommandOutput {
199+
200+
public static func runCommandAndGetOutput(arguments: [any Argument], exitOnSigint: Bool = true) async throws -> [String] {
201201
let output = Pipe()
202202

203203
let process = Process()
@@ -210,12 +210,13 @@ extension ShellUtil {
210210
process.executableURL = URL(filePath: "/bin/bash")
211211
process.arguments = ["-c", arguments.map { $0.asSpaceEscapedString() }.joined(separator: " ")]
212212
try process.run()
213-
214-
#if os(macOS)
215-
return output.fileHandleForReading.bytes.lines
216-
#else
217-
return .init(output.fileHandleForReading)
218-
#endif
213+
214+
let result = try await output.fileHandleForReading.bytes.lines.map { $0 }.reduce([]) { $0 + [$1] }
215+
216+
try output.fileHandleForReading.close()
217+
try output.fileHandleForWriting.close()
218+
219+
return result
219220
}
220221

221222
public static func runCommandAndWait(arguments: [any Argument], currentDirectoryURL: URL? = nil, exitOnSigint: Bool = true, quiet: Bool = false) async throws {

0 commit comments

Comments
 (0)