-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Building zig from source on Guix fails at stage3 #18434
Comments
Guix exports $ ./pre-inst-env guix shell -D [email protected] --search-paths | grep LIBRARY
export LIBRARY_PATH="/gnu/store/dy0hhdbz7z2gzy57m0jz9zdl6543dymm-profile/lib${LIBRARY_PATH:+:}$LIBRARY_PATH" Tried to solve it this kind of "way" (only to be sure this action actually solves anything): diff --git a/CMakeLists.txt b/CMakeLists.txt
index 92be8fbfe..d3794f189 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -863,6 +863,15 @@ endif()
# -Dno-autodocs is currently hardcoded because the C backend generates a miscompilation
# that prevents it from working.
# To obtain these two forms of documentation, run zig build against stage3 rather than stage2.
+string(REPLACE ":" ";" LIBRARY_PATH "$ENV{LIBRARY_PATH}")
+set(SEARCH_PATHS "")
+
+foreach(PATH ${LIBRARY_PATH})
+ list(APPEND SEARCH_PATHS "--search-prefix ${PATH}")
+endforeach()
+
+list(JOIN SEARCH_PATHS " " SEARCH_PREFIXES)
+
set(ZIG_BUILD_ARGS
--zig-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
@@ -877,6 +886,7 @@ set(ZIG_BUILD_ARGS
"-Dtarget=${ZIG_TARGET_TRIPLE}"
"-Dcpu=${ZIG_TARGET_MCPU}"
"-Dversion-string=${RESOLVED_ZIG_VERSION}"
+ ${SEARCH_PREFIXES}
)
add_custom_target(stage3 ALL But stuck with the way cmake's |
Finally managed to pass desired parameters through manual hacking: $ rg 'zig2 build' build/CMakeFiles/
build/CMakeFiles/stage3.dir/build.make
73: build/zig2 build --prefix build/stage3 --zig-lib-dir lib -Dconfig_h=build/config.h -Denable-llvm -Dno-langref -Dno-autodocs -Dtarget=native -Dcpu=native -Dversion-string=0.11.0 --search-prefix /gnu/store/dy0hhdbz7z2gzy57m0jz9zdl6543dymm-profile/lib --search-prefix /gnu/store/hvckqjrpikqs1zgn5gw838mf3ad9q753-profile/lib Resulting executable is as follows: $ ldd build/stage3/bin/zig
linux-vdso.so.1 (0x00007ffcd41cc000)
libclang-cpp.so.16 => not found
libLLVM-16.so => not found
libstdc++.so.6 => not found
libz.so.1 => not found
libc.so.6 => /gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-2.35/lib/libc.so.6 (0x00007fbeda5b0000)
/usr/lib64/ld-linux-x86-64.so.2 => /gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-2.35/lib/ld-linux-x86-64.so.2 (0x00007fbeda7ae000) |
I, too, am trying to build it on Guix. This here seems to work for adding the arguments: diff -crB zig.orig/CMakeLists.txt zig/CMakeLists.txt
*** zig.orig/CMakeLists.txt 2024-04-16 00:59:10.664981173 +0200
--- zig/CMakeLists.txt 2024-04-16 02:33:53.218625749 +0200
***************
*** 921,926 ****
--- 921,932 ----
"-Dversion-string=${RESOLVED_ZIG_VERSION}"
)
+ string(REPLACE ":" ";" LIBRARY_PATH "$ENV{LIBRARY_PATH}")
+ foreach(entry ${LIBRARY_PATH})
+ LIST(APPEND ZIG_BUILD_ARGS "--search-prefix")
+ LIST(APPEND ZIG_BUILD_ARGS "${entry}")
+ endforeach()
+
add_custom_target(stage3 ALL
DEPENDS "${CMAKE_BINARY_DIR}/stage3/bin/zig"
) And results in the following command:
The
|
Guix is too far behind Zig versions at this point, so it's really not fan to write Zig with it at the moment. I have some hope that this will be resolved in the future. See ziglang/zig#18434
As of zig 0.12, I am getting a bunch of these warnings building stage3:
The check phase still fails completely, but with a slightly different error this time:
Unfortunately, I don't have even remotely enough knowledge to fix this, or to know where to look for more infos, but here's hoping someone who knows will drop by. EDIT: for reference, my package definition is here: https://gitea.lyrion.ch/zilti/guixchannel/src/branch/master/zilti/packages/zig.scm |
Useful when someone wants to pass argument that is not yet exposed to CMake via "ZIG_WHATEVER" option, for example "--search-prefix" from here: ziglang#18434 . Also bump minimum CMake version to "3.9". Signed-off-by: Eric Joldasov <[email protected]>
Useful when someone wants to pass argument that is not yet exposed to CMake via "ZIG_WHATEVER" option, for example "--search-prefix" from here: ziglang#18434 . Also change order of arguments in cmake/install.cmake to be the same as in CMakeLists.txt, so that "--prefix" can be overriden in both steps. Also bump minimum CMake version to "3.9". Signed-off-by: Eric Joldasov <[email protected]>
Useful when someone wants to pass argument that is not yet exposed to CMake via `ZIG_WHATEVER` option, for example `--search-prefix` from here: ziglang#18434 . Also change order of arguments in cmake/install.cmake to be the same as in CMakeLists.txt, so that `--prefix` can be overriden in both steps. Also bump minimum CMake version to "3.9". Signed-off-by: Eric Joldasov <[email protected]>
Any updates on this? |
Still doesn't build. I bet maintainers even unaware of this issue. |
@nektro would you mind sharing how this was resolved on NixOS? Are you applying patches to build |
This issue should be addressed on Guix side (wip-zig-bootstrap branch) now, please help test it out! :) |
@rakino Thank you for your work! I'll try building and testing BunJS locally. |
Zig Version
Steps to Reproduce and Observed Behavior
I'm trying to package Zig 0.11 on Guix: currently, there is only 0.10 available, and I believe 0.11 is major step forward. To what, indeed?
I've already tried to package zig when there was only 0.9 (and I was trying 0.10). That time I failed, and now, with 0.11 release out - with it comes new self-hosting compiler.
Compilers! Especially self-hosting! What would be even more interesting?
I've really enjoyed reading a blog post explaining approach Zig has been taken with self-hosting problem. (If you didn't mind, self-hosted compilers usually become a major obstacle for distro maintainers & packagers. They also create funny chain of dependency on it's "previous self", which is also major impact to problem surface packagers tries to solve.)
I also really appreciate how Zig Build System tries to integrate with the world. And, finally, building a compiler with it's build system with just one command is really pleasurable.
So, what is the bug, and how to reproduce it? Here is a Guix Package definition, which one can use to reproduce this bug:
Save it to any location, and then use with
guix build
command's--file
option (notezig-0.11
variable at the end of such a file):$ guix build --keep-failed -f zig.scm # keep build results for further investigation
Build process will be finished successfully, but
check
phase will fail because ofzig3
improperly linked with system libraries (command used to buildzig3
just for convenience):Why so?
It is dynamically linked executable, as expected (and supposed by) Guix build process.
It is not only linked against system-wide libraries, but also missing one completely (that one is from
ZIG_CLANG_LIBRARIES
list).The problem is that, whenever
zig2
get's built with "system compiler" - all the dependencies properly resolved thanks to cmake. But whenzig build
kicks in - this integration get's lost. Although I read carefully Zig Build System documentation, and there is--search-prefix
option tozig build
, I didn't find any way to propose those search prefix(es) from cmake part, which is actually used to build compiler: it has a bunch of options which one can set withcmake -DZIG_SHARED_LLVM=ON
etc, but cmake has no any attempt to propagate discovered libraries tozig build
, IIUC (from readingbuild.zig
of0.11.0
tag, and sporadicstd.build
chunks).Although I managed to pass those
--search-prefix
es to./zig2 build ...
while debugging, it seems like that has no effect at this particular problem:zig3
get's linked against system libraries no matter what I pass to--search-prefix
.I did some search of similar issues before opening this one, here some examples:
/usr/bin/env
to detect dynamic-linker path #14577All they relate in some way to proper discovery of libraries (and headers) when one do choose to build from source, but mostly system-specific: there is no problem with libraries discovery when
zig2
get's built with system compiler whenever one's system compiler is able to properly discover shared libraries. There is no such problem on Guix:The problem is that there is no way to communicate desired choices of libraries to
./zig2 build
usingcmake
.Also, note there was attempts (in Guix) to patch
std.build
to properly handle library discovery, using mechanism known as "search paths" (meaning that there was attempt to make zig respect some C-related well-defined search paths).I think, this again touches the same pain point. What do you think?
I opening this bug here, in Zig upstream because I believe this is a Zig problem - not eg. Guix. Also, from the packager point, there is no room to "fix" this using Guix build process: all one can do is to resort to patching of cmake's generated build files, which I think is no-option in Guix upstream.
Expected Behavior
Zig 0.11.0 get's built with provided Guix Package definition, with
zig3
's executable dynamically linked against Guix shared libraries (package inputs).The text was updated successfully, but these errors were encountered: