Skip to content

Commit b290d10

Browse files
committed
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.
1 parent 25fb289 commit b290d10

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkgs/by-name/co/codec2/package.nix

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
lib,
33
stdenv,
4+
buildPackages,
45
fetchFromGitHub,
56
cmake,
67
freedvSupport ? false,
@@ -18,12 +19,23 @@ stdenv.mkDerivation rec {
1819
hash = "sha256-69Mp4o3MgV98Fqfai4txv5jQw2WpoPuoWcwHsNAFPQM=";
1920
};
2021

21-
nativeBuildInputs = [ cmake ];
22+
nativeBuildInputs = [
23+
cmake
24+
buildPackages.stdenv.cc # needs to build a C program to run at build time
25+
];
2226

2327
buildInputs = lib.optionals freedvSupport [
2428
lpcnetfreedv
2529
];
2630

31+
# we need to unset these variables from stdenv here and then set their equivalents in the cmake flags
32+
# otherwise it will pass the same compiler to the native and cross phases and crash trying to execute
33+
# host binaries (generate_codebook) on the build system.
34+
preConfigure = ''
35+
unset CC
36+
unset CXX
37+
'';
38+
2739
postInstall = ''
2840
install -Dm0755 src/{c2enc,c2sim,freedv_rx,freedv_tx,cohpsk_*,fdmdv_*,fsk_*,ldpc_*,ofdm_*} -t $out/bin/
2941
'';
@@ -37,6 +49,8 @@ stdenv.mkDerivation rec {
3749
[
3850
# RPATH of binary /nix/store/.../bin/freedv_rx contains a forbidden reference to /build/
3951
"-DCMAKE_SKIP_BUILD_RPATH=ON"
52+
"-DCMAKE_C_COMPILER=${stdenv.cc.targetPrefix}cc"
53+
"-DCMAKE_CXX_COMPILER=${stdenv.cc.targetPrefix}c++"
4054
]
4155
++ lib.optionals freedvSupport [
4256
"-DLPCNET=ON"

0 commit comments

Comments
 (0)