A package that wraps ripgrep and provides a Swift interface
SwiftyRipgrep
This repository contains a Swift package that wraps ripgrep to be used programmatically in iOS (device and simulator) and macOS.
Usage
SwiftyRipgrep is distributed as a Swift Package. All you need to do is to add the dependency to your project through Xcode or in the Package.swift
of your package:
let package = Package(
...
dependencies: [
.package(url: "https://github.com/chimerarun/SwiftyRipgrep.git", from: "13.0.0")
],
...
)
Version: The version of SwiftyRipgrep aligns with the version of Ripgrep wrapped so version 13.0.0 indicates that the Swift package is using the same version of Ripgrep.
Development
System dependencies
We recommend the usage of asdf to install the dependencies necessary to contribute to this project:
- Ruby 3.1.2
- Rust
- swift-bridge-cli
Generate the Swift Package
The project uses swift-bridge, a Rust tool that leverages macros and other build-time tools to generate the Swift Package from the Rust code. If you change the Rust code or update Cargo dependencies you’ll have to run bin/generate.rb
. The script will update the Package.swift
and the content under Sources
and generate a RustXcframework.xcframework
directory at the root.
Testing the generated Swift package
The repository contains a Swift package under fixture
that contains a tests target to test the public interface of the SwiftyRipgrep
package generated at the root. You can run the tests by running swift test --package-path ./fixture
References
- From Rust to Swift
- Grep Crate
- Cocoa CPU Architectures
- swift-create-xcframework GitHub action
- XCFrameworks
- Recipe for Calling Swift Closures from Asynchronous Rust Code
- Building and Deploying a Rust library on iOS
- The swift-bridge book