Build error - no field or member function named 'addIncludeDir' in 'Build.Step.Compile'

Hi all -

I’m writing a small programming language and the build seems to be almost finishing but I have this error -

error: no field or member function named 'addIncludeDir' in 'Build.Step.Compile'
    exe.addIncludeDir("compiler/lexer");
    ~~~^~~~~~~~~~~~~~
/home/andy/zig/lib/std/Build/Step/Compile.zig:1:1: note: struct declared here
const builtin = @import("builtin");
^~~~~
referenced by:
    runBuild__anon_8729: /home/andy/zig/lib/std/Build.zig:1987:27
    main: /home/andy/zig/lib/build_runner.zig:310:29
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

I’ve found previously that Zig’s build system seems to be rapidly changing so I’m thinking that addIncludeDir may no longer be a valid option.
It must be possible to add include directories so if someone is able to let me know what is used now instead of addIncludeDir, that’d be great!

I’m using Linux Mint and running Zig 0.12.0-dev.2811+3cafb9655 .

Many thanks in advance -
mooseman

It is called addIncludePath

example call: exe.addIncludePath(b.path("compiler/lexer"));

Hi dimdin - thanks for your reply!
Ahh, addIncludePath! Yep, makes sense - many thanks for that!

I have to say - in spite of the occasional little hiccup like this now and again, I’m loving using Zig!
I’ve used C for stuff like this in the past but I never even thought of using that this time - from now on, it’s Zig all the way for me… :slight_smile:

Cheers - thanks again -

  • mooseman

UPDATE - Hi again all.
I tried using this snippet but it didn’t work -

exe.addIncludePath(b.path("compiler/lexer"));

However, what did work was the following snippet, found in the build.zig file of the Zig compiler at Github -

exe.addIncludePath(. { .cwd_relative = "compiler/lexer"  });

That should be useful in case others have a similar problem.
Anyway - I got past that but have this problem now -

andy@obsidian:~$ cd silicon
andy@obsidian:~/silicon$ zig build
install
└─ install silicon_compiler
   └─ zig build-exe silicon_compiler Debug native 1 errors
src/main.zig:23:25: error: expected expression, found 'invalid bytes'
    const source_code = @"
                        ^~
src/main.zig:23:27: note: invalid byte: '\n'
    const source_code = @"
                          ^~
error: the following command failed with 1 compilation errors:
/home/andy/zig/zig build-exe -ODebug -I /home/andy/silicon/compiler/lexer -I /home/andy/silicon/compiler/parser -I /home/andy/silicon/compiler/semantic -I /home/andy/silicon/compiler/codegen -Mroot=/home/andy/silicon/src/main.zig --cache-dir /home/andy/silicon/zig-cache --global-cache-dir /home/andy/.cache/zig --name silicon_compiler --listen=- 
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install silicon_compiler transitive failure
   └─ zig build-exe silicon_compiler Debug native 1 errors
error: the following build command failed with exit code 1:
/home/andy/silicon/zig-cache/o/4074d924a3733864704ff0e5d18246ea/build /home/andy/zig/zig /home/andy/silicon /home/andy/silicon/zig-cache /home/andy/.cache/zig --seed 0xd4f3730 -Z37795ad03bbe086e
andy@obsidian:~/silicon$ 

I’m definitely very close to success - it was building the AST and so on - but it’s just failed with the above error. So, if someone can help with that, that would be great. My apologies for all this…

Thanks in advance -
mooseman

3 Likes

Hi all -

Sorry for replying to my own post but anyway…

I’m surprised I didn’t see this earlier - the problem is in the small bit of inline code that the lexer is trying to lex, then the parser is called and so on.
I should admit (somewhat ashamedly) that the code was generated by chatGPT but it has generated pretty good code for me for as long as I’ve used it (a few months now).

Anyway - here’s the relevant code -

pub fn main() void {
    const allocator = std.heap.page_allocator;

    const source_code = @"    <----- The error is here  
        class MyClass {
            let x = 10;
            func myFunc() {
                if x in [1, 2, 3] {
                    return x;
                } else {
                    return -1;
                }
            }
        }
    ";
    var lexer = try Lexer.init(allocator, source_code);
    defer lexer.deinit();

    try lexer.tokenize();

    var parser = Parser.init(lexer.tokens.toSlice());
    const ast = try parser.parse();

The build seems to be objecting to the newline after the @" .
Seems weird. Is there any way of tweaking this so that the lexer can read in the piece of code?
Even if the test bit of code were separate (as is usual), it would still have newlines in it so this is especially odd!

Many thanks in advance -
mooseman

Seems like ChatGPT still has some learning to do on Zig syntax. That piece of code calls for a multiline string whereas it’s trying to use quoted identifier syntax:

const source_code =
        \\class MyClass {
        \\    let x = 10;
        \\    func myFunc() {
        \\        if x in [1, 2, 3] {
        \\            return x;
        \\        } else {
        \\            return -1;
        \\        }
        \\    }
        \\}
    ;
2 Likes

So far my experiences with asking ChatGPT Zig questions have been it’s essentially unusable :joy: It basically gives a fever dream answer that’s sorta Zig, sort of a hallucinated non-existent language

3 Likes

AI is going to be a bad bet for quite some time. I looked at the prospect of training an auto-completer and Zig’s current syntax and it’s too much of a moving target. The stuff that you’d actually like to automate (boilerplate like the build system) is actually the most unstable part so far.

1 Like

Hi Hayden and Andrew - great to see you both!

I agree. ChatGPT is a bit “hit and miss” at present. It’s promising, sure, but it’s still at the “learning to walk” stage. Still a bit “wobbly on the legs…” :slight_smile:

I’ve decided to get a bit more “hands-on” with Zig. It’ll do me a world of good to explore it more like that.

Cheers - bye for now -
mooseman