Swifty-LLVM is a Swifty interface for the LLVM compiler infrastructure, currently wrapping LLVM's C API.
See also: swift-llvm-bindings
This package requires Swift 5.9
This package requires LLVM 17. Major versions of LLVM are not interchangeable or backward-compatible.
If you are using this package for development we strongly recommend the use of an LLVM with assertions enabled such as these; otherwise it's much too easy to violate LLVM's preconditions without knowing it.
If you want to build with the Swift Package Manager you'll need an
installation of LLVM with an llvm-config executable, which we will
use to create an pkg-config file for LLVM.
-
Configure: choose a build-directory and a CMake
build-type(usuallyDebugorRelease) and then, where is the path to the root directory of your LLVM installation,cmake -D CMAKE_BUILD_TYPE=<build-type> \ -D LLVM_DIR=<LLVM>/lib/cmake/llvm \ -G Ninja -S . -B <build-directory>(on Windows substitute your shell's line continuation character for
\or just remove the line breaks and backslashes).If you want to run tests, add
-D BUILD_TESTING.If this command fails it could be because you have an LLVM without CMake support installed; we suggest you try one of these packages instead.
-
Build:
cmake --build <build-directory> -
Test (requires
-D BUILD_TESTINGin step 1):ctest --parallel --test-dir <build-directory>
-
Generate Xcode project: choose a build-directory and then, where is the path to the root directory of your LLVM installation,
cmake -D LLVM_DIR=<LLVM>/lib/cmake/llvm \ -G Xcode -S . -B <build-directory>If you want to run tests, add
-D BUILD_TESTING. -
Profit: open the
.xcodeprojfile in the build-directory and use Xcode's UI to build.
Note: Windows support with Swift Package Manager is not guaranteed due to the instability of continuous integration (see issue 252 and Swifty-LLVM/issue 24).
First, you need to create a pkgconfig file specific to your
installation and make it visible to your build tools. We use a bash
script as follows in the top-level directory of this project:
./Tools/make-pkgconfig.sh ./llvm.pcif you are on Windows, your git installation (which is required for
Swift) contains a bash executable so you can do something like:
C:\Program Files\Git\bin\bash ./Tools/make-pkgconfig.sh ./llvm.pcThe command above generates llvm.pc in the current directory and
prints its contents to the terminal. You can either add its directory
to your PKG_CONFIG_PATH environment variable for use with
command-line tools:
export PKG_CONFIG_PATH=$PWDor you can put it somewhere that pkg_config already searches (needed
for use with Xcode):
sudo mkdir -p /usr/local/lib/pkgconfig && sudo mv llvm.pc /usr/local/lib/pkgconfig/Once llvm.pc is set up, you should be able to build this project
using Swift package manager:
swift build -c release- Add
platforms: [.macOS("xxx")]toPackage.swiftwherexxxis your macOS version to address the warning complaining that an "object file was built for newer macOS version than being linked". - You may need to add the path to
zstdlibrary inllvm.pc.