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

Zig build should error when overwriting output files #20235

Open
Tracked by #8
wooster0 opened this issue Jun 8, 2024 · 1 comment
Open
Tracked by #8

Zig build should error when overwriting output files #20235

wooster0 opened this issue Jun 8, 2024 · 1 comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@wooster0
Copy link
Contributor

wooster0 commented Jun 8, 2024

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});

    const optimize = b.standardOptimizeOption(.{});

    const x = b.addExecutable(.{
        .name = "x",
        .root_source_file = b.path("x.zig"),
        .target = target,
        .optimize = optimize,
    });
    b.installArtifact(x);

    const y = b.addExecutable(.{
        .name = "x",
        .root_source_file = b.path("y.zig"),
        .target = target,
        .optimize = optimize,
    });
    b.installArtifact(y);
}

Can you spot the mistake? Indeed, I forgot to change the name of the second executable, which means it's going to output two different binaries at the same location in zig-out/bin/, silently causing only one binary to be outputted.

I propose to make the Zig build script error when this happens because I can't see a use case for ever wanting to overwrite a binary that you already installed. If you do so, you're more likely doing something wrong, no?
It should be possible to check for a file already existing of the same name before it outputs the file. This applies to anywhere Zig build can output files.

@rohlem
Copy link
Contributor

rohlem commented Jun 8, 2024

It should be possible to check for a file already existing of the same name before it outputs the file.

Probably what you already meant, but this should of course be atomic.
So not checkExists -> createFile, but instead via a file creation flag that makes the operation fail if the file already exists.
(Or if the executable is already generated somewhere in the zig-cache first, a file copy with a flag that makes it fail if it would overwrite another file.)

@Vexu Vexu added enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig build system std.Build, the build runner, `zig build` subcommand, package management labels Jun 8, 2024
@Vexu Vexu added this to the 0.14.0 milestone Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
None yet
Development

No branches or pull requests

3 participants