First project for Apple platforms
This page builds LZ4 for macOS, iOS and the iOS simulator and calls it from Swift. You need otok (installed) and Xcode.
Describe the project
Section titled “Describe the project”In your app’s directory (or an empty one), create otok.toml:
[otok]format = 1
[apple]platforms = ["macosx", "ios", "iossim"]deployment = { macos = "14.0", ios = "17.0" }
[deps.lz4]recipe = "apotocki/lz4"version = "~> 1.10"[apple]is the target.platformslists what you ship:ios,iossim,macosx,catalyst,tvos,tvossim,watchos,watchossim,xros,xrossim. Each is built for all its architectures (arm64andx86_64for the simulators and macOS) unlessarchitecturesnarrows it.deploymentgives the minimum OS versions. They are required: otok does not take Xcode’s default, which changes with every Xcode.[deps.lz4]asks for the librarylz4, built by the recipeapotocki/lz4of the public index, at version 1.10 or a later 1.x.
Install
Section titled “Install”otok installotok.lock created: added lz4 1.11.0 (r1) tool added cmake 4.4.5 (r1) tool added ninja 1.13.2 (r1) tool added python 3.14.10 (r1)...built lz4 1.11.0 for ios-arm64 (3.9 s), 3 of 5 slices...packaging lz4 1.11.0 for appleoutput 'Otok': 1 copied, 0 unchanged, 0 removedotok chose the newest version the constraint allows, wrote it into otok.lock, fetched the sources and built LZ4
for every platform and architecture (a slice each) with the CMake and Ninja of their own recipes. The first run
takes a while; the next ones, in this project or any other, take the builds from the cache.
Commit otok.toml and otok.lock: the lock pins every version, recipe and source by its hash, so another machine
running otok install builds the same libraries. Otok/ is generated: add it to .gitignore.
Otok/ is a Swift package:
Otok/ Package.swift the products of all libraries: here LZ4 Packages/lz4/ lz4_lz4.xcframework every platform's slices shims/LZ4/ the product's privacy manifest and link settings Acknowledgements.md the licenses of everything built, for your about screen Acknowledgements.plist the same as a Settings.bundle page otok-config.cmake the same products for CMakeUse it in Xcode
Section titled “Use it in Xcode”- File → Add Package Dependencies…, then Add Local…, and choose the
Otokdirectory. - Add the product LZ4 to your app target.
- Import the module:
import LZ4
print("LZ4 \(String(cString: LZ4_versionString()))")The library’s privacy manifest comes with the product; App Store finds it in your app.
Use it from a Swift package
Section titled “Use it from a Swift package”import PackageDescription
let package = Package( name: "Hello", platforms: [.macOS(.v14)], dependencies: [.package(path: "Otok")], targets: [ .executableTarget(name: "Hello", dependencies: [.product(name: "LZ4", package: "Otok")]), ])swift runLZ4 1.11.0Use it from CMake
Section titled “Use it from CMake”For a CMake project (3.28 or later, any generator, Xcode’s included):
find_package(Otok CONFIG REQUIRED PATHS "${CMAKE_SOURCE_DIR}/Otok" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)target_link_libraries(app PRIVATE otok::LZ4)otok::LZ4 brings the XCFramework’s slice for the platform you build for, its headers and its link settings.
- Coming from CocoaPods: what a Podfile becomes.
- Options, profiles and configurations of the libraries you build.
- Updating:
otok updatemoves to newer versions and rewrites the lock. - The
otok.tomlreference.
© 2026 Alexander A Pototskiy and contributors. Text CC BY 4.0; examplesCC0.