I am building myself a rust project that should be able to cross-compile to windows and mac, but i am running into problems with windows build already.
One of my libs (adb_client) uses rustls as a dependency, which uses aws-lc-rs, and it refuses to build with the following error:
CMake Error at /nix/store/yxf0cmyfrar671zqh0ml8pcw15mxk0mh-cmake-3.30.5/share/ cmake-3.30/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler
"/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: '/my-project-dir/target/x86_64-pc-windows-gnu/release/build/aws-lc-sys-0560811f42265f9d/out/build/CMakeFiles/CMakeScratch/TryCompile-Ex21uY'
Run Build Command(s): /nix/store/yxf0cmyfrar671zqh0ml8pcw15mxk0mh-cmake-3.30.5/bin/cmake -E env VERBOSE=1 /nix/store/hbzw8k8ygv6bfzvsvnd4gb8qmm8xjbvn-gnumake-4.4.1/bin/make -f Makefile cmTC_3a399/fast
make[1]: Entering directory '/my-project-dir/target/x86_64-pc-windows-gnu/release/build/aws-lc-sys-0560811f42265f9d/out/build/CMakeFiles/CMakeScratch/TryCompile-Ex21uY'
/nix/store/hbzw8k8ygv6bfzvsvnd4gb8qmm8xjbvn-gnumake-4.4.1/bin/make -f CMakeFiles/cmTC_3a399.dir/build.make CMakeFiles/cmTC_3a399.dir/build
make[2]: Entering directory '/my-project-dir/target/x86_64-pc-windows-gnu/release/build/aws-lc-sys-0560811f42265f9d/out/build/CMakeFiles/CMakeScratch/TryCompile-Ex21uY'
Building C object CMakeFiles/cmTC_3a399.dir/testCCompiler.c.obj
/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/gcc -ffunction-sections -fdata-sections -m64 -ffunction-sections -fdata-sections -m64 -std=c11 -I /my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0/generated-include -I /my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0/include -I /my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0/aws-lc/include -I /my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0/aws-lc/third_party/s2n-bignum/include -Wall -Wextra -Wno-unused-parameter -pthread -ffile-prefix-map=/my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0= -D_XOPEN_SOURCE=700 -DBORINGSSL_IMPLEMENTATION=1 -DBORINGSSL_PREFIX=aws_lc_0_26_0 -o CMakeFiles/cmTC_3a399.dir/testCCompiler.c.obj -c /my-project-dir/target/x86_64-pc-windows-gnu/release/build/aws-lc-sys-0560811f42265f9d/out/build/CMakeFiles/CMakeScratch/TryCompile-Ex21uY/testCCompiler.c
Linking C executable cmTC_3a399.exe
/nix/store/yxf0cmyfrar671zqh0ml8pcw15mxk0mh-cmake-3.30.5/bin/cmake -E cmake_link_script CMakeFiles/cmTC_3a399.dir/link.txt --verbose=1
/nix/store/yxf0cmyfrar671zqh0ml8pcw15mxk0mh-cmake-3.30.5/bin/cmake -E rm -f CMakeFiles/cmTC_3a399.dir/objects.a
/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/ar qc CMakeFiles/cmTC_3a399.dir/objects.a @CMakeFiles/cmTC_3a399.dir/objects1.rsp
/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0/bin/gcc -ffunction-sections -fdata-sections -m64 -ffunction-sections -fdata-sections -m64 -std=c11 -I /my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0/generated-include -I /my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0/include -I /my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0/aws-lc/include -I /my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0/aws-lc/third_party/s2n-bignum/include -Wall -Wextra -Wno-unused-parameter -pthread -ffile-prefix-map=/my-project-dir/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-sys-0.26.0= -D_XOPEN_SOURCE=700 -DBORINGSSL_IMPLEMENTATION=1 -DBORINGSSL_PREFIX=aws_lc_0_26_0 -Wl,--whole-archive CMakeFiles/cmTC_3a399.dir/objects.a -Wl,--no-whole-archive -o cmTC_3a399.exe -Wl,--out-implib,libcmTC_3a399.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles/cmTC_3a399.dir/linkLibs.rsp
/nix/store/vk4mlknqk9yjbqa68a7rvpfxfdw3rad7-binutils-2.43.1/bin/ld: unrecognized option '--major-image-version'
/nix/store/vk4mlknqk9yjbqa68a7rvpfxfdw3rad7-binutils-2.43.1/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/cmTC_3a399.dir/build.make:101: cmTC_3a399.exe] Error 1
make[2]: Leaving directory '/my-project-dir/target/x86_64-pc-windows-gnu/release/build/aws-lc-sys-0560811f42265f9d/out/build/CMakeFiles/CMakeScratch/TryCompile-Ex21uY'
make[1]: *** [Makefile:127: cmTC_3a399/fast] Error 2
make[1]: Leaving directory '/my-project-dir/target/x86_64-pc-windows-gnu/release/build/aws-lc-sys-0560811f42265f9d/out/build/CMakeFiles/CMakeScratch/TryCompile-Ex21uY'
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:7 (enable_language)
Here is my config. It’s messy because i’ve tried to fix it before.
{ pkgs ? import <nixpkgs> {} }:
let
rustBuildTargetTriple = "x86_64-pc-windows-gnu";
rustBuildHostTriple = "x86_64-unknown-linux-gnu";
overrides = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml));
rustupToolchain = overrides.toolchain.channel;
# Our windows cross package set.
pkgs-cross-mingw = import pkgs.path {
crossSystem = {
config = "x86_64-w64-mingw32";
};
};
# Our windows cross compiler plus
# the required libraries and headers.
mingw_w64_cc = pkgs-cross-mingw.stdenv.cc;
mingw_w64 = pkgs-cross-mingw.windows.mingw_w64;
mingw_w64_pthreads_w_static = pkgs-cross-mingw.windows.mingw_w64_pthreads.overrideAttrs (oldAttrs: {
# TODO: Remove once / if changed successfully upstreamed.
configureFlags = (oldAttrs.configureFlags or []) ++ [
# Rustc require 'libpthread.a' when targeting 'x86_64-pc-windows-gnu'.
# Enabling this makes it work out of the box instead of failing.
"--enable-static"
];
});
wine = pkgs.wineWowPackages.stable;
in
pkgs.mkShell rec {
nativeBuildInputs = with pkgs; [
mingw_w64_cc
wine
openssl
];
buildInputs = with pkgs; [
#cargo
rustup
#cargo-xwin
cmake
mingw_w64_cc
wine
openssl
];
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
RUSTC_VERSION = overrides.toolchain.channel;
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
# Avoid polluting home dir with local project stuff.
RUSTUP_HOME = toString ./.rustup;
CARGO_HOME = toString ./.cargo;
WINEPREFIX = toString ./.wine;
RUSTUP_TOOLCHAIN = rustupToolchain;
# Set windows as the default cargo target so that we don't
# have use the `--target` argument on every `cargo` invocation.
CARGO_BUILD_TARGET = rustBuildTargetTriple;
# Set wine as our cargo runner to allow the `run` and `test`
# command to work.
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER = "${wine}/bin/wine64";
CMAKE_SYSTEM_NAME = "Generic";
shellHook = ''
export PATH=$PATH:${CARGO_HOME}/bin
export PATH=$PATH:${RUSTUP_HOME}/toolchains/${rustupToolchain}-${rustBuildHostTriple}/bin/
# Ensures our windows target is added via rustup.
# rustup target add "${rustBuildTargetTriple}"
rustup show
cargo update
'';
RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
mingw_w64
mingw_w64_pthreads_w_static
]);
}