zmwangx / rust-ffmpeg-sys

FFmpeg bindings for Rust.
125 stars 86 forks source link

Issue related to building in RISC-V #31

Open Avimitin opened 2 years ago

Avimitin commented 2 years ago

I've encountered an error in building the ffmpeg-next crate. When running the build function, the env::var("CARGO_CFG_TARGET_ARCH").unwrap() function at line 214 in build.rs file return riscv64gc-unknown-linux-gnu which is a wrong RISC-V arch name. It should return riscv64-unknown-linux-gnu.

I try to fix this issue like below. But I found that I have to change multiple dependencies to build the final program. It will be easier to fix this bug in upstream.

--- B/build.rs  2021-12-11 15:28:22.479878768 +0800
+++ A/build.rs  2021-12-11 15:28:17.586545306 +0800
@@ -211,9 +211,13 @@
         let prefix = compiler[0..suffix_pos].trim_end_matches("-wr"); // "wr-c++" compiler

         configure.arg(format!("--cross-prefix={}-", prefix));
+        let arch_arg = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
         configure.arg(format!(
-            "--arch={}",
-            env::var("CARGO_CFG_TARGET_ARCH").unwrap()
+            "--arch={}", if arch_arg == "riscv64gc-unknown-linux-gnu" {
+                String::from("riscv64-unknown-linux-gnu")
+            } else {
+                arch_arg
+            }
         ));
         configure.arg(format!(
             "--target_os={}",