From b290d10aef3fb8b049a21740a072f6b703b4ccaa Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Sat, 22 Feb 2025 20:26:59 -0700 Subject: [PATCH] codec2: fix cross compilation It uses cmake flags and environment variables in a way that interacts poorly with stdenv's defaults. See code comments for details. --- pkgs/by-name/co/codec2/package.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/co/codec2/package.nix b/pkgs/by-name/co/codec2/package.nix index f5c82cfb8a51..d68de7cfd4c7 100644 --- a/pkgs/by-name/co/codec2/package.nix +++ b/pkgs/by-name/co/codec2/package.nix @@ -1,6 +1,7 @@ { lib, stdenv, + buildPackages, fetchFromGitHub, cmake, freedvSupport ? false, @@ -18,12 +19,23 @@ stdenv.mkDerivation rec { hash = "sha256-69Mp4o3MgV98Fqfai4txv5jQw2WpoPuoWcwHsNAFPQM="; }; - nativeBuildInputs = [ cmake ]; + nativeBuildInputs = [ + cmake + buildPackages.stdenv.cc # needs to build a C program to run at build time + ]; buildInputs = lib.optionals freedvSupport [ lpcnetfreedv ]; + # we need to unset these variables from stdenv here and then set their equivalents in the cmake flags + # otherwise it will pass the same compiler to the native and cross phases and crash trying to execute + # host binaries (generate_codebook) on the build system. + preConfigure = '' + unset CC + unset CXX + ''; + postInstall = '' install -Dm0755 src/{c2enc,c2sim,freedv_rx,freedv_tx,cohpsk_*,fdmdv_*,fsk_*,ldpc_*,ofdm_*} -t $out/bin/ ''; @@ -37,6 +49,8 @@ stdenv.mkDerivation rec { [ # RPATH of binary /nix/store/.../bin/freedv_rx contains a forbidden reference to /build/ "-DCMAKE_SKIP_BUILD_RPATH=ON" + "-DCMAKE_C_COMPILER=${stdenv.cc.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${stdenv.cc.targetPrefix}c++" ] ++ lib.optionals freedvSupport [ "-DLPCNET=ON"