Closed zlw closed 1 year ago
On Linux and macOS the file handle for stdin
is constant and can therefore be resolved at comptime
.
On Windows (fwict) this is not the case: It has to be looked up at runtime.
Zig only allows initializing global (technically container-level) declarations with comptime
-known values.
Your options are:
const
declaration into a function/block scope, where it will be executed at runtime.var
and overwrite its value in a function scope/block at runtime. (Initialize it with undefined
, or declare it with an optional type and initialize it with null
.)stdin
without code execution - but I assume the authors of std
have done their due diligence and Windows just doesn't offer that option.)Previous issues: #6845, #14203
Zig Version
0.11.0
Steps to Reproduce and Observed Behavior
While following Crafting Interpreters book in Zig, I wanted to try cross-compiling to different targets. It works like a charm for linux and mac (I'm on mac), but it failed for windows while trying to get stdIn handle:
To fully reproduce it you could clone the repo https://github.com/zlw/zlox/commit/166a2eb038532d0358e44f7be65506e651d0b9f3 and try to compile it with:
make cross_release target=windows
which runs:
zig build -Doptimize=ReleaseFast -Dtarget="x86_64-windows"
but I'm guessing the minimal way to reproduce it would be something like:
Thanks for all the work on Zig, it's my first low-level language and it's been a great journey so far 😄 It made working with memory way less scary, Allocator a'la DI is an amazing idea 🤯
Expected Behavior
Cross compilation woks for all 3 main target on OSX