Skip to content

Race with .intentionally-empty-file #348

@simonzkl

Description

@simonzkl

There's a race condition when running multiple instances of cargo-zigbuild (when for example compiling to multiple targets at the same time)

Error: Failed to collect `zig cc` options
Caused by:
    Failed to run `zig cc -v` with status exit status: 1: clang version 19.1.7
    Target: x86_64-unknown-linux4.19.0-gnu2.31.0
    Thread model: posix
    InstalledDir: /nix/store/jb7n26fqzkbvqqwz0wm69gx0rm4cw9lg-zig-0.14.1/bin
    zig: error: no such file or directory: '/root/.cache/cargo-zigbuild/0.20.0/.intentionally-empty-file.c'

It can happen here:

cargo-zigbuild/src/zig.rs

Lines 686 to 688 in f903aaa

if !empty_file_path.exists() {
fs::write(&empty_file_path, "")?;
}

Or potentially here?

fs::remove_file(&empty_file_path).ok();

I don't really understand why this is necessary, but I guess one easy way to fix this would be to randomly generate the file name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions