Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ PLENARY_DIR ?= ../plenary.nvim
MINI_DIR ?= ../mini.nvim

PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig

# Compile-time cfg that gates the watcher + git-status fuzz stress test.
STRESS_RUSTFLAGS := --cfg stress
Expand Down Expand Up @@ -50,38 +52,25 @@ build:
build-e2e:
cargo build --release -p fff-nvim -p fff-c --no-default-features --features zlob

# Build the C library, header, and pkg-config file via cargo-c.
build-c-lib:
cargo build --release -p fff-c --no-default-features --features zlob
@command -v cargo-cbuild >/dev/null 2>&1 || { echo "error: cargo-c is required to build the C library. Install it with: cargo install cargo-c" >&2; exit 1; }
cargo cbuild -p fff-c --release --no-default-features --features zlob --prefix=$(PREFIX) --bindir=$(BINDIR) --libdir=$(LIBDIR) --includedir=$(INCLUDEDIR) --pkgconfigdir=$(PKGCONFIGDIR)

header:
cbindgen --config crates/fff-c/cbindgen.toml --crate fff-c --output crates/fff-c/include/fff.h

# Install the C library and header under $(PREFIX) (default /usr/local).
# Override PREFIX for user-local installs, e.g. `make install PREFIX=$$HOME/.local`.
# DESTDIR is honoured for packagers.
# Install the C library, header, and pkg-config file via cargo-c.
install: build-c-lib
install -d $(DESTDIR)$(LIBDIR)
install -d $(DESTDIR)$(INCLUDEDIR)
install -m 0644 crates/fff-c/include/fff.h $(DESTDIR)$(INCLUDEDIR)/fff.h
@if [ -f target/release/libfff_c.dylib ]; then \
install -m 0755 target/release/libfff_c.dylib $(DESTDIR)$(LIBDIR)/libfff_c.dylib; \
echo "Installed $(DESTDIR)$(LIBDIR)/libfff_c.dylib"; \
fi
@if [ -f target/release/libfff_c.so ]; then \
install -m 0755 target/release/libfff_c.so $(DESTDIR)$(LIBDIR)/libfff_c.so; \
echo "Installed $(DESTDIR)$(LIBDIR)/libfff_c.so"; \
fi
@if [ -f target/release/fff_c.dll ]; then \
install -m 0755 target/release/fff_c.dll $(DESTDIR)$(LIBDIR)/fff_c.dll; \
echo "Installed $(DESTDIR)$(LIBDIR)/fff_c.dll"; \
fi
@echo "Installed header $(DESTDIR)$(INCLUDEDIR)/fff.h"
@command -v cargo-cinstall >/dev/null 2>&1 || { echo "error: cargo-c is required to install the C library. Install it with: cargo install cargo-c" >&2; exit 1; }
cargo cinstall -p fff-c --release --no-default-features --features zlob --prefix=$(PREFIX) --bindir=$(BINDIR) --libdir=$(LIBDIR) --includedir=$(INCLUDEDIR) --pkgconfigdir=$(PKGCONFIGDIR) $(if $(DESTDIR),--destdir=$(DESTDIR),)

uninstall:
rm -f $(DESTDIR)$(LIBDIR)/libfff_c.dylib
rm -f $(DESTDIR)$(LIBDIR)/libfff_c.so
rm -f $(DESTDIR)$(LIBDIR)/fff_c.dll
rm -f $(DESTDIR)$(LIBDIR)/libfff_c.*
rm -f $(DESTDIR)$(LIBDIR)/fff_c.*
rm -f $(DESTDIR)$(BINDIR)/fff_c.dll
rm -f $(DESTDIR)$(INCLUDEDIR)/fff.h
rm -f $(DESTDIR)$(PKGCONFIGDIR)/fff_c.pc
@echo "Removed fff-c from $(DESTDIR)$(PREFIX)"

test-setup:
Expand Down
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -664,25 +664,33 @@ Native rust crate that is performing all the search. Stable and well documented.

### Build

Building and installing the C library requires [cargo-c](https://crates.io/crates/cargo-c):

```bash
# Builds only the C cdylib (fastest):
cargo install cargo-c
```

```bash
# Builds the C library, header, and pkg-config file:
make build-c-lib

# or directly with cargo:
cargo build --release -p fff-c --features zlob
# or directly with cargo-c:
cargo cbuild -p fff-c --release --no-default-features --features zlob
```

> The `zlob` feature (requires the [Zig](https://ziglang.org) toolchain) switches both
> glob matching **and** filesystem traversal to [zlob](https://github.com/dmtrKovalenko/zlob)'s
> native parallel walker. Without it, the default build uses the pure-Rust
> [`ignore`](https://crates.io/crates/ignore) (ripgrep) walker and `globset`.

The output is a `cdylib` (`libfff_c.so` / `libfff_c.dylib` / `fff_c.dll`). The header lives at [`crates/fff-c/include/fff.h`](./crates/fff-c/include/fff.h).
The output includes dynamic libraries (`libfff_c.so` / `libfff_c.dylib` / `fff_c.dll`) and a static library (`libfff_c.a` / `fff_c.lib`). The header lives at [`crates/fff-c/include/fff.h`](./crates/fff-c/include/fff.h).

Prebuilt binaries for every version, including every commit on main, are on the [releases page](https://github.com/dmtrKovalenko/fff/releases). The same binaries also ship inside the `@ff-labs/fff-bin-*` npm packages.

### Install

Then install via `make install`:

```bash
# System-wide (needs sudo):
sudo make install
Expand All @@ -694,11 +702,21 @@ make install PREFIX=$HOME/.local
make install DESTDIR=/tmp/pkgroot PREFIX=/usr
```

Drops `libfff_c.{so,dylib,dll}` into `$(PREFIX)/lib` and the header into `$(PREFIX)/include/fff.h`. Remove with `make uninstall`, which honours the same `PREFIX` and `DESTDIR`.
Or directly with `cargo-c`:

```bash
cargo cinstall -p fff-c --release --no-default-features --features zlob --prefix=/usr/local
```

Installs `libfff_c.{so,dylib}` and `libfff_c.a` into `$(PREFIX)/lib` on Unix. On Windows, it installs `fff_c.dll` into `$(BINDIR)` and `fff_c.lib` into `$(PREFIX)/lib`. It also installs the header into `$(PREFIX)/include/fff.h` and `fff_c.pc` into `$(PKGCONFIGDIR)`. Remove with `make uninstall`, which honours the same `PREFIX` and `DESTDIR`.

Link against it after install:

```bash
# Using pkg-config:
cc my_app.c $(pkg-config --cflags --libs fff_c) -o my_app

# Or directly:
cc my_app.c -lfff_c -o my_app
```

Expand Down
7 changes: 6 additions & 1 deletion crates/fff-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ license = "MIT"
workspace = true

[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "staticlib"]

[package.metadata.capi.header]
name = "fff"
subdirectory = false

[features]
default = ["ripgrep"] # use ripgrep base crates to avoid requiring zig for rust crate
capi = []
ripgrep = ["fff/ripgrep", "fff-query-parser/ripgrep"]
zlob = ["fff/zlob", "fff-query-parser/zlob"]

Expand Down
Loading