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

Build.zig can't produce LLVM bytecode without outputting the full binary #20699

Closed
gwenzek opened this issue Jul 20, 2024 · 2 comments
Closed
Labels
bug Observed behavior contradicts documented or intended behavior zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@gwenzek
Copy link
Sponsor Contributor

gwenzek commented Jul 20, 2024

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

Create a hello world file at "hello.zig"
Next to it create the following "build.zig" file.

const std = @import("std");

pub fn build(b: *std.Build) void {
    const hello = b.addObject(.{
        .name = "hello_world",
        .root_source_file = b.path("hello.zig"),
        .optimize = .ReleaseFast,
        .target = b.standardTargetOptions(.{}),
        .use_llvm = true,
    });

    const install_bc = b.addInstallFile(hello.getEmittedLlvmBc(), "hello.bc");
    b.getInstallStep().dependOn(&install_bc.step);
}

    // If this two lines are commented out, the bytecode file doesn't get installed (but still emitted).
    // const install_bin = b.addInstallFile(zig_kernel.getEmittedBin(), "hello.bin");
    // b.getInstallStep().dependOn(&install_bin.step);
}

Then zig build fails with the following error:

getPath() was called on a GeneratedFile that wasn't built yet.
  Is there a missing Step dependency on step 'zig build-obj hello_world ReleaseFast native'?

Expected Behavior

Zig should accept to compile the program and only output llvm bytecode, not the full binary.

Note this is still present on zig_0.14.0-dev.363, and it was also present a few months ago when I wrote this https://gist.github.com/gwenzek/7e77e592320b9b1971b95fb0d6429424 (totally forgot about it in the meantime).

This issue is not only about Llvm bytecode, it's also reproducible with other outputs kind such as -femit-asm

Note that directly calling zig build-obj -fno-emit-bin -femit-llvm-bytecode works fine it's really an issue with the build system.

@gwenzek gwenzek added the bug Observed behavior contradicts documented or intended behavior label Jul 20, 2024
@gwenzek gwenzek changed the title Build.zig doesn't work with Build.zig can't produce LLVM bytecode without outputting the full binary Jul 20, 2024
@andrewrk andrewrk added the zig build system std.Build, the build runner, `zig build` subcommand, package management label Jul 26, 2024
@andrewrk andrewrk added this to the 0.14.0 milestone Jul 26, 2024
@Snektron
Copy link
Collaborator

Should be fixed by #21115

@Snektron
Copy link
Collaborator

Above pr is merged and contains a test for this exact case

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 zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
None yet
Development

No branches or pull requests

3 participants