I'm trying to use LLVMSwift as a package dependency in an Xcode project. However, for one reason or another, the build always links against the libc++ in my Homebrew-managed LLVM installation, rather than the system copy. This is a problem because I want to distribute the built products to people who don't have LLVM installed through Homebrew (everything is statically linked except libc++).
Now, I know I said I wanted to build through Xcode, but I tried using the package in a vanilla SwiftPM build process and I have the same problem.
Here is a (consumer) Package.swift demonstrating the problem:
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "llvmtest",
platforms: [
.macOS(.v10_14)
],
dependencies: [
.package(url: "https://github.com/ThatsJustCheesy/LLVMSwift", .branch("llvm-9"))
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "llvmtest",
dependencies: [
"LLVM"
]),
]
)
For a build to work, you'll need to have LLVM installed via brew
and have run the make-pkgconfig.swift
script (see LLVMSwift/README.md#installation).
After a swift build
, otool -L .build/debug/llvmtest
produces:
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11)
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
/usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.9.0)
/usr/local/opt/llvm/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
@rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 1100.8.255)
@rpath/libswiftFoundation.dylib (compatibility version 1.0.0, current version 0.0.0)
All of these entries are expected except for /usr/local/opt/llvm/lib/libc++.1.dylib
. For my binary to be portable, I'm under the impression this will have to either be changed to /usr/lib/libc++.1.dylib
or be relative to @rpath
, but I cannot for the life of me figure out how to do this (I've been trying for almost an entire day). Any pointers on how to force linking the system stdlib, and/or why the copy in /usr/local/opt/llvm
is being used at all? I assume it has something to do with the interactions between the cllvm.pc pkg-config file and the linker input, but the exact interactions that make this happen are still a mystery to me.
Thanks for your time and any explanations or advice!