Cross-compile with Rust

Hi there! I'm trying to crosscompile from Archlinux to Windows, but I get an error:

   Compiling ejdb-sys v0.3.0
error: failed to run custom build command for `ejdb-sys v0.3.0`

Caused by:
  process didn't exit successfully: `/home/duckerman/Games_64/Rust/telecloud/target/release/build/ejdb-sys-72f292154e0f9579/build-script-build` (exit code: 101)
--- stdout
cargo:rustc-link-search=native=/usr/lib
cargo:rustc-link-lib=z
running: "cmake" "/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream" "-DCMAKE_SYSTEM_NAME=Windows" "-DCMAKE_RC_COMPILER=/usr/bin/x86_64-w64-mingw32-windres" "-DBUILD_SAMPLES=OFF" "-DBUILD_SHARED_LIBS=OFF" "-DCMAKE_INSTALL_PREFIX=/home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/release/build/ejdb-sys-1fbad58815bfcc97/out" "-DCMAKE_C_FLAGS= -w -ffunction-sections -fdata-sections -m64" "-DCMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_CXX_COMPILER=/usr/bin/x86_64-w64-mingw32-g++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc" "-DCMAKE_BUILD_TYPE=Release"
-- Using project changelog file: /home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/Changelog
-- Could NOT find BZip2 (missing: BZIP2_LIBRARIES) (found version "1.0.8")
-- Could NOT find LibLZMA (missing: LIBLZMA_LIBRARY LIBLZMA_HAS_AUTO_DECODER LIBLZMA_HAS_EASY_ENCODER LIBLZMA_HAS_LZMA_PRESET) (found version "5.2.5")
-- Lzo includes and libraries NOT found. 
-- Configuring incomplete, errors occurred!
See also "/home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/release/build/ejdb-sys-1fbad58815bfcc97/out/build/CMakeFiles/CMakeOutput.log".
See also "/home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/release/build/ejdb-sys-1fbad58815bfcc97/out/build/CMakeFiles/CMakeError.log".

--- stderr
CMake Error at src/CMakeLists.txt:108 (message):
  Unable to find pcre.h include file


thread 'main' panicked at '
command did not execute successfully, got: exit code: 1

build script failed, must exit now', /home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.44/src/lib.rs:885:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


1 Like

I've changed cargo config, and I got different error:

 error: failed to run custom build command for `ejdb-sys v0.3.0`

Caused by:
  process didn't exit successfully: `/home/duckerman/Games_64/Rust/telecloud/target/debug/build/ejdb-sys-093695ec2a33c935/build-script-build` (exit code: 101)
--- stdout
cargo:rustc-link-search=native=/usr/lib
cargo:rustc-link-lib=z
running: "cmake" "/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream" "-DCMAKE_SYSTEM_NAME=Windows" "-DCMAKE_RC_COMPILER=/usr/bin/x86_64-w64-mingw32-windres" "-DBUILD_SAMPLES=OFF" "-DBUILD_SHARED_LIBS=OFF" "-DCMAKE_INSTALL_PREFIX=/home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/debug/build/ejdb-sys-8a01b2e291141eaa/out" "-DCMAKE_C_FLAGS= -w -ffunction-sections -fdata-sections -m64" "-DCMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_CXX_COMPILER=/usr/bin/x86_64-w64-mingw32-g++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc" "-DCMAKE_BUILD_TYPE=Release"
-- Using project changelog file: /home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/Changelog
-- The C compiler identification is GNU 10.1.0
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Could NOT find BZip2 (missing: BZIP2_LIBRARIES) (found version "1.0.8")
-- Found ZLIB: /usr/lib/libz.a (found version "1.2.11") 
-- Could NOT find LibLZMA (missing: LIBLZMA_LIBRARY LIBLZMA_HAS_AUTO_DECODER LIBLZMA_HAS_EASY_ENCODER LIBLZMA_HAS_LZMA_PRESET) (found version "5.2.5")
-- Lzo includes and libraries NOT found. 
-- Looking for windows.h
-- Looking for windows.h - found
-- Looking for time.h
-- Looking for time.h - found
-- Looking for pcre.h
-- Looking for pcre.h - found
-- Looking for pcreposix.h
-- Looking for pcreposix.h - found
-- Looking for pcre_compile in pcre
-- Looking for pcre_compile in pcre - found
-- Looking for pthread_exit in winpthread
-- Looking for pthread_exit in winpthread - found
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for dirent.h
-- Looking for dirent.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/debug/build/ejdb-sys-8a01b2e291141eaa/out/build
running: "cmake" "--build" "." "--target" "install" "--config" "Release" "--"
Scanning dependencies of target ejdb
[  4%] Building C object src/CMakeFiles/ejdb.dir/tcutil/md5.c.obj
[  8%] Building C object src/CMakeFiles/ejdb.dir/tcutil/myconf.c.obj

--- stderr
CMake Warning (dev) at CMakeLists.txt:39 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'PROJECT_PPA_DISTRIB_TARGET'.
This warning is for project developers.  Use -Wno-dev to suppress it.


LINK LIBS: -lwinpthread;-lpcreposix;-lpcre;/usr/lib/librt.a;/usr/lib/libm.a;/usr/lib/libz.a

INCLUDE DIRS: /home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/debug/build/ejdb-sys-8a01b2e291141eaa/out/build/src/generated;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcutil;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tchdb;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcbdb;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tctdb;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcfdb;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/bson;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/ejdb;/usr/include

SOURCES: /home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcutil/md5.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcutil/myconf.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcutil/platform.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcutil/tcutil.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcutil/utf8proc.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tchdb/tchdb.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcbdb/tcbdb.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tctdb/tctdb.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcfdb/tcfdb.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/bson/bson.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/bson/encoding.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/bson/numbers.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/bson/nxjson.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/ejdb/ejdb.c;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/ejdb/ejdbutl.c

PUB_HDRS: /home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcutil/tcutil.h;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tchdb/tchdb.h;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcbdb/tcbdb.h;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tctdb/tctdb.h;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcfdb/tcfdb.h;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/bson/bson.h;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/ejdb/ejdb.h;/home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/debug/build/ejdb-sys-8a01b2e291141eaa/out/build/src/generated/basedefs.h;/home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/ejdb/ejdb_private.h

CMAKE_BUILD_TYPE: Release
BUILD_SHARED_LIBS: OFF
BUILD_TESTS: OFF
BUILD_SAMPLES: OFF
CMAKE_INSTALL_PREFIX: /home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/debug/build/ejdb-sys-8a01b2e291141eaa/out
CPACK_GENERATORS: TGZ;ZIP
CMAKE_SYSTEM_NAME: Windows
PROJECT_ARCH: x86_64
PROJECT: ejdb (1.2.12) testing; urgency=medium
CHANGELOG_MESSAGE:
  *  Fix: "no record found" after creating two collections in a row #174
  *  Fix: SEGFAULT on sequential open/close with the same handle #169
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_ASM_COMPILER
    CMAKE_ASM_FLAGS
    CMAKE_CXX_COMPILER
    CMAKE_CXX_FLAGS


In file included from /usr/include/stdlib.h:394,
                 from /usr/lib/gcc/x86_64-w64-mingw32/10.1.0/include/mm_malloc.h:27,
                 from /usr/lib/gcc/x86_64-w64-mingw32/10.1.0/include/xmmintrin.h:34,
                 from /usr/lib/gcc/x86_64-w64-mingw32/10.1.0/include/immintrin.h:29,
                 from /usr/lib/gcc/x86_64-w64-mingw32/10.1.0/include/x86intrin.h:32,
                 from /usr/x86_64-w64-mingw32/include/winnt.h:1554,
                 from /usr/x86_64-w64-mingw32/include/minwindef.h:163,
                 from /usr/x86_64-w64-mingw32/include/windef.h:8,
                 from /usr/x86_64-w64-mingw32/include/windows.h:69,
                 from /home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/debug/build/ejdb-sys-8a01b2e291141eaa/out/build/src/generated/basedefs.h:59,
                 from /home/duckerman/Games_64/Rust/telecloud/target/x86_64-pc-windows-gnu/debug/build/ejdb-sys-8a01b2e291141eaa/out/build/src/generated/myconf.h:27,
                 from /home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/ejdb-sys-0.3.0/ejdb-upstream/src/tcutil/myconf.c:18:
/usr/include/sys/types.h:108:19: error: incompatible types for  «ssize_t»
  108 | typedef __ssize_t ssize_t;
      |                   ^~~~~~~
compilation abordet because of Wfatal-errors.
make[2]: *** [src/CMakeFiles/ejdb.dir/build.make:98: src/CMakeFiles/ejdb.dir/tcutil/myconf.c.obj] Ошибка 1
make[1]: *** [CMakeFiles/Makefile2:219: src/CMakeFiles/ejdb.dir/all] Ошибка 2
make: *** [Makefile:172: all] Ошибка 2
thread 'main' panicked at '
command did not execute successfully, got: exit code: 2

build script failed, must exit now', /home/duckerman/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.44/src/lib.rs:885:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It looks like your app has some C dependencies, so you need a C toolchain for Windows. For example, MXE.

Once that's done, when you run Cargo, you need to have the correct environment variables set to point it at your mingw toolchain instead of trying to use the Arch compiler. The cc crate documents the environment variables that are used to find the C compiler.

cargo:rustc-link-search=native=/usr/lib

That output line, mentioning the native libraries directory, specifically tells me that you don't have your C toolchain set up. If it was, it wouldn't try to link native libraries into your cross-compiled app.