natecraddock / zf

a commandline fuzzy finder and zig package designed for filtering filepaths
MIT License
451 stars 14 forks source link

Which Zig version works? #44

Closed mizlan closed 1 year ago

mizlan commented 1 year ago

Attempting to build tag 0.8.0 from source with Zig 0.10.1, which is the "latest stable Zig" as specified in the readme, fails with this error:

Unrecognized argument: -fsummary

Edit: the above is my bad, the option is not present in the readme in 0.8.0, however I'm still running into problems.

If I omit that flag I run into dependency errors, which is reasonable since I don't have ziglyph package on my system, but I don't know how 0.8.0 brought that dependency in. There is no .zon file in that tree.

I would overall like clearer instructions for how to build zf for someone with minimal Zig knowledge.

edit: nevermind, i figured it all out (git submodules) i'm a bit dumb, i'm getting there hehe

mizlan commented 1 year ago

I've successfully compiled! One question though: how may I get the .a and .so files for the C library? I will need both of them.

natecraddock commented 1 year ago

@mizlan Looks like I should add some better instructions for how to set up zf for those unfamiliar with Zig :)

To compile the library, I would do the following

$ zig build-lib -OReleaseSafe -static src/clib.zig
$ zig build-lib -OReleaseSafe -dynamic src/clib.zig

And in this case, you don't even need to clone the submodule because the fuzzy finding interface doesn't (currently) require ziglyph.

You can also specify the exact output filename with the -femit-bin=<path> option. And you can look at the justfile in my telescope-zf-native.nvim project for an example of cross-compiling.

There currently isn't a header file so you will have to make your own. I'm happy to help with that too if you need it.

mizlan commented 1 year ago

Got it! Now I ran objdump -t libzf.a but it doesnt seem like there are exported symbols that are function names?

natecraddock commented 1 year ago

I just wrote this simple C program to test

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

// declare the external function
double rank(
    const char *str,
    const char **tokens,
    uint64_t num_tokens,
    bool case_sensitive,
    bool plain
);

int main() {

    const char *tokens[1] = { "t" };
    double r = rank("test", tokens, 1, true, false);
    printf("the rank: %f\n", r);

    return 0;
}

And compiled with zig cc main.c libzf.a. I executed the output a.out file and everything works for me.

And I'm not an expert on the output of objdump, so I'm not sure why the symbols don't show the functions. But things do work... :)

mizlan commented 1 year ago

There currently isn't a header file so you will have to make your own. I'm happy to help with that too if you need it.

Hmm. I think I will need one. I think the build system I'm using right now uses -c to skip linking.

Edit: going to try -femit-h

mizlan commented 1 year ago

Seems like it is a bit sketchy getting zig.h which is included when using -femit-h. There are a number of open github issues e.g., https://github.com/ziglang/zig/pull/14576

natecraddock commented 1 year ago

Okay, let me take some time to write some better docs and an .h file and I'll let you know when that's ready.

I think the build system I'm using right now uses -c to skip linking.

If you don't mind sharing, it would be helpful to know more about what you are doing. It might give more context into how I can assist

mizlan commented 1 year ago

I think I've resolved everything to do with the Zig side, but unfortunately the API I'm using on the other end (ocaml-ctypes, with dune) is still experimental, so I think I will port the zf algorithm to OCaml actually. I will take a read through the (very tidy!) codebase.

natecraddock commented 1 year ago

I think I've resolved everything to do with the Zig side, but unfortunately the API I'm using on the other end (ocaml-ctypes, with dune) is still experimental

Unfortunate :( I hope your OCaml version works well!