Description
The example given here: https://ziglang.org/learn/samples/#hello
As a beginner in zig, running it and seeing this mess wasn't fun:
lib\std\os\windows.zig:2126:13: error: unable to evaluate comptime expression
asm (
^~~
lib\std\os\windows.zig:2135:15: note: called at comptime from here
return teb().ProcessEnvironmentBlock;
~~~^~
lib\std\io.zig:19:27: note: called at comptime from here
return windows.peb().ProcessParameters.hStdOutput;
~~~~~~~~~~~^~
lib\std\io.zig:30:40: note: called at comptime from here
return .{ .handle = getStdOutHandle() };
~~~~~~~~~~~~~~~^~
C:\Users\zeik\Documents\zig-testing\test.zig:3:32: note: called at comptime from here
const stdout = std.io.getStdOut().writer();
~~~~~~~~~~~~~~~~^~
C:\Users\zeik\Documents\zig-testing\test.zig:3:41: note: initializer of container-level variable must be comptime-known
const stdout = std.io.getStdOut().writer();
~~~~~~~~~~~~~~~~~~~~~~~~~^~
I usually assume hello world is the baseline for getting started and this was a shock. Had I misconfigured something? How? zig was a single executable, the sample on the landing page which was much more complicated worked fine.
I eventually dug up an old closed issue that explained the problem: ziglang/zig#6845 (comment)
The solution was really simple, if a bit gross, and moving that getStdOut call into the function did indeed fix the issue.
But might be worth mentioning in a note on the page or having both examples? zig beginners will struggle unnecessarily otherwise. Thanks!
EDIT: Just noticed that the Zigg Zagg example does in fact have this done in the Windows-friendly way, inside the function: https://ziglang.org/learn/samples/#zigg-zagg
Activity