#build on save do not work

1 messages · Page 1 of 1 (latest)

coarse ember
#

Hello, i fallow https://zigtools.org/zls/guides/build-on-save/, and this is my build.zig:

pub fn build(b: *std.Build) void {
    // const optimize = b.standardTargetOption(.{});
    const exe_mod = b.createModule(.{ 
        .root_source_file = b.path("src/main.zig"),
        .target = b.graph.host,
        .optimize = .Debug
    });        
    const exe = b.addExecutable(.{
        .name = "io_multiplexing",
        .root_module = exe_mod,
    });
    b.installArtifact(exe);
    // Run step
    const run_exe = b.addRunArtifact(exe);
    const run_step = b.step(
        "run", "runs exe"
    );
    run_step.dependOn(&run_exe.step);
    // Test step
    const test_exe = b.addTest(.{
        .name = "tests",
        .root_module = b.createModule(.{
           .root_source_file = b.path("src/main.zig"),
           .target = b.graph.host
        }),
    });
    b.installArtifact(test_exe);
    const run_tests = b.addRunArtifact(test_exe);
    const test_run_step = b.step("test", "runs tests");
    test_run_step.dependOn(&run_tests.step);
    // Check
    const exe_check = b.addExecutable(.{
        .name = "io_multiplexing",
        .root_module = exe_mod,
    });
    const check = b.step("check", "Check if foo compiles");
    check.dependOn(&exe_check.step);
}

ZLS do not enabled build on save, i do not get diagnostics for build issues.
What am I doing wrong here?
THX for help!

coarse ember
#

zig build check sees exceptions, but ZLS not

coarse ember
#

"'enable_build_on_save' is ignored because no build runner is available"

calm bay
#

is zls working otherwise? This may be a case of having an incompatible ZLS and Zig version. Are you using zig master?

coarse ember
#

i switched from windows to linux, and it works without problem

#

yes, zig master

#

@calm bay do you know how to add tests to check?

#

also, how to include other modules/files that i am workin on, in that build check, like
i am working on some file, it is not used yet in main/files imported in main
how to include all into checkl?

calm bay
calm bay
coarse ember
#

@calm bay but my problem is, that tests even in main file, do not pariticpate in check, i dont have same diagnosticks for them

#

also i dont have root, i have main only, it is not a lib, do i need to create a library in order to include all files? for regular exe importing does not work, i dont have diagnosticsk for other files

#

is there a flag to include all? or something. Do i need to allways create root, in order to create library, to have diagnostics everywhere?

#

it is crazy, if i add extra function out of main, that is not used yet, it is not checked

quasi fractal
#

the check is a step you define, zls just runs it. if you want tests to be included you need to add it to your check, the same way you did with the executable.

coarse ember
#

ok it works in tests at main, but it do not work in imported file, wheel_of_time

quasi fractal
#

refAllDecls[Recursive] cannot reference non public declarations.
your import is non public. either make it public, or reference it explicitly
_ = wheel_of_time;

coarse ember
#

@calm bay
Ok i figure it out, imports should be in test block

#

o ok, doing it way you saidm, make import public, make those files compile even without using it in tests

#

thx

#

is there some name convention or something?
now in main i will have bunch of pub imports

quasi fractal
#

or reference it explicitly
_ = wheel_of_time;
I did provide an alternate solution if you didnt want to make them public.

coarse ember
#

but i cant reference them in main, you mean tor eference them in that test {}?

quasi fractal
#

yes reference them, i did not mean to move the import into the test.

coarse ember
#

is there a way to use build to check if build is run with check flag? to make all those import imported only for checks and tests runs

#

diffference betwen making them pub VS importing and referencing them in test, is that:
make them public: public stuff + tests are checked, even if those public functions are not tested
import + reference in test {}: check only stuff used in tests

#

so i will leave them as pub

#

THX