Swift/bridging location

I can see swift/bridging installed relative usr/include in the snapshots, but this doesn't appear to be in the default clang include path. Adding unsafe flags to my package is undesirable, of course. Is there a workaround?

$ ls /opt/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-07-10-a-ubuntu22.04-aarch64/usr/include/swift/bridging

Copy the bridging file into your project, include it in your modulemap file and include it the way you would :grinning:

swift/bridging is a Swift C++ header though, not an ObjC bridging header – I'd rather not copy and paste that.

The header is typically placed into /usr/include/swift provided your Swift toolchain is installed in the root of the filesystem. In this case since you're using a different location for your Swift toolchain you need to manually pass the /opt/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-07-10-a-ubuntu22.04-aarch64/usr/include path to Clang and Swift, using the -I /opt/swift-5.9-DEVELOPMENT-SNAPSHOT-2023-07-10-a-ubuntu22.04-aarch64/usr/include flag for both compilers.

Ah, sure. There’s no SPM magic to get the toolchain root?

This doesn't work :face_with_raised_eyebrow:

As a workaround, I'm using the following in Package.swift:

import Foundation

func tryGuessSwiftLibRoot() -> String { 
    let task = Process()
    task.executableURL = URL(fileURLWithPath: "/bin/sh")
    task.arguments = ["-c", "which swift"]
    task.standardOutput = Pipe()
    do {
        try task.run()
        let outputData = (task.standardOutput as! Pipe).fileHandleForReading.readDataToEndOfFile()
        let path = URL(fileURLWithPath: String(decoding: outputData, as: UTF8.self))
        return path.deletingLastPathComponent().path + "/../lib/swift"
    } catch {
        return "/usr/lib/swift"

let SwiftLibRoot = tryGuessSwiftLibRoot()

You can then add SwiftLibRoot to the include and library paths as appropriate.

Thanks. But can you provide a link to the package.swift for more context please?