tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

cross compiling #2733

Closed firmwarecostum closed 10 months ago

firmwarecostum commented 10 months ago

can you add CMAKE_CROSSCOMPILING to make cross compilation easier. so the command when building td cmake -DCMAKE_CROSSCOMPILING and no longer using the prepare_cross_compiling tried building this in openwrt. or maybe you have an idea to change CMakeLists.txt to run cross compilation i include logs when i build td which fails

SHELL= flock /home/open/wrt/tmp/.td-1.8.0.tar.gz.flock -c '     /home/open/wrt/scripts/download.pl "/home/open/wrt/dl" "td-1.8.0.tar.gz" "skip" "" "https://codeload.github.com/tdlib/td/tar.gz/v1.8.0?"    '
touch /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/.prepared_c80d7fb28354f4e84026baac6685e01c_6664517399ebbbc92a37c5bb081b5c53_check
. /home/open/wrt/include/shell.sh; /home/open/wrt/staging_dir/host/bin/libdeflate-gzip
-dc /home/open/wrt/dl/td-1.8.0.tar.gz | tar -C /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/.. -xf -
[ ! -d ./src/ ] || cp -fpR ./src/. /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0
touch /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/.prepared_c80d7fb28354f4e84026baac6685e01c_6664517399ebbbc92a37c5bb081b5c53
rm -f /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/.configured_*
rm -f /home/open/wrt/staging_dir/target-aarch64_generic_musl/stamp/.td_installed
mkdir -p /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/build
(cd /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/build; CFLAGS="-Os -pipe -mcpu=generic -fno-caller-saves -fno-plt -fhonour-copts -ffile-prefix-map=/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0=td-1.8.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CXXFLAGS="-Os -pipe -mcpu=generic -fno-caller-saves -fno-plt -fhonour-copts -ffile-prefix-map=/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0=td-1.8.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " LDFLAGS="-L/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/usr/lib -L/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/lib -znow -zrelro " cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_VERSION=1 -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" -DCMAKE_C_COMPILER_LAUNCHER="" -DCMAKE_C_COMPILER="/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-musl-gcc" -DCMAKE_CXX_COMPILER_LAUNCHER="" -DCMAKE_CXX_COMPILER="/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-musl-g++" -DCMAKE_ASM_COMPILER_LAUNCHER="" -DCMAKE_ASM_COMPILER="/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-musl-gcc" -DCMAKE_EXE_LINKER_FLAGS:STRING="-L/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/usr/lib -L/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/lib -znow -zrelro" -DCMAKE_MODULE_LINKER_FLAGS:STRING="-L/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/usr/lib -L/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/lib -znow -zrelro -Wl,-Bsymbolic-functions" -DCMAKE_SHARED_LINKER_FLAGS:STRING="-L/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/usr/lib -L/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/lib -znow -zrelro -Wl,-Bsymbolic-functions" -DCMAKE_AR="/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-musl-gcc-ar" -DCMAKE_NM="/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-musl-gcc-nm" -DCMAKE_RANLIB="/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-musl-gcc-ranlib" -DCMAKE_FIND_ROOT_PATH="/home/open/wrt/staging_dir/target-aarch64_generic_musl/usr;/home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl" -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_STRIP=: -DCMAKE_INSTALL_PREFIX=/usr -DDL_LIBRARY=/home/open/wrt/staging_dir/target-aarch64_generic_musl -DCMAKE_PREFIX_PATH=/home/open/wrt/staging_dir/target-aarch64_generic_musl -DCMAKE_SKIP_RPATH=TRUE -DCMAKE_EXPORT_PACKAGE_REGISTRY=FALSE -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=TRUE -DCMAKE_FIND_USE_PACKAGE_REGISTRY=FALSE -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=TRUE -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=FALSE -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=TRUE -DCMAKE_GENERATOR="Ninja" /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0 )
-- The CXX compiler identification is GNU 12.3.0
-- The C compiler identification is GNU 12.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-musl-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-musl-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found ccache
-- Found OpenSSL: /home/open/wrt/staging_dir/target-aarch64_generic_musl/usr/lib/libcrypto.so (found version "3.0.12")
-- Found OpenSSL: /home/open/wrt/staging_dir/target-aarch64_generic_musl/usr/include /home/open/wrt/staging_dir/target-aarch64_generic_musl/usr/lib/libssl.so;/home/open/wrt/staging_dir/target-aarch64_generic_musl/usr/lib/libcrypto.so
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Performing Test HAVE_STD14
-- Performing Test HAVE_STD14 - Success
-- Performing Test HAVE_CXX_FLAG_WALL
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2
-- Performing Test HAVE_CXX_FLAG_WIMPLICIT_FALLTHROUGH_2 - Success
-- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH
-- Performing Test HAVE_CXX_FLAG_WPOINTER_ARITH - Success
-- Performing Test HAVE_CXX_FLAG_WCAST_QUAL
-- Performing Test HAVE_CXX_FLAG_WCAST_QUAL - Success
-- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE
-- Performing Test HAVE_CXX_FLAG_WSIGN_COMPARE - Success
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_BRANCHES - Success
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND
-- Performing Test HAVE_CXX_FLAG_WDUPLICATED_COND - Success
-- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO
-- Performing Test HAVE_CXX_FLAG_WALLOC_ZERO - Success
-- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP
-- Performing Test HAVE_CXX_FLAG_WLOGICAL_OP - Success
-- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE
-- Performing Test HAVE_CXX_FLAG_WTAUTOLOGICAL_COMPARE - Success
-- Performing Test HAVE_CXX_FLAG_WVLA
-- Performing Test HAVE_CXX_FLAG_WVLA - Success
-- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_FLAG_WNON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER
-- Performing Test HAVE_CXX_FLAG_WUNUSED_PARAMETER - Success
-- Performing Test HAVE_CXX_FLAG_WCONVERSION
-- Performing Test HAVE_CXX_FLAG_WCONVERSION - Success
-- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION
-- Performing Test HAVE_CXX_FLAG_WSIGN_CONVERSION - Success
-- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC
-- Performing Test HAVE_CXX_FLAG_WCXX14_COMPAT_PEDANTIC - Failed
-- Performing Test HAVE_CXX_FLAG_WDEPRECATED
-- Performing Test HAVE_CXX_FLAG_WDEPRECATED - Success
-- Performing Test HAVE_CXX_FLAG_WUNUSED_COMMAND_LINE_ARGUMENT
-- Performing Test HAVE_CXX_FLAG_WUNUSED_COMMAND_LINE_ARGUMENT - Failed
-- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS
-- Performing Test HAVE_CXX_FLAG_QUNUSED_ARGUMENTS - Failed
-- Performing Test HAVE_CXX_FLAG_WODR
-- Performing Test HAVE_CXX_FLAG_WODR - Success
-- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING
-- Performing Test HAVE_CXX_FLAG_FLTO_ODR_TYPE_MERGING - Success
-- Performing Test HAVE_CXX_FLAG_WMAYBE_UNINITIALIZED
-- Performing Test HAVE_CXX_FLAG_WMAYBE_UNINITIALIZED - Success
-- Performing Test HAVE_CXX_FLAG_WREDUNDANT_MOVE
-- Performing Test HAVE_CXX_FLAG_WREDUNDANT_MOVE - Success
-- Checking for one of the modules 'zlib'
-- Found ZLIB: /home/open/wrt/staging_dir/target-aarch64_generic_musl/usr/lib/libz.so (found version "1.2.13")
-- Found ZLIB: /home/open/wrt/staging_dir/target-aarch64_generic_musl/usr/include /home/open/wrt/staging_dir/target-aarch64_generic_musl/usr/lib/libz.so
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done (2.9s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:
    CMAKE_ASM_COMPILER
    CMAKE_ASM_COMPILER_LAUNCHER
    CMAKE_EXPORT_NO_PACKAGE_REGISTRY
    CMAKE_EXPORT_PACKAGE_REGISTRY
    CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY
    CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY
    CMAKE_MODULE_LINKER_FLAGS
    DL_LIBRARY
-- Build files have been written to: /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/build
touch /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/.configured_68b329da9893e34099c7d8ad5cb9c940
rm -f /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/.built
touch /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/.built_check
MAKEFLAGS="" /home/open/wrt/staging_dir/host/bin/ninja  -j1 -C /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/build
ninja: Entering directory `/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/build'
[5/315] Building CXX object CMakeFiles/tdcore.dir/td/mtproto/Handshake.cpp.o
FAILED: CMakeFiles/tdcore.dir/td/mtproto/Handshake.cpp.o
ccache /home/open/wrt/staging_dir/toolchain-aarch64_generic_gcc-12.3.0_musl/bin/aarch64-openwrt-linux-musl-g++ -D_FILE_OFFSET_BITS=64 -I/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0 -I/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/td/generate/auto -I/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/tdactor -I/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/tdutils -I/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/build/tdutils -I/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/tdnet -I/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/tddb -Os -pipe -mcpu=generic -fno-caller-saves -fno-plt -fhonour-copts -ffile-prefix-map=/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0=td-1.8.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -std=c++14 -fno-omit-frame-pointer -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wall -Wextra -Wimplicit-fallthrough=2 -Wpointer-arith -Wcast-qual -Wsign-compare -Wduplicated-branches -Wduplicated-cond -Walloc-zero -Wlogical-op -Wno-tautological-compare -Wpointer-arith -Wvla -Wnon-virtual-dtor -Wno-unused-parameter -Wconversion -Wno-sign-conversion -Wdeprecated -Wodr -flto-odr-type-merging -Wno-maybe-uninitialized -Wno-redundant-move -DNDEBUG -fPIC -MD -MT CMakeFiles/tdcore.dir/td/mtproto/Handshake.cpp.o -MF CMakeFiles/tdcore.dir/td/mtproto/Handshake.cpp.o.d -o CMakeFiles/tdcore.dir/td/mtproto/Handshake.cpp.o -c /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/td/mtproto/Handshake.cpp
/home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/td/mtproto/Handshake.cpp:12:10: fatal error: td/mtproto/mtproto_api.h: No such file or directory
   12 | #include "td/mtproto/mtproto_api.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
make[2]: *** [Makefile:50: /home/open/wrt/build_dir/target-aarch64_generic_musl/td-1.8.0/.built] Error 1
make[2]: Leaving directory '/home/open/wrt/package/td'
time: package/td/compile#2.62#1.16#3.58
    ERROR: package/td failed to build.
make[1]: *** [package/Makefile:128: package/td/compile] Error 1
make[1]: Leaving directory '/home/open/wrt'
make: *** [/home/open/wrt/include/toplevel.mk:225: package/td/compile] Error 2
levlam commented 10 months ago

You must run prepare_cross_compiling target with a native compiler before building with CMAKE_CROSSCOMPILING. It is impossible to launch binaries and generate source files during crosscompilation.

firmwarecostum commented 10 months ago

hy @levlam

I've tried adding prepare_cross_compiling in my Makefile but that command is not there. currently openwrt uses ninja

firmwarecostum commented 10 months ago

If you look at the log above when building TD, that's how OpenWRT works when building TD. Is it possible that this command error does not have prepare_cross_compiling because OpenWRT uses Ninja

levlam commented 10 months ago

You must build prepare_cross_compiling with a native compiler and not with a cross-compiler.

firmwarecostum commented 10 months ago

have you tested building this source with ninja?

levlam commented 10 months ago

Yes.

firmwarecostum commented 10 months ago

@levlam

are you sure?

ninja: error: unknown target 'prepare_cross_compiling'

levlam commented 10 months ago

Because you must build prepare_cross_compiling with a native compiler and not with a cross-compiler.

firmwarecostum commented 10 months ago

cmake

Usage: cmake --build <dir> [options] [-- [native-options]]
Options:
  <dir>          = Project binary directory to be built.
  --parallel [<jobs>], -j [<jobs>]
                 = Build in parallel using the given number of jobs.
                   If <jobs> is omitted the native build tool's
                   default number is used.
                   The CMAKE_BUILD_PARALLEL_LEVEL environment variable
                   specifies a default parallel level when this option
                   is not given.
  --target <tgt>..., -t <tgt>...
                 = Build <tgt> instead of default targets.
  --config <cfg> = For multi-configuration tools, choose <cfg>.
  --clean-first  = Build target 'clean' first, then build.
                   (To clean only, use --target 'clean'.)
  --verbose, -v  = Enable verbose output - if supported - including
                   the build commands to be executed.
  --             = Pass remaining options to the native tool.

ninja

usage: ninja [options] [targets...]
if targets are unspecified, builds the 'default' target (see manual).
options:
  --version      print ninja version ("1.11.1")
  -v, --verbose  show all command lines while building
  --quiet        don't show progress status, just command output
  -C DIR   change to DIR before doing anything else
  -f FILE  specify input build file [default=build.ninja]
  -j N     run N jobs in parallel (0 means infinity) [default=3 on this system]
  -k N     keep going until N jobs fail (0 means infinity) [default=1]
  -l N     do not start new jobs if the load average is greater than N
  -n       dry run (don't run commands but act like they succeeded)
  -d MODE  enable debugging (use '-d list' to list modes)
  -t TOOL  run a subtool (use '-t list' to list subtools)
    terminates toplevel options; further flags are passed to the tool
  -w FLAG  adjust warnings (use '-w list' to list warnings)
levlam commented 10 months ago

Run

mkdir build-native
cd build-native
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --target prepare_cross_compiling
cd ..

before running cross-compilation build.

firmwarecostum commented 10 months ago

@levlam

The problem is that prepare_cross_compiling cannot be called when building. is there any idea to change cmakelist.txt so that cross compilation can be done without doing prepare_cross_compiling command

thank you for your patience

levlam commented 10 months ago

I already told three times that the target exists, must be build before cross compilation, and even show you exact commands for target building. "It is impossible to launch binaries and generate source files during crosscompilation." Hence there is no way to do cross compilation without doing prepare_cross_compiling beforehand.