#Please help with the placement of the include/zeb.h library in my repository

1 messages · Page 1 of 1 (latest)

leaden pilot
#

When people use build.zig.zon in their project(created by just zig init-exe), they get an error: "Can't find <zeb.h>" which I have included inside zeb.zig file present inside src directory.
Repo link: https://github.com/RohanVashisht1234/zeb

  • How should I tell them to change their build.zig in a way that it imports zeb.zig as well as provides zeb.h to zeb.zig library?
  • How should I change my build.zig so that it considers zeb.h?
GitHub

An extremely fast backend Framework for Zig. Contribute to RohanVashisht1234/zeb development by creating an account on GitHub.

toxic lake
#

I'm not familiar enough with the Zig build system to really be able to offer much here

#

However

#

It might be something along the lines of them using b.dependency("zeb") followed by exe.root_module.addImport("zeb", that.module("zeb"));
They would then point their build.zig.zon to either the .tar.gz of the GH repo that Github provides, or to the zeb folder which contains your build.zig and it does the rest

#

I don't know if createModule on the zeb side is enough to make that.module("zeb") work or not though

#

@crystal halo might be able to illuminate us both there.

leaden pilot
#

hmm

crystal halo
#

let me have a look

#

is this 0.11.x or master?

#

@leaden pilot

#

0.11.x makes it a lot harder, but technically possible - 0.12.x makes it easy

#

ah wait, this is 0.11.x just judging by the createModule call

leaden pilot
#

yes 0.11

crystal halo
#

well with 0.11 you basically have to transport the headers via a dummy artifact

leaden pilot
#

hmm

crystal halo
#

let me refresh my memory on the hack

#

I would strongly suggest moving to 0.12 to trivialise this though

#

as this will soon become unnecessary and obsolete - in 0.12, you'd just do zeb_module.addIncludePath(.{ .path = "include/" });

#

anyway, the hack for 0.11.x looks something like this:

// library build.zig build function:
const header_artifact = b.addStaticLibrary(.{ .name = "headers" });
header_artifact.installHeader("include", "include");
b.installArtifact(header_artifact);
// user build.zig build function:
const zeb_dep = b.dependency("zeb", .{ ... });
const exe = b.addExecutable(.{ ... });
exe.addModule("zeb", zeb_dep.module("zeb"));
exe.installLibraryHeaders(zeb_dep.artifact("headers"));
#

I haven't used 0.11 in a hot minute so this might not work out of the box and need some tweaks

#

but this is the basic idea

#

however I'll re-iterate, I would strongly suggest moving to 0.12 if this is an important use case, as that is when this becomes officially supported, no hacks needed

leaden pilot
#

Thanks alot!!!

crystal halo
#

feel free to mark the question as solved by reacting to the post with ✅

leaden pilot
#

Yes! just shifted to zig 12.0

crystal halo
#

welcome to the overhauled build system

leaden pilot
#

yeah, doubt: the people with 0.11 would be able to use my project?

crystal halo
#

probably not, the versions possess incompatible code in the build system

#

if you want to support 0.11 people, I'd suggest tagging a commit or a branch that uses the hack I pointed out

#

however, it should be noted, most of the ecosystem already tails master

#

(plus, people who are seriously using the package manager will also want to move to 0.12 as well, since again, that brought about a whole slew of beneficial changes)

leaden pilot
#

in how long would 0.12 would become a stable release?

crystal halo
#

well, the objectives for the 0.12 milestone on github are thinning out, so it should be sooner than later

leaden pilot
#

hmm.... can you please tell me how to slice a string []const u8 in zig (sorry for disturbing you so much 😅 )

crystal halo
#

slice[a..b]

leaden pilot
#

not in that way

#

I mean split at delimiter " "

crystal halo
#

there's std.mem.tokenize* and std.mem.split* functions

#

each returning an iterator of a slice of whatever which iterate over the given slices, splitting based on a given delimiter or set of delimiters, with a given behaviour

leaden pilot
#

thanks alot!

steady carbon
#

Assuming that zeb.h file is yours … and you are doing this as a learning exercise - you could have a go at porting it directly to zig as well. Most of what that c code does can also be found in the zig stdlib.

leaden pilot
#

or is there a hidden way of doing it 🤔

#

My overall status:

- brain thunder storming for 1 hour to build logic
- brain over raged thunder storming for 1 days for adding type conversions
- brain blizzard for feeling like a failure after I was not able to add type conversion

leaden pilot
steady carbon
#

Also - the fact you you understand C very well should make the zig journey much more enjoyable too

leaden pilot
#

really enjoying zig

steady carbon
#

Haha .. wait till you discover the power of comptime 🙂 You won’t sleep for a week thinking of all the possibilities. Enjoy.

leaden pilot
leaden pilot
crystal halo
#

not sure what you mean by "not able to configure"

leaden pilot
#

I have hosted my zeb library and released a package.
Suppose I am a user of zeb, how should I configure my project, that's what i want to know

crystal halo
#

I'm still not understanding fully what you mean. Are you asking how a person is meant to depend on your library?

leaden pilot
crystal halo
#

one would add a link to a .tar.gz of your project to their dependencies in build.zig.zon

#

github automatically exposes a .tar.gz of your repo per commit and tag

#

simplest way to get the one for any particular repo is git ls-remote https://github.com/owner/repo, and then take the hash listed for HEAD or whatever relevant tag and use it as the value for <hash> in https://github.com/owner/repo/archive/<hash>.tar.gz

#

you can then either add that manually to build.zig.zon, or run zig fetch https://github.com/owner/repo/archive/<hash>.tar.gz --save=name

leaden pilot
crystal halo
#

appears to be fine to me

#

feel free to open another thread if you run into trouble

leaden pilot
crystal halo
#

exe.root_module.addImport(b.dependency("zeb", .{}).module("zeb"));

#

assuming they have the dependency named as zeb in their zon file

leaden pilot
#
error: member function expected 2 argument(s), found 1
    exe.root_module.addImport(b.dependency("zeb", .{}).module("zeb"));
    ~~~~~~~~~~~~~~~^~~~~~~~~~
/Users/rohanvashisht/.zig/lib/std/Build/Module.zig:246:5: note: function declared here
pub fn addImport(m: *Module, name: []const u8, module: *Module) void {
neat eagle
#

exe.root_module.addImport("zeb", b.dependency("zeb", .{}).module("zeb"));

#

Use the module named zeb from the dependency named zeb for imports of zeb.

leaden pilot
#

**OH WOW!!!!!!!!! ** Thank you everyone!!