Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder.LibExeObjStep.addIncludeDir() not working in custom build.zig? #794

Closed
ccll opened this issue Feb 27, 2018 · 4 comments
Closed

builder.LibExeObjStep.addIncludeDir() not working in custom build.zig? #794

ccll opened this issue Feb 27, 2018 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@ccll
Copy link

ccll commented Feb 27, 2018

I'd like to call GTK functions from my zig program, here is the relevant code:

// build.zig
const cell = b.addExecutable("cell", ...);
cell.setBuildMode(mode);
cell.addIncludeDir("/usr/include/gtk-3.0");
// my module
const builtin = @import("builtin");
const Os = builtin.Os;
const c = switch (builtin.os) {
    Os.linux, Os.macosx => @cImport({
        @cInclude("stdio.h");
        @cInclude("stdlib.h");
        @cInclude("gtk/gtk.h");
    }),
    else => {},
}

But the compiler complaints about not finding the header file:

/home/cailei/proj/cell/infra/win.zig:6:28: error: C import failed
    Os.linux, Os.macosx => @cImport({
                           ^
/tmp/KyXYT4.h:3:10: note: 'gtk/gtk.h' file not found
#include <gtk/gtk.h>
         ^

And the file is apparently there:

$ ll /usr/include/gtk-3.0/gtk/gtk.h                                                   
-rw-r--r-- 1 root root 9663 10月 31 04:07 /usr/include/gtk-3.0/gtk/gtk.h  
@andrewrk andrewrk added this to the 0.2.0 milestone Feb 27, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Feb 27, 2018
@andrewrk
Copy link
Member

I just tried this out, and when I do zig build --verbose I get:

zig build-exe /home/andy/tmp/testzig/main.zig --cache-dir /home/andy/tmp/testzig/zig-cache --output /home/andy/tmp/testzig/zig-cache/cell --name cell -isystem /usr/include/gtk-3.0 

which looks like it's passing the correct -isystem argument. Do you get this output?

@bnoordhuis
Copy link
Contributor

Does it work when you add everything that pkg-config --cflags-only-I gtk+-3.0 prints?

@ccll
Copy link
Author

ccll commented Feb 28, 2018

@andrewrk Oops! My bad!
I just found out the compile error comes from a "TestStep" I've added in build.zig, which runs before compiling the main executable target.

const cell_test = b.addTest(...);
b.default_step.dependOn(&cell_test.step);

After commented out the test step, the executable target itself compiles fine.

I keep all test cases in the same file as the actual code for clarity and ease of code organization,
for now I could check builtin.is_test and ignore the @Cinclude("gtk/gtk.h") in test mode, as my tests does not use the header file.
In the long term maybe there should be an addIncludeDir() implemented for TestStep?

@andrewrk
Copy link
Member

Ah yeah that's a good point. This is a pretty straightforward userland change to std/build.zig if anyone wants to take a crack at it. Otherwise I'll try to fix it soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants