Skip to content

Commit

Permalink
Fix dynamic library copying for universal builds
Browse files Browse the repository at this point in the history
  • Loading branch information
stackotter committed Oct 31, 2021
1 parent 7b0e534 commit b167873
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Sources/swift-bundler/Subcommands/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ extension Bundler {
let packageFrameworksDir = productsDir.appendingPathComponent("PackageFrameworks")
let libDir = appContents.appendingPathComponent("lib")
try FileManager.default.createDirectory(at: libDir)

let contents = try FileManager.default.contentsOfDirectory(at: productsDir, includingPropertiesForKeys: nil, options: [])
for file in contents where file.pathExtension == "dylib" {
log.info("Copying '\(file.lastPathComponent)' to app bundle")
try FileManager.default.copyItem(at: file, to: libDir.appendingPathComponent(file.lastPathComponent))

// Update the executable's library path for this dylib
Shell.runSilently("install_name_tool -change @rpath/\(file.lastPathComponent) @rpath/../lib/\(file.lastPathComponent) \(executable.path)")
}

if FileManager.default.itemExists(at: packageFrameworksDir, withType: .directory) { // The app was built with Xcode
let contents = try FileManager.default.contentsOfDirectory(at: packageFrameworksDir, includingPropertiesForKeys: nil, options: [])
for framework in contents where framework.pathExtension == "framework" {
Expand All @@ -122,15 +132,6 @@ extension Bundler {
// Update the executable's library path for this framework
Shell.runSilently("install_name_tool -change @rpath/\(libName).framework/Versions/A/\(libName) @rpath/../lib/lib\(libName).dylib \(executable.escapedPath)")
}
} else { // The app was built with SwiftPM
let contents = try FileManager.default.contentsOfDirectory(at: productsDir, includingPropertiesForKeys: nil, options: [])
for file in contents where file.pathExtension == "dylib" {
log.info("Copying '\(file.lastPathComponent)' to app bundle")
try FileManager.default.copyItem(at: file, to: libDir.appendingPathComponent(file.lastPathComponent))

// Update the executable's library path for this dylib
Shell.runSilently("install_name_tool -change @rpath/\(file.lastPathComponent) @rpath/../lib/\(file.lastPathComponent) \(executable.path)")
}
}
} catch {
terminate("Failed to copy dynamic libraries to app bundle; \(error)")
Expand Down

0 comments on commit b167873

Please sign in to comment.