Raspberry pi, yocto SDK, rust, cmake, c broken

Hello, trying to build a minimal rust project with yocto generated SDK for raspberry pi aarch64.
I installed SDK, and source /opt/poky/5.0.6/environment-setup-cortexa57-poky-linux

I have a very minimal build.rs where I start a cmake build:

use cmake::Config;

fn main() {
    let dst = Config::new("test_cmake").very_verbose(false).build();
}

the test_cmake is a minimal cmake c project with hello world main.c.
I can't get cmake to configure successfully the c project:

test_cmake on  master [?] is 📦 v0.1.0 via
❯ cargo clean && cargo build
     Removed 61 files, 24.2MiB total
   Compiling shlex v1.3.0
   Compiling cc v1.2.10
   Compiling cmake v0.1.53
   Compiling test_cmake v0.1.0 (/home/adi/workspace/test_cmake)
warning: unused variable: `dst`
 --> build.rs:4:9
  |
4 |     let dst = Config::new("test_cmake").very_verbose(false).build();
  |         ^^^ help: if this is intentional, prefix it with an underscore: `_dst`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: `test_cmake` (build script) generated 1 warning
error: failed to run custom build command for `test_cmake v0.1.0 (/home/adi/workspace/test_cmake)`

Caused by:
  process didn't exit successfully: `/home/adi/workspace/test_cmake/target/debug/build/test_cmake-c8c5ee18cb0695dc/build-script-build` (exit status: 101)
  --- stdout
  CMAKE_TOOLCHAIN_FILE_aarch64-poky-linux-gnu = None
  CMAKE_TOOLCHAIN_FILE_aarch64_poky_linux_gnu = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = Some("/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake")
  CMAKE_GENERATOR_aarch64-poky-linux-gnu = None
  CMAKE_GENERATOR_aarch64_poky_linux_gnu = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_aarch64-poky-linux-gnu = None
  CMAKE_PREFIX_PATH_aarch64_poky_linux_gnu = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_aarch64-poky-linux-gnu = None
  CMAKE_aarch64_poky_linux_gnu = None
  TARGET_CMAKE = None
  CMAKE = None
  running: cd "/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out/build" && CMAKE_PREFIX_PATH="" LC_ALL="C" "cmake" "/home/adi/workspace/test_cmake/test_cmake" "-DCMAKE_TOOLCHAIN_FILE=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake" "-DCMAKE_INSTALL_PREFIX=/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -pipe -feliminate-unused-debug-types" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -pipe -feliminate-unused-debug-types" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -pipe -feliminate-unused-debug-types" "-DCMAKE_BUILD_TYPE=Debug"
  -- The C compiler identification is GNU 13.3.0
  -- The CXX compiler identification is GNU 13.3.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - failed
  -- Check for working C compiler: /opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc
  -- Check for working C compiler: /opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc - broken
  -- Configuring incomplete, errors occurred!

  --- stderr
  CMake Error at /opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):
    The C compiler

      "/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc"

    is not able to compile a simple test program.

    It fails with the following output:

      Change Dir: '/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out/build/CMakeFiles/CMakeScratch/TryCompile-LDjpo0'
      
      Run Build Command(s): /opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/cmake -E env VERBOSE=1 /opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/make -f Makefile cmTC_29fe2/fast
      /opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/make  -f CMakeFiles/cmTC_29fe2.dir/build.make CMakeFiles/cmTC_29fe2.dir/build
      make[1]: Entering directory '/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out/build/CMakeFiles/CMakeScratch/TryCompile-LDjpo0'
      make[1]: *** [CMakeFiles/cmTC_29fe2.dir/build.make:77: CMakeFiles/cmTC_29fe2.dir/testCCompiler.c.o] Segmentation fault (core dumped)
      make[1]: Leaving directory '/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out/build/CMakeFiles/CMakeScratch/TryCompile-LDjpo0'
      make: *** [Makefile:127: cmTC_29fe2/fast] Error 2
      
      

    

    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:2 (project)


  thread 'main' panicked at /opt/poky/5.0.6/sysroots/cortexa57-poky-linux/home/cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.53/src/lib.rs:1121:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

if i manually copy-paste the cmake command, it successfully creates the Makefile:

test_cmake on  master [?] is 📦 v0.1.0 via 
❯ CMAKE_PREFIX_PATH="" LC_ALL="C" "cmake" "/home/adi/workspace/test_cmake/test_cmake" "-DCMAKE_TOOLCHAIN_FILE=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake" "-DCMAKE_INSTALL_PREFIX=/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -pipe -feliminate-unused-debug-types" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -pipe -feliminate-unused-debug-types" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -pipe -feliminate-unused-debug-types" "-DCMAKE_BUILD_TYPE=Debug"
-- The C compiler identification is GNU 13.3.0
-- The CXX compiler identification is GNU 13.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-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: /opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.3s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_ASM_FLAGS


-- Build files have been written to: /home/adi/workspace/test_cmake

the error message seems to indicate part of cmake compiler detection logic is not working. i'm guessing some environment variables set by cargo confused cmake and probably cmake picked a wrong cc or set some bad CFLAGS.

just noticed this check is "skipped", so you are cross compiling from an non-aarch64 system? to cross compile, you need to pass a --target option to cargo. I'm not familiar with yocto, does it use glibc or musl (or other libc)? here's an example how to cross compile for a glibc target:

$ cargo build --target aarch64-unknown-linux-gnu

you may need to first run rustup target add aarch64-unknown-linux-gnu if you have not installed the cross compiling target yet.

Yes, I am crosscompiling from arch linux x86_64.
After sourcing the SDK env source /opt/poky/5.0.6/environment-setup-cortexa57-poky-linux , I use cargo from:

❯ which cargo
/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/cargo

thus I think --target should not be needed anymore.
Using glibc that comes with the sdk.
rustup is not installed in the sdk.

I don't know about the x86_64-pokysdk-linux toolchain, but somehow cmake cannot figure out it was cross compiling for a different architecture.

normally, cross compiling should be setup automatically when using a toolchain file, I'm not sure why it wasn't working in your case. I can only give some random guesses, you can find the CMakeCache.txt file after cargo build fails, and check which variables are incorrect.

  • is the variable CMAKE_CROSSCOMPILING set?
  • what's the value of CMAKE_HOST_SYSTEM_PROCESSOR?
  • what's the value of CMAKE_SYSTEM_PROCESSOR?
  • what's the value of CMAKE_SYSTEM_NAME and/or CMAKE_HOST_SYSTEM_NAME?

Cargo will alwyas build for the host unless you pass --target.

maybe the sdk has a preset configuration, e.g. $CARGO_HOME/config.toml

None of these variables are set in the CMakeCache.txt:

# This is the CMakeCache file.
# For build in directory: /home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out/build
# It was generated by CMake: /opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/cmake
# You can edit this file to change values found and used by cmake.
# If you do not want to change any of the values, simply exit the editor.
# If you do want to change a value, simply edit, save, and exit the editor.
# The syntax for the file is as follows:
# KEY:TYPE=VALUE
# KEY is the name of a variable in the cache.
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.
# VALUE is the current value for the KEY.

########################
# EXTERNAL cache entries
########################

//Path to a program.
CMAKE_ADDR2LINE:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-addr2line

//Path to a program.
CMAKE_AR:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar

//No help, variable specified on the command line.
CMAKE_ASM_FLAGS:UNINITIALIZED= -ffunction-sections -fdata-sections -fPIC -pipe -feliminate-unused-debug-types

//Choose the type of build, options are: None Debug Release RelWithDebInfo
// MinSizeRel ...
CMAKE_BUILD_TYPE:STRING=Debug

//Enable/Disable color output during build.
CMAKE_COLOR_MAKEFILE:BOOL=ON

//CXX compiler
CMAKE_CXX_COMPILER:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++

//A wrapper around 'ar' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_AR:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar

//Arguments to CXX compiler
CMAKE_CXX_COMPILER_ARG1:STRING=  -mcpu=cortex-a57+crc -mbranch-protection=standard -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/poky/5.0.6/sysroots/cortexa57-poky-linux

//A wrapper around 'ranlib' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ranlib

CMAKE_CXX_FLAGS:STRING=' -O2 -pipe -g -feliminate-unused-debug-types '

//C compiler
CMAKE_C_COMPILER:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc

//A wrapper around 'ar' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_C_COMPILER_AR:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ar

//Arguments to C compiler
CMAKE_C_COMPILER_ARG1:STRING=  -mcpu=cortex-a57+crc -mbranch-protection=standard -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/poky/5.0.6/sysroots/cortexa57-poky-linux

//A wrapper around 'ranlib' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_C_COMPILER_RANLIB:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc-ranlib

CMAKE_C_FLAGS:STRING=' -O2 -pipe -g -feliminate-unused-debug-types '

//Flags used by the C compiler during DEBUG builds.
CMAKE_C_FLAGS_DEBUG:STRING=-g

//Flags used by the C compiler during MINSIZEREL builds.
CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG

//Flags used by the C compiler during RELEASE builds.
CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG

//Flags used by the C compiler during RELWITHDEBINFO builds.
CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG

//Path to a program.
CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND

//Flags used by the linker during all build types.
CMAKE_EXE_LINKER_FLAGS:STRING=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed  -Wl,-z,relro,-z,now

//Flags used by the linker during DEBUG builds.
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=

//Flags used by the linker during MINSIZEREL builds.
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=

//Flags used by the linker during RELEASE builds.
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=

//Flags used by the linker during RELWITHDEBINFO builds.
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=

//Enable/Disable output of compile commands during generation.
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=

//Value Computed by CMake.
CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out/build/CMakeFiles/pkgRedirects

//Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out

//Path to a program.
CMAKE_LINKER:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld

//Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/make

//Flags used by the linker during the creation of modules during
// all build types.
CMAKE_MODULE_LINKER_FLAGS:STRING=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed  -Wl,-z,relro,-z,now

//Flags used by the linker during the creation of modules during
// DEBUG builds.
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=

//Flags used by the linker during the creation of modules during
// MINSIZEREL builds.
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=

//Flags used by the linker during the creation of modules during
// RELEASE builds.
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=

//Flags used by the linker during the creation of modules during
// RELWITHDEBINFO builds.
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=

//Path to a program.
CMAKE_NM:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-nm

//Path to a program.
CMAKE_OBJCOPY:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objcopy

//Path to a program.
CMAKE_OBJDUMP:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-objdump

//Value Computed by CMake
CMAKE_PROJECT_DESCRIPTION:STATIC=

//Value Computed by CMake
CMAKE_PROJECT_HOMEPAGE_URL:STATIC=

//Value Computed by CMake
CMAKE_PROJECT_NAME:STATIC=tutorial

//Path to a program.
CMAKE_RANLIB:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ranlib

//Path to a program.
CMAKE_READELF:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-readelf

//Flags used by the linker during the creation of shared libraries
// during all build types.
CMAKE_SHARED_LINKER_FLAGS:STRING=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed  -Wl,-z,relro,-z,now

//Flags used by the linker during the creation of shared libraries
// during DEBUG builds.
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=

//Flags used by the linker during the creation of shared libraries
// during MINSIZEREL builds.
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=

//Flags used by the linker during the creation of shared libraries
// during RELEASE builds.
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=

//Flags used by the linker during the creation of shared libraries
// during RELWITHDEBINFO builds.
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=

//If set, runtime paths are not added when installing shared libraries,
// but are added when building.
CMAKE_SKIP_INSTALL_RPATH:BOOL=NO

//If set, runtime paths are not added when using shared libraries.
CMAKE_SKIP_RPATH:BOOL=NO

//Flags used by the linker during the creation of static libraries
// during all build types.
CMAKE_STATIC_LINKER_FLAGS:STRING=

//Flags used by the linker during the creation of static libraries
// during DEBUG builds.
CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING=

//Flags used by the linker during the creation of static libraries
// during MINSIZEREL builds.
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING=

//Flags used by the linker during the creation of static libraries
// during RELEASE builds.
CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING=

//Flags used by the linker during the creation of static libraries
// during RELWITHDEBINFO builds.
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=

//Path to a program.
CMAKE_STRIP:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-strip

//Path to a program.
CMAKE_TAPI:FILEPATH=CMAKE_TAPI-NOTFOUND

//The CMake toolchain file
CMAKE_TOOLCHAIN_FILE:FILEPATH=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake

//If this value is on, makefiles will be generated without the
// .SILENT directive, and all commands will be echoed to the console
// during the make.  This is useful for debugging only. With Visual
// Studio IDE projects all commands are done without /nologo.
CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE

//Value Computed by CMake
tutorial_BINARY_DIR:STATIC=/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out/build

//Value Computed by CMake
tutorial_IS_TOP_LEVEL:STATIC=ON

//Value Computed by CMake
tutorial_SOURCE_DIR:STATIC=/home/adi/workspace/test_cmake/test_cmake


########################
# INTERNAL cache entries
########################

//ADVANCED property for variable: CMAKE_ADDR2LINE
CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_AR
CMAKE_AR-ADVANCED:INTERNAL=1
//This is the directory where this CMakeCache.txt was created
CMAKE_CACHEFILE_DIR:INTERNAL=/home/adi/workspace/test_cmake/target/aarch64-poky-linux-gnu/debug/build/test_cmake-ff2e9f1936fce91e/out/build
//Major version of cmake used to create the current loaded cache
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
//Minor version of cmake used to create the current loaded cache
CMAKE_CACHE_MINOR_VERSION:INTERNAL=28
//Patch version of cmake used to create the current loaded cache
CMAKE_CACHE_PATCH_VERSION:INTERNAL=3
//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
//Path to CMake executable.
CMAKE_COMMAND:INTERNAL=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/cmake
//Path to cpack program executable.
CMAKE_CPACK_COMMAND:INTERNAL=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/cpack
//Path to ctest program executable.
CMAKE_CTEST_COMMAND:INTERNAL=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/ctest
//ADVANCED property for variable: CMAKE_CXX_COMPILER
CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR
CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB
CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_COMPILER
CMAKE_C_COMPILER-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_COMPILER_AR
CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB
CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS
CMAKE_C_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_DLLTOOL
CMAKE_DLLTOOL-ADVANCED:INTERNAL=1
//Executable file format
CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS
CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG
CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE
CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS
CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1
//Name of external makefile project generator.
CMAKE_EXTRA_GENERATOR:INTERNAL=
//Name of generator.
CMAKE_GENERATOR:INTERNAL=Unix Makefiles
//Generator instance identifier.
CMAKE_GENERATOR_INSTANCE:INTERNAL=
//Name of generator platform.
CMAKE_GENERATOR_PLATFORM:INTERNAL=
//Name of generator toolset.
CMAKE_GENERATOR_TOOLSET:INTERNAL=
//Source directory with the top level CMakeLists.txt file for this
// project
CMAKE_HOME_DIRECTORY:INTERNAL=/home/adi/workspace/test_cmake/test_cmake
//Install .so files without execute permission.
CMAKE_INSTALL_SO_NO_EXE:INTERNAL=0
//ADVANCED property for variable: CMAKE_LINKER
CMAKE_LINKER-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MAKE_PROGRAM
CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG
CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE
CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_NM
CMAKE_NM-ADVANCED:INTERNAL=1
//number of local generators
CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1
//ADVANCED property for variable: CMAKE_OBJCOPY
CMAKE_OBJCOPY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_OBJDUMP
CMAKE_OBJDUMP-ADVANCED:INTERNAL=1
//Platform information initialized
CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1
//ADVANCED property for variable: CMAKE_RANLIB
CMAKE_RANLIB-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_READELF
CMAKE_READELF-ADVANCED:INTERNAL=1
//Path to CMake installation.
CMAKE_ROOT:INTERNAL=/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/share/cmake-3.28
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG
CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE
CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH
CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SKIP_RPATH
CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS
CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG
CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE
CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STRIP
CMAKE_STRIP-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_TAPI
CMAKE_TAPI-ADVANCED:INTERNAL=1
//uname command
CMAKE_UNAME:INTERNAL=/usr/bin/uname
//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE
CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1
//linker supports push/pop state
_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED:INTERNAL=TRUE

Indeed I also have:


❯ /usr/bin/cat  $CARGO_HOME/config 
[build]
target = "aarch64-poky-linux-gnu"
# TARGET_SYS
[target.aarch64-poky-linux-gnu]
linker = "target-rust-ccld"

I guess these variables are not cached but only set at configure time.

normally, the host os and cpu are determined by cmake, while the target os and cpu are set by the toolchain file. I cannot think of a good reason, but somehow, the cmake invoked by cargo cannot figure out it was supposed to do cross compiling.

just to double check, what's the output if you log these variables explicitly, e.g.:

# CMakeLists.txt

message("host cpu: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message("target cpu: ${CMAKE_SYSTEM_PROCESSOR}")

although I don't know how the poky sdk works, this is what I would have guessed anyway.

CMake can fail during the first configure step, then succeed when rerun. It’s annoying when that happens. It’s usually because some important variable (most likely from the toolchain file) is only defined late, however it’s cached when the second configure is run, and that in turn succeeds.

Changed build.rs to:

// build.rs
fn main() {
  let output = std::process::Command::new(
          "/opt/poky/5.0.6/sysroots/x86_64-pokysdk-linux/usr/bin/cmake",
      )
    .args(["--system-information"])
    .output()
    .expect("failed to execute process");
    println!(
        "====system-information {:?}, {:?}",
        String::from_utf8_lossy(&output.stderr),
        String::from_utf8_lossy(&output.stdout)
    );
}

This does not fail, but it prints:

[test_cmake 0.1.0] ====system-information "CMake Error at /opt/poky/5.0.6_lts-mixins/sysroots/x86_64-pokysdk-linux/usr/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):\n  The C compiler\n\n    \"/opt/poky/5.0.6_lts-mixins/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc\"\n\n  is not able to compile a simple test program.\n\n  It fails with the following output:\n\n    Change Dir: '/home/adi/workspace/test_cmake/__cmake_systeminformation/CMakeFiles/CMakeScratch/TryCompile-BE0Skp'\n    \n    Run Build Command(s): /opt/poky/5.0.6_lts-mixins/sysroots/x86_64-pokysdk-linux/usr/bin/cmake -E env VERBOSE=1 /opt/poky/5.0.6_lts-mixins/sysroots/x86_64-pokysdk-linux/usr/bin/make -f Makefile cmTC_78bdd/fast\n    /opt/poky/5.0.6_lts-mixins/sysroots/x86_64-pokysdk-linux/usr/bin/make  -f CMakeFiles/cmTC_78bdd.dir/build.make CMakeFiles/cmTC_78bdd.dir/build\n    make[1]: Entering directory '/home/adi/workspace/test_cmake/__cmake_systeminformation/CMakeFiles/CMakeScratch/TryCompile-BE0Skp'\n    make[1]: *** [CMakeFiles/cmTC_78bdd.dir/build.make:77: CMakeFiles/cmTC_78bdd.dir/testCCompiler.c.o] Segmentation fault (core dumped)\n    make[1]: Leaving directory '/home/adi/workspace/test_cmake/__cmake_systeminformation/CMakeFiles/CMakeScratch/TryCompile-BE0Skp'\n    make: *** [Makefile:127: cmTC_78bdd/fast] Error 2\n    \n    \n\n  \n\n  CMake will not be able to correctly generate this project.\nCall Stack (most recent call first):\n  CMakeLists.txt:6 (project)\n\n\nError: --system-information failed on internal CMake!\n", ""

which makes me think maybe is something wrong with the rust/cargo build in yocto SDK.

This works without problem if I use host cargo/rust installation /home/adi/.cargo/bin/cargo

In the end i managed to have the build working by using a docker image that uses the rootfs generated from yocto, and installing yocto SDK in that rootfs, and doing the build there. I think there is a libc issue.

Also opened https://bugzilla.yoctoproject.org/show_bug.cgi?id=15735