ziglang/zig-bootstrap
14
41
Fork
You've already forked zig-bootstrap
12

x86_64-windows-gnu broken, CMakeFiles/zig2.dir/zig2.c.obj Errors out #261

Open
opened 2026年05月16日 17:07:30 +02:00 by Beneppe · 4 comments

When producing zig2.c.obj on

** Visual Studio 2026 Developer Command Prompt v18.5.2
[vcvarsall.bat] Environment initialized for: 'x64'

error C2466: cannot allocate an array of constant size 0
on multiple occasions.

FAILED: [code=2] CMakeFiles/zig2.dir/zig2.c.obj
C:\PROGRA~1\MIB055~118円\COMMUN~1\VC\Tools\MSVC1450円~1.357\bin\Hostx64\x64\cl.exe /nologo -IC:\Users7743円l\Desktop\Giit\SRC\zig\stage1 -IC:\Users7743円l\Desktop\Giit\SRC\out-win\host\include /DWIN32 /D_WINDOWS /O2 /Ob2 /DNDEBUG -MD /Od /showIncludes /FoCMakeFiles\zig2.dir\zig2.c.obj /FdCMakeFiles\zig2.dir\ /FS -c C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c
cl : Command line warning D9025 : overriding '/O2' with '/Od'
C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(12953): error C2466: cannot allocate an array of constant size 0
...
C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(72213): error C2466: cannot allocate an array of constant size 0
C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(135660): warning C4273: 'free': inconsistent dll linkage
C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\corecrt_malloc.h(89): note: see previous definition of 'free'
C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(168891): warning C4273: 'malloc': inconsistent dll linkage
C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\corecrt_malloc.h(101): note: see previous definition of 'malloc'
C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(168897): warning C4273: 'realloc': inconsistent dll linkage
C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\corecrt_malloc.h(126): note: see previous definition of 'realloc'
C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(168900): warning C4028: formal parameter 1 different from declaration
C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(168900): warning C4273: '_msize': inconsistent dll linkage
C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\corecrt_malloc.h(113): note: see previous definition of '_msize'
ninja: build stopped: subcommand failed.
When producing zig2.c.obj on ``` ** Visual Studio 2026 Developer Command Prompt v18.5.2 [vcvarsall.bat] Environment initialized for: 'x64' ``` error C2466: cannot allocate an array of constant size 0 on multiple occasions. ``` FAILED: [code=2] CMakeFiles/zig2.dir/zig2.c.obj C:\PROGRA~1\MIB055~118円\COMMUN~1\VC\Tools\MSVC1450円~1.357\bin\Hostx64\x64\cl.exe /nologo -IC:\Users7743円l\Desktop\Giit\SRC\zig\stage1 -IC:\Users7743円l\Desktop\Giit\SRC\out-win\host\include /DWIN32 /D_WINDOWS /O2 /Ob2 /DNDEBUG -MD /Od /showIncludes /FoCMakeFiles\zig2.dir\zig2.c.obj /FdCMakeFiles\zig2.dir\ /FS -c C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c cl : Command line warning D9025 : overriding '/O2' with '/Od' C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(12953): error C2466: cannot allocate an array of constant size 0 ... C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(72213): error C2466: cannot allocate an array of constant size 0 C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(135660): warning C4273: 'free': inconsistent dll linkage C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\corecrt_malloc.h(89): note: see previous definition of 'free' C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(168891): warning C4273: 'malloc': inconsistent dll linkage C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\corecrt_malloc.h(101): note: see previous definition of 'malloc' C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(168897): warning C4273: 'realloc': inconsistent dll linkage C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\corecrt_malloc.h(126): note: see previous definition of 'realloc' C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(168900): warning C4028: formal parameter 1 different from declaration C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(168900): warning C4273: '_msize': inconsistent dll linkage C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\corecrt_malloc.h(113): note: see previous definition of '_msize' ninja: build stopped: subcommand failed. ```
Beneppe changed title from (削除) x86_64-windows-gnu broken, CMakeFiles/zig2.dir/zig2.c.obj Errors out (削除ここまで) to x86_64-windows-msvc broken, CMakeFiles/zig2.dir/zig2.c.obj Errors out 2026年05月17日 00:31:30 +02:00
Beneppe changed title from (削除) x86_64-windows-msvc broken, CMakeFiles/zig2.dir/zig2.c.obj Errors out (削除ここまで) to x86_64-windows-gnu broken, CMakeFiles/zig2.dir/zig2.c.obj Errors out 2026年05月17日 01:42:40 +02:00
Author
Copy link

Err for both x86_64-windows-gnu and x86_64-windows-msvc

Err for both x86_64-windows-gnu and x86_64-windows-msvc

Relevant issue is ziglang/zig#31576

Relevant issue is https://codeberg.org/ziglang/zig/issues/31576
Author
Copy link

Building with clang-cl.exe instead, also errors, but this time is does not seem like ziglang/zig#31576 is the culprit:

[16/19] Building C object CMakeFiles\zig2.dir\zig2.c.obj
FAILED: [code=1] CMakeFiles/zig2.dir/zig2.c.obj
C:\clang+llvm-22.1.2-x86_64-pc-windows-msvc\bin\clang-cl.exe /nologo -IC:\Users7円743l\Desktop\Giit\SRC\zig\stage1 -IC:\Users7円743l\Desktop\Giit\SRC\out-win\host\include /DWIN32 /D_WINDOWS /O2 /Ob2 /DNDEBUG -MD /Od -clang:-MD -clang:-MTCMakeFiles\zig2.dir\zig2.c.obj -clang:-MFCMakeFiles\zig2.dir\zig2.c.obj.d /FoCMakeFiles\zig2.dir\zig2.c.obj /FdCMakeFiles\zig2.dir\ -c -- C:\Users7円743l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c
C:\Users7円743l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(289,29): error: field '__p__environ' declared as a function
 289 | struct process_Environ_743 environ;
 | ^
C:\Program Files (x86)\Windows Kits1円0\include1円0.0.26100.0\ucrt\stdlib.h(1344,21): note: expanded from macro 'environ'
 1344 | #define environ _environ
 | ^
C:\Program Files (x86)\Windows Kits1円0\include1円0.0.26100.0\ucrt\stdlib.h(1171,25): note: expanded from macro '_environ'
 1171 | #define _environ (*__p__environ()) // Pointer to narrow environment table
 | ^
C:\Users7円743l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(291,19): error: static assertion failed due to requirement 'sizeof(struct process_Init_Minimal_741) == 24': incorrect size
 291 | zig_static_assert(sizeof (struct process_Init_Minimal_741) == 24, "incorrect size");
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users7円743l\Desktop\Giit\SRC\zig\stage1\zig.h(158,53): note: expanded from macro 'zig_static_assert'
 158 | #define zig_static_assert(cond, msg) _Static_assert(cond, msg)
 | ^~~~
C:\Users7円743l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(291,60): note: expression evaluates to '1 == 24'
 291 | zig_static_assert(sizeof (struct process_Init_Minimal_741) == 24, "incorrect size");
 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
C:\Users7円743l\Desktop\Giit\SRC\zig\stage1\zig.h(158,53): note: expanded from macro 'zig_static_assert'
 158 | #define zig_static_assert(cond, msg) _Static_assert(cond, msg)
 | ^~~~

But the problem is not neccessarily that the "C backend emits incorrect type layouts for MSVC", but rather that the variable name environ is already a defined macro in

C:\Program Files (x86)\Windows Kits1円0\include1円0.0.26100.0\ucrt\stdlib.h(1344,21): note: expanded from macro 'environ'
 1344 | #define environ _environ
 | ^

This gets used in

struct process_Init_Minimal_741 { /* process.Init.Minimal */
 struct process_Args_745 args;
 struct process_Environ_743 environ;
};

And causes all my errors downstream

**Building with clang-cl.exe** instead, also errors, but this time is does not seem like [ziglang/zig#31576](https://codeberg.org/ziglang/zig/issues/31576) is the culprit: ``` bash [16/19] Building C object CMakeFiles\zig2.dir\zig2.c.obj FAILED: [code=1] CMakeFiles/zig2.dir/zig2.c.obj C:\clang+llvm-22.1.2-x86_64-pc-windows-msvc\bin\clang-cl.exe /nologo -IC:\Users7743円l\Desktop\Giit\SRC\zig\stage1 -IC:\Users7743円l\Desktop\Giit\SRC\out-win\host\include /DWIN32 /D_WINDOWS /O2 /Ob2 /DNDEBUG -MD /Od -clang:-MD -clang:-MTCMakeFiles\zig2.dir\zig2.c.obj -clang:-MFCMakeFiles\zig2.dir\zig2.c.obj.d /FoCMakeFiles\zig2.dir\zig2.c.obj /FdCMakeFiles\zig2.dir\ -c -- C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(289,29): error: field '__p__environ' declared as a function 289 | struct process_Environ_743 environ; | ^ C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\stdlib.h(1344,21): note: expanded from macro 'environ' 1344 | #define environ _environ | ^ C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\stdlib.h(1171,25): note: expanded from macro '_environ' 1171 | #define _environ (*__p__environ()) // Pointer to narrow environment table | ^ C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(291,19): error: static assertion failed due to requirement 'sizeof(struct process_Init_Minimal_741) == 24': incorrect size 291 | zig_static_assert(sizeof (struct process_Init_Minimal_741) == 24, "incorrect size"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\Users7743円l\Desktop\Giit\SRC\zig\stage1\zig.h(158,53): note: expanded from macro 'zig_static_assert' 158 | #define zig_static_assert(cond, msg) _Static_assert(cond, msg) | ^~~~ C:\Users7743円l\Desktop\Giit\SRC\out-win\build-zig-host\zig2.c(291,60): note: expression evaluates to '1 == 24' 291 | zig_static_assert(sizeof (struct process_Init_Minimal_741) == 24, "incorrect size"); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ C:\Users7743円l\Desktop\Giit\SRC\zig\stage1\zig.h(158,53): note: expanded from macro 'zig_static_assert' 158 | #define zig_static_assert(cond, msg) _Static_assert(cond, msg) | ^~~~ ``` But the problem is not neccessarily that the "C backend emits incorrect type layouts for MSVC", but rather that the variable name environ is already a defined macro in ``` bash C:\Program Files (x86)\Windows Kits10円\include10円.0.26100.0\ucrt\stdlib.h(1344,21): note: expanded from macro 'environ' 1344 | #define environ _environ | ^ ``` This gets used in ``` c struct process_Init_Minimal_741 { /* process.Init.Minimal */ struct process_Args_745 args; struct process_Environ_743 environ; }; ``` And causes all my errors downstream
Author
Copy link

I believe we need to add "environ" to
https://codeberg.org/ziglang/zig/blame/branch/master/src/codegen/c.zig const reserved_idents = std.StaticStringMap(void)
and update zig1.wasm.

Skipping this for now by simply adding:

#undef environ

allows to pass my previous environ related errors, but now i hit this again

@squeek502 wrote in #261 (comment):

Relevant issue is ziglang/zig#31576

So yeah, this is a twofold issue:

  1. The reserved var name "environ"
  2. The "C backend emits incorrect type layouts for MSVC #31576"
I believe we need to add "environ" to https://codeberg.org/ziglang/zig/blame/branch/master/src/codegen/c.zig const reserved_idents = std.StaticStringMap(void) and update zig1.wasm. Skipping this for now by simply adding: ``` c #undef environ ``` allows to pass my previous environ related errors, but now i hit this again @squeek502 wrote in https://codeberg.org/ziglang/zig-bootstrap/issues/261#issuecomment-15088395: > Relevant issue is ziglang/zig#31576 So yeah, this is a twofold issue: 1. The reserved var name "environ" 2. The "C backend emits incorrect type layouts for MSVC #31576"
Sign in to join this conversation.
No Branch/Tag specified
master
0.16.x
0.15.x
0.14.x
0.12.x
0.10.x
0.9.x
0.8.x
0.7.x
0.16.0
0.15.2
0.15.1
0.14.1
0.14.0
0.12.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.1
0.9.0
0.8.1
0.8.0
0.7.1
0.7.0
0.6.0
Labels
Clear labels
bounty
https://ziglang.org/news/announcing-donor-bounties
bug
Observed behavior contradicts documented or intended behavior.
contributor-friendly
This issue is limited in scope and/or knowledge of project internals.
downstream
An issue with a third-party project that uses this project.
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
infra
An issue related to project infrastructure, e.g. continuous integration.
optimization
A task to improve performance and/or resource usage.
question
No questions on the issue tracker; use a community space instead.
regression
Something that used to work in a previous version stopped working
upstream
An issue with a third-party project that this project uses.
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig-bootstrap#261
Reference in a new issue
ziglang/zig-bootstrap
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?