Rework CMake
Closes #12722
Thank you. This looks like good work. Can you share the set of systems that you tested it on?
Thank you. This looks like good work. Can you share the set of systems that you tested it on?
Gentoo and Arch. I hitted this bug in Windows MSYS2, but it looks irrelevant:
[189/195] Linking CXX static library zigcpp\libzigcpp.a
[190/195] Linking CXX static library zigcpp\libzigstage1.a
[191/195] Linking CXX executable zig1.exe
[192/195] Building stage2 object C:/msys64/home/▒▒▒▒/zig/build/zig2.obj
FAILED: zig2.obj C:/msys64/home/▒▒▒▒/zig/build/zig2.obj
cmd.exe /C "cd /D C:\msys64\home\▒▒▒▒\zig && C:\msys64\home\▒▒▒▒\zig\build\zig1.exe src/stage1.zig --name zig2 --zig-lib-dir C:/msys64/home/▒▒▒▒/zig/lib -femit-bin=C:/msys64/home/▒▒▒▒/zig/build/zig2.obj -fcompiler-rt -target native -mcpu baseline -lc --pkg-begin build_options C:/msys64/home/▒▒▒▒/zig/build/config.zig --pkg-end --pkg-begin compiler_rt C:/msys64/home/▒▒▒▒/zig/lib/compiler_rt.zig --pkg-end"
Assertion failed at C:/msys64/home/▒▒▒▒/zig/src/stage1/os.cpp:1143 in utf8Decode2. This is a bug in the Zig compiler.
ninja: build stopped: subcommand failed.
Reproducible on master, fixed by removing Cyrillic characters from path (moved to another directory)
[194/195] Linking CXX executable zig2.exe
FAILED: zig2.exe
cmd.exe /C "cd . && C:\msys64\mingw64\bin\c++.exe -O3 -DNDEBUG -Wl,--stack,16777216 zig2.obj CMakeFiles/zig2.dir/src/stage1/empty.cpp.obj -o zig2.exe -Wl,--out-implib,zigcpp\libzig2.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L/lib zigcpp/libzigstage1.a -lntdll zigcpp/libopt_c_util.a zigcpp/libembedded_softfloat.a zigcpp/libzigcpp.a C:/msys64/mingw64/lib/libclang-cpp.dll.a C:/msys64/mingw64/lib/liblldMinGW.a C:/msys64/mingw64/lib/liblldELF.a C:/msys64/mingw64/lib/liblldCOFF.a C:/msys64/mingw64/lib/liblldWasm.a C:/msys64/mingw64/lib/liblldMachO.a C:/msys64/mingw64/lib/liblldCommon.a C:/msys64/mingw64/bin/libLLVM-14.dll -lpsapi -lshell32 -lole32 -luuid -ladvapi32 -lpthread -lz -lxml2 -lversion -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.obj:zig2:(.text+0x136): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.obj:zig2:(.text+0x6c6): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.obj:zig2:(.text+0x796): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.obj:zig2:(.text+0x866): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.obj:zig2:(.text+0x936): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.obj:zig2:(.text+0xa06): more undefined references to `__stack_chk_fail' follow
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.obj:zig2:(.rdata$.refptr.__stack_chk_guard[.refptr.__stack_chk_guard]+0x0): undefined reference to `__stack_chk_guard'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Same on master:
[3/4] Linking CXX executable zig2.exe
FAILED: zig2.exe
cmd.exe /C "cd . && C:\msys64\mingw64\bin\c++.exe -O3 -DNDEBUG -Wl,--stack,16777216 zig2.o CMakeFiles/zig2.dir/src/stage1/empty.cpp.obj -o zig2.exe -Wl,--out-implib,zigcpp\libzig2.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L/lib zigcpp/libzigstage1.a -lntdll zigcpp/libopt_c_util.a zigcpp/libembedded_softfloat.a zigcpp/libzigcpp.a -lclang-cpp -Wl,-Bstatic -llldMinGW -llldELF -llldCOFF -llldWasm -llldMachO -llldCommon -Wl,-Bdynamic C:/msys64/mingw64/bin/libLLVM-14.dll -lpsapi -lshell32 -lole32 -luuid -ladvapi32 -lpthread -lz -lxml2 -lversion -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.o:zig2:(.text+0x136): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.o:zig2:(.text+0x6c6): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.o:zig2:(.text+0x796): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.o:zig2:(.text+0x866): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.o:zig2:(.text+0x936): undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.o:zig2:(.text+0xa06): more undefined references to `__stack_chk_fail' follow
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: zig2.o:zig2:(.rdata$.refptr.__stack_chk_guard[.refptr.__stack_chk_guard]+0x0): undefined reference to `__stack_chk_guard'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
UPD: sounds like https://github.com/ziglang/zig/issues/12703#issuecomment-1233130622
Ready I think.
If you want, I can extract fix for https://github.com/ziglang/zig/issues/12722 to the new PR, so you won't need to check all changes in this PR