zig icon indicating copy to clipboard operation
zig copied to clipboard

Zig emits compile error, but it doesn't prevent compilation

Open So1aric opened this issue 1 year ago • 1 comments

Zig Version

0.12.0-dev.2063+804cee3b9

Steps to Reproduce and Observed Behavior

build.zig snippet:

    const glfw = b.dependency("mach-glfw", .{
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("mach-glfw", glfw.module("mach-glfw"));

    const gl = b.dependency("zgl", .{ .target = target, .optimize = optimize });
    exe.root_module.addImport("zgl", gl.module("zgl"));

    b.installArtifact(exe);

Running zig build run, zig emits:

error: Invalid option: -Dcpu
error: Invalid option: -Dtarget
error: Invalid option: -Doptimize
/home/so1aric/zig/0.12.0-dev.2063+804cee3b9/files/lib/std/Build.zig:1731:35: 0x112add6 in dependency__anon_13446 (build)
            return dependencyInner(b, name, pkg.build_root, if (@hasDecl(pkg, "build_zig")) pkg.build_zig else null, pkg.deps, args);
                                  ^
/home/so1aric/Projects/phyade/build.zig:20:28: 0x10e0bbd in build (build)
    const gl = b.dependency("zgl", .{ .target = target, .optimize = optimize });
                           ^
/home/so1aric/zig/0.12.0-dev.2063+804cee3b9/files/lib/std/Build.zig:1850:33: 0x10cd593 in runBuild__anon_8077 (build)
        .Void => build_zig.build(b),
                                ^
/home/so1aric/zig/0.12.0-dev.2063+804cee3b9/files/lib/build_runner.zig:319:29: 0x10c916f in main (build)
        try builder.runBuild(root);
                            ^
/home/so1aric/zig/0.12.0-dev.2063+804cee3b9/files/lib/std/start.zig:585:37: 0x10b4535 in posixCallMainAndExit (build)
            const result = root.main() catch |err| {
                                    ^
/home/so1aric/zig/0.12.0-dev.2063+804cee3b9/files/lib/std/start.zig:253:5: 0x10b4021 in _start (build)
    asm volatile (switch (native_arch) {

But it doesn't prevent compilation, and the program is compiled successfully ( despite the weird error message ). Is this a bug or something intended?

Expected Behavior

It just compile without these messages.

So1aric avatar Feb 08 '24 01:02 So1aric

I'm getting the same error :/

tuket avatar Jul 19 '24 20:07 tuket

Believe I am also running into the same problem.

error: invalid option: -Doptimize
/usr/lib/zig/std/Build.zig:1954:35: 0x1158f64 in dependency__anon_14236 (build)
            return dependencyInner(b, name, pkg.build_root, if (@hasDecl(pkg, "build_zig")) pkg.build_zig else null, pkg_hash, pkg.deps, args);
                                  ^
/home/core/GitSources/Zig/ztorrent/build.zig:18:41: 0x1112d70 in build (build)
    const zig_bencode_dep = b.dependency("zig-bencode", .{
                                        ^
/usr/lib/zig/std/Build.zig:2116:33: 0x10f7c83 in runBuild__anon_8818 (build)
        .Void => build_zig.build(b),
                                ^
/usr/lib/zig/compiler/build_runner.zig:301:29: 0x10f2e8e in main (build)
        try builder.runBuild(root);
                            ^
/usr/lib/zig/std/start.zig:524:37: 0x10da7e5 in posixCallMainAndExit (build)
            const result = root.main() catch |err| {
                                    ^
/usr/lib/zig/std/start.zig:266:5: 0x10da301 in _start (build)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x7 in ??? (???)
Unwind information for `???:0x7` was not available, trace may be incomplete

This is on Arch Linux with Zig version 0.13.0 and installed from the package manager. I also tried using the zig release from official site and building 0.13 from source locally. Same results.

The error shows up in a simple project created with zig init and with just one zig-bencode dependency added to build.zig and build.zig.zon with no other code aside from what was generated by zig init. The generated binary in zig-out still works fine even though this error is reported.

SanchayanMaity avatar Nov 06 '24 05:11 SanchayanMaity

I've just run into this, and I think it has something to do with the dependency's build.zig not making use of target or optimize. (ie. b.standardTargetOptions(.{}) and b.standardOptimizeOption(.{})).

When I change the dependent's build.zig from:

const datetime = b.dependency(name: "datetime", .{.target = target, .optimize = optimize});

to

const datetime = b.dependency(name: "datetime", .{});

the error goes away.

dryfisc avatar Nov 28 '24 09:11 dryfisc