bytecodealliance / wamr-rust-sdk

Apache License 2.0
35 stars 10 forks source link

Compiling `wamr-sys` for `thumbv6m-none-eabi` fails #30

Open Zelzahn opened 6 months ago

Zelzahn commented 6 months ago

Honestly, I'm not really sure whether I should file this issue here or in the WAMR repo, but I would like to run WAMR on a RP2040 (thus the thumbv6m-none-eabi target).

When I try to build my project, I get the following error:

error: failed to run custom build command for `wamr-sys v0.1.0 (https://github.com/bytecodealliance/wamr-rust-sdk?branch=main#83efde0c)`

Caused by:
  process didn't exit successfully: `target/debug/build/wamr-sys-4c26d7286deec4f6/build-script-build` (exit status: 101)
  --- stdout
  CMAKE_TOOLCHAIN_FILE_thumbv6m-none-eabi = None
  CMAKE_TOOLCHAIN_FILE_thumbv6m_none_eabi = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_thumbv6m-none-eabi = None
  CMAKE_GENERATOR_thumbv6m_none_eabi = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_thumbv6m-none-eabi = None
  CMAKE_PREFIX_PATH_thumbv6m_none_eabi = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_thumbv6m-none-eabi = None
  CMAKE_thumbv6m_none_eabi = None
  TARGET_CMAKE = None
  CMAKE = None
  running: cd "target/thumbv6m-none-eabi/debug/build/wamr-sys-b5227011006dca32/out/build" && CMAKE_PREFIX_PATH="" "cmake" ".cargo/git/checkouts/wamr-rust-sdk-a60624a35074c840/83efde0/crates/wamr-sys/wasm-micro-runtime" "-DWAMR_BUILD_AOT=1" "-DWAMR_BUILD_INTERP=1" "-DWAMR_BUILD_FAST_INTERP=1" "-DWAMR_BUILD_JIT=0" "-DWAMR_BUILD_BULK_MEMORY=1" "-DWAMR_BUILD_REF_TYPES=1" "-DWAMR_BUILD_SIMD=1" "-DWAMR_BUILD_LIBC_WASI=1" "-DWAMR_BUILD_LIBC_BUILTIN=1" "-DCMAKE_SYSTEM_NAME=none" "-DCMAKE_SYSTEM_PROCESSOR=arm" "-DCMAKE_INSTALL_PREFIX=target/thumbv6m-none-eabi/debug/build/wamr-sys-b5227011006dca32/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -mthumb -march=armv6s-m" "-DCMAKE_C_COMPILER=/usr/bin/arm-none-eabi-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -mthumb -march=armv6s-m" "-DCMAKE_CXX_COMPILER=/usr/bin/arm-none-eabi-g++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -mthumb -march=armv6s-m" "-DCMAKE_ASM_COMPILER=/usr/bin/arm-none-eabi-gcc" "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
  -- The C compiler identification is GNU 13.2.1
  -- The CXX compiler identification is GNU 13.2.1
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - failed
  -- Check for working C compiler: /usr/bin/arm-none-eabi-gcc
  -- Check for working C compiler: /usr/bin/arm-none-eabi-gcc - broken
  -- Configuring incomplete, errors occurred!

  --- stderr
  System is unknown to cmake, create:
  Platform/none to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
  Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. Please post that file on discourse.cmake.org.
  System is unknown to cmake, create:
  Platform/none to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
  System is unknown to cmake, create:
  Platform/none to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
  CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:67 (message):
    The C compiler

      "/usr/bin/arm-none-eabi-gcc"

    is not able to compile a simple test program.

    It fails with the following output:

      Change Dir: 'target/thumbv6m-none-eabi/debug/build/wamr-sys-b5227011006dca32/out/build/CMakeFiles/CMakeScratch/TryCompile-zBseL8'

      Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_5bad6/fast
      /usr/bin/make  -f CMakeFiles/cmTC_5bad6.dir/build.make CMakeFiles/cmTC_5bad6.dir/build
      make[1]: Entering directory 'target/thumbv6m-none-eabi/debug/build/wamr-sys-b5227011006dca32/out/build/CMakeFiles/CMakeScratch/TryCompile-zBseL8'
      Building C object CMakeFiles/cmTC_5bad6.dir/testCCompiler.c.obj
      /usr/bin/arm-none-eabi-gcc   -ffunction-sections -fdata-sections -mthumb -march=armv6s-m  -o CMakeFiles/cmTC_5bad6.dir/testCCompiler.c.obj -c target/thumbv6m-none-eabi/debug/build/wamr-sys-b5227011006dca32/out/build/CMakeFiles/CMakeScratch/TryCompile-zBseL8/testCCompiler.c
      Linking C executable cmTC_5bad6
      /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_5bad6.dir/link.txt --verbose=1
      /usr/bin/arm-none-eabi-gcc  -ffunction-sections -fdata-sections -mthumb -march=armv6s-m  CMakeFiles/cmTC_5bad6.dir/testCCompiler.c.obj -o cmTC_5bad6
      /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-exit.o): in function `exit':
      exit.c:(.text.exit+0x16): undefined reference to `_exit'
      /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-writer.o): in function `_write_r':
      writer.c:(.text._write_r+0x10): undefined reference to `_write'
      /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-closer.o): in function `_close_r':
      closer.c:(.text._close_r+0xc): undefined reference to `_close'
      /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-lseekr.o): in function `_lseek_r':
      lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'
      /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-readr.o): in function `_read_r':
      readr.c:(.text._read_r+0x10): undefined reference to `_read'
      /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /usr/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-sbrkr.o): in function `_sbrk_r':
      sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
      collect2: error: ld returned 1 exit status
      make[1]: *** [CMakeFiles/cmTC_5bad6.dir/build.make:99: cmTC_5bad6] Error 1
      make[1]: Leaving directory 'target/thumbv6m-none-eabi/debug/build/wamr-sys-b5227011006dca32/out/build/CMakeFiles/CMakeScratch/TryCompile-zBseL8'
      make: *** [Makefile:127: cmTC_5bad6/fast] Error 2

I don't know if the error could be inside the build.rs in wamr-sys? I'm not sure how to debug this, thus any help is very much appreciated.

Zelzahn commented 6 months ago

I think maybe this blog post (PSA: Cortex-M Breakage (LLD as the default linker)) could be relevant.

lum1n0us commented 5 months ago

If it is me, I will start to use /usr/bin/arm-none-eabi-gcc manually compile a file without interference of cmake and rust. If this step is fine, you will know the problem is about rust configuration. Or else, the problem is about compilation toolchain.

$ /usr/bin/arm-none-eabi-gcc -o hello ./hello_world.c