feat(fzf): embed fzf binary #26

Merged
maleszka merged 8 commits from feature/embed-fzf into main 2026-07-01 20:56:50 +02:00
Collaborator

closes #24, allows for the embedding of a statically-compiled fzf binary into wbij itself.

adds two compile options:

  • embed_fzf (bool, defaults to false): whether to embed fzf
  • fzf_path (?[]const u8): where to take the fzf binary from

and a struct FzfBinProvider, which resolves the fzf path (or deploys our own if a cache is available)

closes #24, allows for the embedding of a statically-compiled fzf binary into wbij itself. adds two compile options: - `embed_fzf` (`bool`, defaults to `false`): whether to embed fzf - `fzf_path` (`?[]const u8`): where to take the fzf binary from and a struct `FzfBinProvider`, which resolves the fzf path (or deploys our own if a cache is available)
Author
Collaborator

for example, to test with latest (as of writing) prebuilt static fzf:

wget https://github.com/junegunn/fzf/releases/download/v0.73.1/fzf-0.73.1-linux_amd64.tar.gz -qO fzf-latest.tar.gz
tar xf fzf-latest.tar.gz
zig build -Dembed_fzf -Dfzf_path=./fzf run -- [args...]
for example, to test with latest (as of writing) prebuilt static fzf: ```sh wget https://github.com/junegunn/fzf/releases/download/v0.73.1/fzf-0.73.1-linux_amd64.tar.gz -qO fzf-latest.tar.gz tar xf fzf-latest.tar.gz zig build -Dembed_fzf -Dfzf_path=./fzf run -- [args...] ```
kbity changed title from WIP: feat(fzf): embed fzf binary to feat(fzf): embed fzf binary 2026-05-27 15:34:49 +02:00
maleszka left a comment

thanks! awesome work

thanks! awesome work
build.zig Outdated
@ -30,0 +37,4 @@
} else if (fzf_path != null) {
std.log.info("-Dfzf_path=... has no effect without -Dembed_fzf", .{});
}
Owner

This relation between embed_fzf and fzf_path you can solve this way that embed_fzf in itself is ?[]const u8 and it accepts path for fzf bin

This relation between `embed_fzf` and `fzf_path` you can solve this way that `embed_fzf` in itself is `?[]const u8` and it accepts path for fzf bin
Author
Collaborator

fair point, sounds good

fair point, sounds good
kbity marked this conversation as resolved
@ -0,0 +31,4 @@
_ = self;
}
/// Removes potentially created temporary files
Owner

add build module also to mod module. This way, you will be able to import build directly here.

add `build` module also to `mod` module. This way, you will be able to import `build` directly here.
Author
Collaborator

i'm having some issues with Zig complaining about build existing in multiple files (src/fzf/FzfBinProvider.zig:1:1: error: file exists in modules 'build' and 'build0'); do you happen to know any tricks i could use to get around that?

i'm having some issues with Zig complaining about `build` existing in multiple files (`src/fzf/FzfBinProvider.zig:1:1: error: file exists in modules 'build' and 'build0'`); do you happen to know any tricks i could use to get around that?
kbity marked this conversation as resolved
src/root.zig Outdated
@ -17,3 +18,3 @@
queried_for_nondefault: bool, // referenced in select{Account,Contest,CodeLang}
pub fn init(allocator: std.mem.Allocator, args: anytype) !Wbij {
pub fn init(allocator: std.mem.Allocator, args: anytype, comptime has_embedded_fzf: bool) !Wbij {
Owner

you don't need it if you add build module to mod module in build.zig; you can source build directly then

you don't need it if you add `build` module to `mod` module in `build.zig`; you can source `build` directly then
kbity marked this conversation as resolved
Owner

Will you manage to add fzf as submodule and add fzf build step inside build.zig directly? Then you can import fzf binary as a build artifact into wbij.

You can compile fzf with the following commands for static compilation:

export CGO_ENABLED=0
export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
make
make bin/fzf
Will you manage to add `fzf` as submodule and add fzf build step inside `build.zig` directly? Then you can import fzf binary as a build artifact into wbij. You can compile fzf with the following commands for static compilation: ``` export CGO_ENABLED=0 export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw" make make bin/fzf ```
kbity force-pushed feature/embed-fzf from 4eb3501505 to 9de1c7ee6a 2026-06-18 10:25:23 +02:00 Compare
Owner

I rewrote the saving logic of embedded binary to disk. Now:

  • binary persists across sessions
  • is it safe for multiple wbij instances to use one cache dir
  • there is a simple yet correct implementation of cache staleness detection (I save binary to a filename which is calculated basing on the binary contents)

The intended usage:

wget https://github.com/junegunn/fzf/releases/download/v0.73.1/fzf-0.73.1-linux_amd64.tar.gz -qO fzf-latest.tar.gz
tar xf fzf-latest.tar.gz
zig build -Dfzf_path=fzf run -- [args...]
I rewrote the saving logic of embedded binary to disk. Now: - binary persists across sessions - is it safe for multiple wbij instances to use one cache dir - there is a simple yet correct implementation of cache staleness detection (I save binary to a filename which is calculated basing on the binary contents) The intended usage: ``` wget https://github.com/junegunn/fzf/releases/download/v0.73.1/fzf-0.73.1-linux_amd64.tar.gz -qO fzf-latest.tar.gz tar xf fzf-latest.tar.gz zig build -Dfzf_path=fzf run -- [args...] ```
maleszka deleted branch feature/embed-fzf 2026-07-01 20:56:50 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
maleszka/wbij!26
No description provided.