zig icon indicating copy to clipboard operation
zig copied to clipboard

zig 0.12.0 ignores DESTDIR (cmake) on NetBSD (fails to install in chrooted builds)

Open nikkicoon opened this issue 10 months ago • 13 comments

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

Building zig 0.12.0 on NetBSD 10.99.10 (GENERIC) amd64 inside a pbulk build chroot ignore DESTDIR. (build receipe on pkgsrc: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/lang/zig/Makefile?rev=1.32&content-type=text/x-cvsweb-markup)

snippet from the build logs:

=> Bootstrap dependency digest>=20211023: found digest-20220214
===> Skipping vulnerability checks.
WARNING: No /usr/pkg/pkgdb/pkg-vulnerabilities file found.
WARNING: To fix run: `/usr/sbin/pkg_admin -K /usr/pkg/pkgdb fetch-pkg-vulnerabilities'.
===> Building for zig-0.12.0
[  5%] Building C object CMakeFiles/zig-wasm2c.dir/stage1/wasm2c.c.o
[ 10%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_llvm-ar.cpp.o
[ 15%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_llvm.cpp.o
[ 21%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_clang.cpp.o
[ 26%] Linking C executable zig-wasm2c
[ 26%] Built target zig-wasm2c
[ 31%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_clang_driver.cpp.o
[ 36%] Converting /tmp/work/zig-0.12.0/stage1/zig1.wasm to /tmp/work/zig-0.12.0/cmake-pkgsrc-build/zig1.c
[ 42%] Building C object CMakeFiles/zig1.dir/stage1/wasi.c.o
[ 47%] Building C object CMakeFiles/zig1.dir/zig1.c.o
[ 52%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_clang_cc1_main.cpp.o
[ 57%] Building CXX object CMakeFiles/zigcpp.dir/src/zig_clang_cc1as_main.cpp.o
[ 63%] Linking CXX static library zigcpp/libzigcpp.a
[ 63%] Built target zigcpp
[ 68%] Linking C executable zig1
[ 68%] Built target zig1
[ 78%] Running zig1.wasm to produce /tmp/work/zig-0.12.0/cmake-pkgsrc-build/compiler_rt.c
[ 78%] Running zig1.wasm to produce /tmp/work/zig-0.12.0/cmake-pkgsrc-build/zig2.c
[ 89%] Building C object CMakeFiles/zig2.dir/compiler_rt.c.o
[ 89%] Building C object CMakeFiles/zig2.dir/zig2.c.o
[ 94%] Linking CXX executable zig2
[ 94%] Built target zig2
[100%] Building stage3
[100%] Built target stage3
=> Bootstrap dependency digest>=20211023: found digest-20220214
=> Checksum BLAKE2s OK for zig-0.12.0.tar.xz
=> Checksum SHA512 OK for zig-0.12.0.tar.xz
=> Bootstrap dependency digest>=20211023: found digest-20220214
=> Checksum BLAKE2s OK for zig-0.12.0.tar.xz
=> Checksum SHA512 OK for zig-0.12.0.tar.xz
===> Installing dependencies for zig-0.12.0
==========================================================================
The following variables will affect the build process of this package,
zig-0.12.0.  Their current value is shown below:

        * TERMINFO_DEFAULT = terminfo

Based on these variables, the following variables have been set:

        * TERMINFO_TYPE = terminfo

You may want to abort the process now with CTRL-C and change the value
of variables in the first group before continuing.  Be sure to run
`/usr/bin/make clean' after the changes.
==========================================================================
=> Tool dependency cmake>=0: found cmake-3.29.2
=> Tool dependency mktools-[0-9]*: found mktools-20220614
=> Tool dependency cwrappers>=20150314: found cwrappers-20220403
=> Tool dependency checkperms>=1.1: found checkperms-1.12
=> Full dependency bash-[0-9]*: found bash-5.2.26nb1
=> Full dependency lld>=17.0.0<18: found lld-17.0.6
=> Full dependency llvm>=17.0.0<18: found llvm-17.0.6
=> Full dependency clang>=17.0.0<18: found clang-17.0.6
===> Skipping vulnerability checks.
WARNING: No /usr/pkg/pkgdb/pkg-vulnerabilities file found.
WARNING: To fix run: `/usr/sbin/pkg_admin -K /usr/pkg/pkgdb fetch-pkg-vulnerabilities'.
===> Overriding tools for zig-0.12.0
===> Extracting for zig-0.12.0
===> Patching for zig-0.12.0
===> Creating toolchain wrappers for zig-0.12.0
===> Configuring for zig-0.12.0
=> Checking for portability problems in extracted files
-- The C compiler identification is GNU 10.5.0
-- The CXX compiler identification is GNU 10.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /tmp/work/.cwrapper/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /tmp/work/.cwrapper/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring zig version 0.12.0
-- Found llvm: /usr/pkg/lib/libLLVM-17.so;-lrt;-lexecinfo;-lpthread;-lm;-lz;-lzstd;-lterminfo;-lxml2 (Required is at least version "17")
-- Found clang: /usr/pkg/lib/libclang-cpp.so.17 (Required is at least version "17")
-- Found lld: /usr/pkg/lib/liblldMinGW.a;/usr/pkg/lib/liblldELF.a;/usr/pkg/lib/liblldCOFF.a;/usr/pkg/lib/liblldWasm.a;/usr/pkg/lib/liblldMachO.a;/usr/pkg/lib/liblldCommon.a (Required is at least version "17")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done (1.0s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_INSTALL_LIBDIR
    CMAKE_INSTALL_MANDIR
    DESTDIR

===> Installing for zig-0.12.0
=> Generating pre-install file lists
[ 36%] Built target zigcpp
[ 47%] Built target zig-wasm2c
[ 68%] Built target zig1
[ 94%] Built target zig2
[100%] Built target stage3
Install the project...
-- Install configuration: "Release"
error: AccessDenied
::
:: ERROR: 1
:: (execute_process)
::
:: argv: /tmp/work/zig-0.12.0/cmake-pkgsrc-build/zig2 build --zig-lib-dir /tmp/work/zig-0.12.0/lib -Dconfig_h=/tmp/work/zig-0.12.0/cmake-pkgsrc-build/config.h -Denable-llvm -Doptimize=ReleaseFast -Dstrip -Dno-langref -Dtarget=native -Dcpu=baseline -Dversion-string=0.12.0 --prefix /usr/pkg
::
:: argv[0]: /tmp/work/zig-0.12.0/cmake-pkgsrc-build/zig2
:: argv[1]: build
:: argv[2]: --zig-lib-dir
:: argv[3]: /tmp/work/zig-0.12.0/lib
:: argv[4]: -Dconfig_h=/tmp/work/zig-0.12.0/cmake-pkgsrc-build/config.h
:: argv[5]: -Denable-llvm
:: argv[6]: -Doptimize=ReleaseFast
:: argv[7]: -Dstrip
:: argv[8]: -Dno-langref
:: argv[9]: -Dtarget=native
:: argv[10]: -Dcpu=baseline
:: argv[11]: -Dversion-string=0.12.0
:: argv[12]: --prefix
:: argv[13]: /usr/pkg
::
CMake Error at /tmp/work/zig-0.12.0/cmake/install.cmake:26 (message):
Call Stack (most recent call first):
  cmake_install.cmake:57 (include)


*** Error code 1

Stop.
make[2]: stopped in /tmp/work/zig-0.12.0/cmake-pkgsrc-build
*** Error code 1

Stop.
make: stopped in /usr/pkgsrc/lang/zig

Expected Behavior

zig should install.

nikkicoon avatar Apr 24 '24 08:04 nikkicoon

since nothing substantial changed in the cmake parts for 2 years, I guess you no longer use cmake for install but build.zig and something changed between 0.11 and 0.12 in the code which handles the installation.

nikkicoon avatar Apr 25 '24 09:04 nikkicoon

using CMAKE_CONFIGURE_ARGS+= -DCMAKE_INSTALL_PREFIX=${DESTDIR}${PREFIX} doesn't change a thing in the outcome.

I'd appreciate pointers in how/where to make zig install in our chroot build environment again.

nikkicoon avatar Apr 25 '24 22:04 nikkicoon

using CMAKE_CONFIGURE_ARGS+= -DCMAKE_INSTALL_PREFIX=${DESTDIR}${PREFIX} doesn't change a thing in the outcome.

I'd appreciate pointers in how/where to make zig install in our chroot build environment again.

The CMAKE_INSTALL_PREFIX used as follows works for me.

cmake -G Ninja -S . -B _build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/opt/zig-0.12.0-30-6fd09f8d2d -DCMAKE_PREFIX_PATH=/opt/llvm-netbsd10.0-amd64-17.0.6-release -DCMAKE_C_FLAGS=-fdiagnostics-color -DCMAKE_CXX_FLAGS=-fdiagnostics-color -DZIG_STATIC=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DZIG_PIE=OFF

followed by

ninja -C _build -j8
ninja -C _build -j8 install

mikdusan avatar Apr 26 '24 21:04 mikdusan

I have to add: it works outside of a chroot without issues. I can safely build and install zig when I run it from pkgsrc as a user (make clean; make package). What you replied didn't look like a build in a pbulk pkgsrc chroot.

The issue for this ticket is:

When the build runs in a pbulk chroot build, it fails to install.

nikkicoon avatar Apr 26 '24 22:04 nikkicoon

this looks sus:

:: argv[12]: --prefix
:: argv[13]: /usr/pkg
::

is it possible something stripped the original --prefix placement which usually would go at argv[2] and appended the hard coded value?

mikdusan avatar Apr 27 '24 13:04 mikdusan

We've changed nothing which would touch this (to my knowledge), that's why we're asking you what changed between 0.11 and 0.12 that we'd encounter this suddenly.

nikkicoon avatar Apr 27 '24 13:04 nikkicoon

so in this case, is --prefix /usr/pkg correct and the chroot user pbulk ? has write access?

mikdusan avatar Apr 27 '24 14:04 mikdusan

pbulk (or anything building) doesn't have write access to /usr/pkg. The builds of pkgsrc happen in ${WRKSRC}, which by default is ${WRKDIR}/${DISTNAME}. We write something like a binary named "zig" to (for example) /usr/work/lang/zig/work/.destdir/usr/pkg/bin, where /usr/pkg is ${PREFIX} and iirc the whole thing before that is the destdir. this is writable in the build environment. Upon package creation, it gets transformed to strip away all that and actual install happens to the real prefix, /usr/pkg for example

nikkicoon avatar Apr 27 '24 14:04 nikkicoon

are you perhaps on discord or zig's irc?

mikdusan avatar Apr 27 '24 14:04 mikdusan

I am on irc, but I don't have enough time today. Tomorrow I'm available.

nikkicoon avatar Apr 27 '24 14:04 nikkicoon

feel free to ping me. I'm on as freshcoffee in libera #zig

mikdusan avatar Apr 27 '24 14:04 mikdusan

thanks, will do!

nikkicoon avatar Apr 27 '24 14:04 nikkicoon

Not really a fix, but what if I packaged the zig-bootstrap, used that to build zig and see if we run into the same issue?

zig build and builds+installs of the zig package in general seem to work for non-root, non-chroot'ed users...

nikkicoon avatar Apr 29 '24 13:04 nikkicoon

Any idea what's going on here, further blockers?

nikkicoon avatar Jun 08 '24 11:06 nikkicoon