#Libraries in Zig
1 messages · Page 1 of 1 (latest)
What do you mean by'library'? Are you wanting to make static/dynamic libraries that C code can call, or just Zig packages that other Zig code can use (i.e. compiled from source into another Zig project)?
well if you're making a zig package then it's pretty much ready for use in other zig code
it's mostly about configuring build script
No you add it through build zig
and then you @import it
check some zig libraries for examples
there are a few different options you could take
somewhere in project dir
but not higher than project root
So in the project
yes, usually people do "libs/" i do "deps/"
but note that you can't do "../*"
Also, isn't it better making .o files like C ?
Not really
no, not at all.
Not if a zig compilation is consuming it, you wouldn't do that without a specific reason
(like maybe it could speed up compilation times, if that's an issue)
if your library is for zig there's no reason to write a C api if you plan to use it in zig.
i think it would worsen the compilation time actually
oh really?
well zig caches artifacts
true
but I'm sure there would be situations where it's a win for compilation speed, though it doesn't feel ziggy
and either way, distributing .o files is a bad idea, .a exists for that reason.
Note that you can put the package source outside your build root (i.e. a directory that is not a child of where your root file is) by using packages in your build.zig
I am leaning towards a thought that it wouln't make a difference in compilation speed, however if you will want to edit something in lib and recompile it, it would take you quite a long time to do and then compile
i dont think you can?
You can
You can set up your source tree like this:
project_root/
- src/ <- we're going to build from a file in here
- deps/ <- external zig package source files
- build.zig
You can then have you're build.zig add packages from files in deps to compilations rooted in src
quote
it is... I guess we have a difference in terminology, by "build root" mean the main_pkg_path field of a LibExeObjStep
which is the thing that prevents you from doing @import("../*")
probably :P
Sorry I wasn't reading xD
Thanks for the help :D
Could you tell me more about build.zig too ?
build.zig is a file that gets compiled into an executable used for executing build steps
Yeah, I mean about the Builder
I mean it really depends on what you want to do - the builder builds a directed graph or steps, you get to decide what those steps do. The best way to learn about it is probably going to be to look at a few articles posted online (https://zig.news/xq/zig-build-explained-part-1-59lf comes to mind, not sure if it will contain anything that has changed since it was written), read the source code (look in lib/std/build.zig and lib/std/build/*, and if you want lib/build_runner.zig which is what executes build()), or you could search for and ask in #1019652020308824145 about specific things you want to accomplish.