Skip to content
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

Alpine: some dev packages raise triggers that fail #36

Closed
epoupon opened this issue Sep 24, 2021 · 12 comments
Closed

Alpine: some dev packages raise triggers that fail #36

epoupon opened this issue Sep 24, 2021 · 12 comments

Comments

@epoupon
Copy link

epoupon commented Sep 24, 2021

Hello,

I am trying to cross build my application using your project.
Unfortunately I have dependencies to rather big packages like libboost-dev or ffmpeg-dev and they trigger things like that:

...
#11 9.281 (75/91) Installing zstd-libs (1.4.9-r1)
#11 9.312 (76/91) Installing libarchive (3.5.1-r0)
#11 9.338 (77/91) Installing busybox (1.33.1-r3)
#11 9.372 Executing busybox-1.33.1-r3.post-install
#11 9.377 ERROR: busybox-1.33.1-r3.post-install: script exited with error 127
#11 9.377 (78/91) Installing ca-certificates (20191127-r5)
#11 9.416 (79/91) Installing brotli-libs (1.0.9-r5)
#11 9.444 (80/91) Installing nghttp2-libs (1.43.0-r0)
#11 9.465 (81/91) Installing libcurl (7.79.1-r0)
#11 9.492 (82/91) Installing rhash-libs (1.4.1-r0)
#11 9.514 (83/91) Installing libuv (1.41.0-r0)
#11 9.538 (84/91) Installing cmake (3.20.3-r0)
#11 10.11 (85/91) Installing gtest-dev (1.11.0-r0)
#11 10.14 (86/91) Installing libconfig++ (1.7.2-r0)
#11 10.16 (87/91) Installing libconfig (1.7.2-r0)
#11 10.18 (88/91) Installing libconfig-dev (1.7.2-r0)
#11 10.20 (89/91) Installing musl-dev (1.2.2-r3)
#11 10.32 (90/91) Installing taglib (1.12-r0)
#11 10.35 (91/91) Installing taglib-dev (1.12-r0)
#11 10.39 Executing busybox-1.33.1-r3.trigger
#11 10.40 ERROR: busybox-1.33.1-r3.trigger: script exited with error 127
#11 10.40 Executing ca-certificates-20191127-r5.trigger
#11 10.40 ERROR: ca-certificates-20191127-r5.trigger: script exited with error 127
#11 10.42 1 error; 443 MiB in 92 packages

Do you know a solution for this problem?

@tonistiigi
Copy link
Owner

tonistiigi commented Sep 24, 2021

These packages run binaries for the target arch during installation so the triggers need to run through the emulation layer. You can install emulators with https://github.com/tonistiigi/binfmt

docker run --privileged -it --rm tonistiigi/binfmt --install all

Notice this is only for the package trigger scripts. Your xx compilation will not go through qemu. Usually, this is not needed as packages you should install with xx-apt are the ones that contain the headers and libraries, but sometimes the dependencies between packages are not very well defined and you get extra things you don't actually need.

An alternative is to use xx-apk add --no-scripts to not run these scripts. Usually, things work without them for cross-compilation use cases. Eg. xx-apk by default removes all the installed binaries anyway

xx/base/xx-apk

Lines 104 to 106 in d69b72b

if [ -z "$XX_APK_KEEP_BINARIES" ]; then
rm -rf "/${XX_TRIPLE:?}/usr/bin/*"
fi

@epoupon
Copy link
Author

epoupon commented Sep 24, 2021

Thanks for you answer!
I went for the --no-scripts option

Unfortunately I still hit some problem at the cmake step:

cmake $(xx-clang --print-cmake-defines) .
cmake -DCMAKE_BUILD_TYPE=Release $(xx-clang --print-cmake-defines) . &&               VERBOSE=1 make:
#16 0.981 -- The C compiler identification is Clang 11.1.0
#16 1.052 -- The CXX compiler identification is Clang 11.1.0
#16 1.065 -- Detecting C compiler ABI info
#16 1.214 -- Detecting C compiler ABI info - done
#16 1.227 -- Check for working C compiler: /usr/local/bin/clang - skipped
#16 1.227 -- Detecting C compile features
#16 1.228 -- Detecting C compile features - done
#16 1.233 -- Detecting CXX compiler ABI info
#16 1.376 -- Detecting CXX compiler ABI info - failed
#16 1.376 -- Check for working CXX compiler: /usr/local/bin/clang++
#16 1.518 -- Check for working CXX compiler: /usr/local/bin/clang++ - broken
#16 1.519 -- Configuring incomplete, errors occurred!
#16 1.519 See also "/tmp/lms/build/CMakeFiles/CMakeOutput.log".
#16 1.519 See also "/tmp/lms/build/CMakeFiles/CMakeError.log".
#16 1.519 CMake Error at /usr/share/cmake/Modules/CMakeTestCXXCompiler.cmake:59 (message):
#16 1.519   The C++ compiler
#16 1.519
#16 1.519     "/usr/local/bin/clang++"
#16 1.519
#16 1.519   is not able to compile a simple test program.
#16 1.519
#16 1.519   It fails with the following output:
#16 1.519
#16 1.519     Change Dir: /tmp/lms/build/CMakeFiles/CMakeTmp
#16 1.519
#16 1.519     Run Build Command(s):/usr/bin/make -f Makefile cmTC_35ca4/fast && /usr/bin/make  -f CMakeFiles/cmTC_35ca4.dir/build.make CMakeFiles/cmTC_35ca4.dir/build
#16 1.519     make[1]: Entering directory '/tmp/lms/build/CMakeFiles/CMakeTmp'
#16 1.519     Building CXX object CMakeFiles/cmTC_35ca4.dir/testCXXCompiler.cxx.o
#16 1.519     /usr/local/bin/clang++ --target=aarch64-alpine-linux-musl   -I/tmp/install/include  -MD -MT CMakeFiles/cmTC_35ca4.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_35ca4.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_35ca4.dir/testCXXCompiler.cxx.o -c /tmp/lms/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
#16 1.519     Linking CXX executable cmTC_35ca4
#16 1.519     /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_35ca4.dir/link.txt --verbose=1
#16 1.519     /usr/local/bin/clang++ --target=aarch64-alpine-linux-musl -I/tmp/install/include  CMakeFiles/cmTC_35ca4.dir/testCXXCompiler.cxx.o -o cmTC_35ca4
#16 1.519     ld.lld: error: unable to find library -lstdc++
#16 1.519     clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
#16 1.519     make[1]: *** [CMakeFiles/cmTC_35ca4.dir/build.make:100: cmTC_35ca4] Error 1
#16 1.519     make[1]: Leaving directory '/tmp/lms/build/CMakeFiles/CMakeTmp'
#16 1.519     make: *** [Makefile:127: cmTC_35ca4/fast] Error 2

I installed: clang make cmake lld curl pkgconfig using regular apk
and gcc musl-dev boost-dev libconfig-dev taglib-dev gtest-dev using xx-apk

@tonistiigi
Copy link
Owner

tonistiigi commented Sep 24, 2021

@epoupon
Copy link
Author

epoupon commented Sep 25, 2021

Thanks, that did the trick!
Very good initiative for #37 , that I was willing to suggest!

@epoupon epoupon closed this as completed Sep 25, 2021
@epoupon
Copy link
Author

epoupon commented Sep 25, 2021

Sorry, hijacking this thread again...

This time, it looks like pkg config or cmake cannot find any dependency.
Example for Gtest-dev:

find_package(GTest REQUIRED)
#16 [stage-1 10/10] RUN         CMAKE_MODULE_PATH=/$(xx-info triple)/usr/share/cmake/Modules CXXFLAGS="-I/tmp/install/include -I/$(xx-info triple)/usr/include" cmake -DCMAKE_BUILD_TYPE=Release $(xx-clang --print-cmake-defines) . &&            VERBOSE=1 make
#16 sha256:627a24b4ce39aab9e75d60dcf3315488c1db957cea94a460e5034b537dd52239
#16 0.716 -- The C compiler identification is Clang 11.1.0
#16 0.790 -- The CXX compiler identification is Clang 11.1.0
#16 0.802 -- Detecting C compiler ABI info
#16 0.947 -- Detecting C compiler ABI info - done
#16 0.960 -- Check for working C compiler: /usr/local/bin/clang - skipped
#16 0.961 -- Detecting C compile features
#16 0.961 -- Detecting C compile features - done
#16 0.967 -- Detecting CXX compiler ABI info
#16 1.113 -- Detecting CXX compiler ABI info - done
#16 1.131 -- Check for working CXX compiler: /usr/local/bin/clang++ - skipped
#16 1.132 -- Detecting CXX compile features
#16 1.133 -- Detecting CXX compile features - done
#16 1.143 -- Found PkgConfig: /usr/bin/aarch64-alpine-linux-musl-pkg-config (found version "1.7.4")
#16 1.145 -- Looking for pthread.h
#16 1.290 -- Looking for pthread.h - found
#16 1.291 -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
#16 1.440 -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
#16 1.444 -- Found Threads: TRUE
#16 1.446 -- Looking for C++ include filesystem
#16 2.506 -- Looking for C++ include filesystem - found
#16 2.506 -- Performing Test CXX_FILESYSTEM_NO_LINK_NEEDED
#16 3.562 -- Performing Test CXX_FILESYSTEM_NO_LINK_NEEDED - Success
#16 3.574 CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
#16 3.574   Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR
#16 3.574   GTEST_MAIN_LIBRARY)
#16 3.574 Call Stack (most recent call first):
#16 3.574   /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
#16 3.574   /usr/share/cmake/Modules/FindGTest.cmake:255 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
#16 3.574   CMakeLists.txt:17 (find_package)
#16 3.574
#16 3.574
#16 3.574 -- Configuring incomplete, errors occurred!

I tried to play with CMAKE_MODULE_PATH with no success.
pkgconfig based stuff do not seem to work either.

Any clue?

@tonistiigi
Copy link
Owner

tonistiigi commented Sep 25, 2021

find_package does not use pkg-config (unfortunately). That resolution logic is built into cmake and cmake definitions that come with gtest-dev. https://cmake.org/cmake/help/latest/module/FindGTest.html

I think setting CMAKE_MODULE_PATH is not the correct approach here. Ideally, you don't have separate cmake per target. Also, you should use -DCMAKE_MODULE_PATH= not env.

What you need should be -DCMAKE_LIBRARY_PATH=/$(xx-info)/usr/lib -DCMAKE_INCLUDE_PATH=/$(xx-info)/usr/include or more cleanly -DCMAKE_PREFIX_PATH=/$(xx-info)/usr. I think we could include it automatically in --print-cmake-defines (if you confirm it fixes) as it shouldn't break any non-cmake resolution.

edit: you shouldn't also need any -I/$(xx-info triple)/usr/include CXXFLAGS stuff

@epoupon
Copy link
Author

epoupon commented Sep 25, 2021

Indeed for -I/$(xx-info triple)/usr/include, that was a part of my investigation that did not have any effect.

Well -DCMAKE_PREFIX_PATH=/$(xx-info)/usr broke everything (clang not even able to compile a simple C file), but -DCMAKE_PREFIX_PATH=/$(xx-info)/usr/lib/cmake made gtest, boost and even wt (package wt-dev) detected.

For pkgconfig based stuff, I added the env var PKG_CONFIG_PATH=/$(xx-info)/usr/lib/pkgconfig to make them work (things like taglib-dev, libconfig-dev

Now I have custom .cmake scripts that fail, I will investigate them as they are very likely to be badly written.

Thanks again for your valuable help!

@tonistiigi
Copy link
Owner

For pkgconfig based stuff, I added the env var PKG_CONFIG_PATH=/$(xx-info)/usr/lib/pkgconfig to make them work (things like taglib-dev, libconfig-dev

Hm. I changed this to use sysroot_dir in 95fac1d#diff-cae662172fd450bb0cd710a769079c05bfc5d8e35efa6576edc7d0377afdd4a2 that worked better. I wonder what is different for you.

@epoupon
Copy link
Author

epoupon commented Sep 26, 2021

Another problem: it seems It cannot create static libraries, I get this:

#15 190.0 make  -f src/libs/som/CMakeFiles/lmssom.dir/build.make src/libs/som/CMakeFiles/lmssom.dir/depend
#15 190.0 make[2]: Entering directory '/tmp/lms/build'
#15 190.0 cd /tmp/lms/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /tmp/lms /tmp/lms/src/libs/som /tmp/lms/build /tmp/lms/build/src/libs/som /tmp/lms/build/src/libs/som/CMakeFiles/lmssom.dir/DependInfo.cmake --color=
#15 190.0 make[2]: Leaving directory '/tmp/lms/build'
#15 190.0 make  -f src/libs/som/CMakeFiles/lmssom.dir/build.make src/libs/som/CMakeFiles/lmssom.dir/build
#15 190.0 make[2]: Entering directory '/tmp/lms/build'
#15 190.0 [ 40%] Building CXX object src/libs/som/CMakeFiles/lmssom.dir/impl/DataNormalizer.cpp.o
#15 190.0 cd /tmp/lms/build/src/libs/som && /usr/local/bin/clang++ --target=aarch64-alpine-linux-musl -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -I/tmp/lms/src/libs/som/include -I/tmp/lms/src/libs/utils/include -I/tmp/install/include -O3 -DNDEBUG -fPIC -Wall -Wextra -pedantic -std=gnu++17 -MD -MT src/libs/som/CMakeFiles/lmssom.dir/impl/DataNormalizer.cpp.o -MF CMakeFiles/lmssom.dir/impl/DataNormalizer.cpp.o.d -o CMakeFiles/lmssom.dir/impl/DataNormalizer.cpp.o -c /tmp/lms/src/libs/som/impl/DataNormalizer.cpp
#15 191.3 [ 41%] Building CXX object src/libs/som/CMakeFiles/lmssom.dir/impl/Network.cpp.o
#15 191.3 cd /tmp/lms/build/src/libs/som && /usr/local/bin/clang++ --target=aarch64-alpine-linux-musl -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -I/tmp/lms/src/libs/som/include -I/tmp/lms/src/libs/utils/include -I/tmp/install/include -O3 -DNDEBUG -fPIC -Wall -Wextra -pedantic -std=gnu++17 -MD -MT src/libs/som/CMakeFiles/lmssom.dir/impl/Network.cpp.o -MF CMakeFiles/lmssom.dir/impl/Network.cpp.o.d -o CMakeFiles/lmssom.dir/impl/Network.cpp.o -c /tmp/lms/src/libs/som/impl/Network.cpp
#15 194.1 [ 42%] Linking CXX static library liblmssom.a
#15 194.1 cd /tmp/lms/build/src/libs/som && /usr/bin/cmake -P CMakeFiles/lmssom.dir/cmake_clean_target.cmake
#15 194.1 cd /tmp/lms/build/src/libs/som && /usr/bin/cmake -E cmake_link_script CMakeFiles/lmssom.dir/link.txt --verbose=1
#15 194.1 CMAKE_AR-NOTFOUND qc liblmssom.a CMakeFiles/lmssom.dir/impl/DataNormalizer.cpp.o CMakeFiles/lmssom.dir/impl/Network.cpp.o
#15 194.1 Error running link command: No such file or directory

@epoupon
Copy link
Author

epoupon commented Sep 26, 2021

Another problem: I don't understand why it cannot find a header file:

I use this in my cmake file:
find_path(STB_INCLUDE_DIR stb/stb.h)
I installed the stb header library in ${PREFIX}/include/stb (PREFIX = /tmp/install)

And then:
PKG_CONFIG_PATH=/$(xx-info)/usr/lib/pkgconfig CXXFLAGS="-I${PREFIX}/include" cmake -DCMAKE_BUILD_TYPE=${LMS_BUILD_TYPE} $(xx-clang --print-cmake-defines) -DCMAKE_PREFIX_PATH=/$(xx-info)/usr/lib/cmake .

(I pushed the current state of my stuff in https://github.com/epoupon/lms/blob/cross-compile/Dockerfile-build)
I can see the -I/tmp/install/include during the compilation, not sure why it does not make cmake find the file?
(it works fine if I put the full path in find_path)

@tonistiigi
Copy link
Owner

#15 194.1 CMAKE_AR-NOTFOUND qc liblmssom.a

Looks like you are missing apk add llvm (not xx-apk) for the ar

Haven't looked at the include issue yet

@tonistiigi
Copy link
Owner

For the include, if the error you get is in cmake resolution (not in compilation) then I think you need -DCMAKE_INCLUDE_PATH= . You can also likely define STB_INCLUDE_DIR directly if that is cleaner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants