Skip to content

Cross compile to Windows fails with relative global cache directory path #19284

@aherrmann

Description

@aherrmann

Zig Version

0.12.0-dev.3282+da5b16f9e

Steps to Reproduce and Observed Behavior

Configuring a global cache directory on the command line using a relative path causes cross compilation to Windows to fail. Tested on Ubuntu 22.04 x86_64.

Steps to reproduce

Download and unpack the Zig SDK.

$ curl -L https://ziglang.org/builds/zig-linux-x86_64-0.12.0-dev.3282+da5b16f9e.tar.xz -o zig-linux-x86_64-0.12.0-dev.3282+da5b16f9e.tar.xz
$ tar xvf zig-linux-x86_64-0.12.0-dev.3282+da5b16f9e.tar.xz

Create a simple hello world program.

$ cat <<EOF >main.zig
const std = @import("std");

pub fn main() !void {
    try std.io.getStdOut().writer().print("Hello world!\n", .{});
}
EOF

Try to cross-compile to Windows while specifying a global cache directory on the command line using a relative path.

$ zig-linux-x86_64-0.12.0-dev.3282+da5b16f9e/zig build-exe --global-cache-dir custom-zig-global-cache -target x86_64-windows-gnu main.zig
error: unable to generate DLL import .lib file for kernel32: FileNotFound

Observe how the build fails due to a missing .lib file for the kernel32 library.

Run the same command, but use an absolute path for the global cache directory parameter.

$ zig-linux-x86_64-0.12.0-dev.3282+da5b16f9e/zig build-exe --global-cache-dir $PWD/custom-zig-global-cache -target x86_64-windows-gnu main.zig
$ wine64 ./main.exe
Hello world!

Observe how the build succeeds and the produced binary can run with Wine.

Context

This issue was initially observed in https://github.com/aherrmann/rules_zig when trying to update to Zig 0.12.0-dev. To ensure that builds are hermetic and reproducible, rules_zig controls the global and local cache directories. At the moment it declares a global and local cache output for each build action that is managed by Bazel. Bazel operates on relative paths, so these cache directory paths are always configured using relative paths.

(Side note: Better cache handling is planned as a future improvement, see aherrmann/rules_zig#87)

Expected Behavior

Zig builds should succeed irrespective of whether the global (or local) cache paths are specified as relative or absolute paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorregressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions