summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2023-04-08 17:29:06 -0700
committerArtturin <Artturin@artturin.com>2023-04-14 07:41:03 +0300
commit4aa036f15aa55e788eda633805d8397274d6c052 (patch)
treea9e038866404dbc4b972340f513bd8a26db789a0
parent3c070a08ff5e8646f15398ff7e257d91b97ac5da (diff)
downloadnixpkgs-4aa036f15aa55e788eda633805d8397274d6c052.tar
nixpkgs-4aa036f15aa55e788eda633805d8397274d6c052.tar.gz
nixpkgs-4aa036f15aa55e788eda633805d8397274d6c052.tar.bz2
nixpkgs-4aa036f15aa55e788eda633805d8397274d6c052.tar.lz
nixpkgs-4aa036f15aa55e788eda633805d8397274d6c052.tar.xz
nixpkgs-4aa036f15aa55e788eda633805d8397274d6c052.tar.zst
nixpkgs-4aa036f15aa55e788eda633805d8397274d6c052.zip
rav1e: fix cross
`cargo cbuild` needs to have the `C{C,XX}_FOR_{${platform}}`
variables set just like `cargo` since it is basically a wrapper
around cargo.  Without these variables, it will try to use the
`hostPlatform` C compiler to compile `build.rs` scripts, and will
pass flags to that compiler which only make sense on the
`buildPlatform`.  So it's just doomed without the environment
variables.

Right now it looks like `rav1e` is the only package we have that is
using `cargo-c`, but if that changes in the future we should factor
this out as its own hook, like `maturinBuildHook` and the others.
-rw-r--r--pkgs/tools/video/rav1e/default.nix23
1 files changed, 22 insertions, 1 deletions
diff --git a/pkgs/tools/video/rav1e/default.nix b/pkgs/tools/video/rav1e/default.nix
index 244aed92f81..83b4204d2dc 100644
--- a/pkgs/tools/video/rav1e/default.nix
+++ b/pkgs/tools/video/rav1e/default.nix
@@ -10,10 +10,29 @@
 , zlib
 , libiconv
 , Security
+, buildPackages
 }:
 
 let
   rustTargetPlatformSpec = rust.toRustTargetSpec stdenv.hostPlatform;
+
+  # TODO: if another package starts using cargo-c (seems likely),
+  # factor this out into a makeCargoChook expression in
+  # pkgs/build-support/rust/hooks/default.nix
+  ccForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc";
+  cxxForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++";
+  ccForHost = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
+  cxxForHost = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++";
+  rustBuildPlatform = rust.toRustTarget stdenv.buildPlatform;
+  rustTargetPlatform = rust.toRustTarget stdenv.hostPlatform;
+  setEnvVars = ''
+    env \
+      "CC_${rustBuildPlatform}"="${ccForBuild}" \
+      "CXX_${rustBuildPlatform}"="${cxxForBuild}" \
+      "CC_${rustTargetPlatform}"="${ccForHost}" \
+      "CXX_${rustTargetPlatform}"="${cxxForHost}" \
+  '';
+
 in rustPlatform.buildRustPackage rec {
   pname = "rav1e";
   version = "0.6.3";
@@ -38,11 +57,13 @@ in rustPlatform.buildRustPackage rec {
 
   checkType = "debug";
 
-  postBuild = ''
+  postBuild =  ''
+    ${setEnvVars} \
     cargo cbuild --release --frozen --prefix=${placeholder "out"} --target ${rustTargetPlatformSpec}
   '';
 
   postInstall = ''
+    ${setEnvVars} \
     cargo cinstall --release --frozen --prefix=${placeholder "out"} --target ${rustTargetPlatformSpec}
   '';