From 923fe510dc0f8677ff2f66572dbebcd38b2fedf1 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 11 Dec 2024 18:32:16 +0000 Subject: [PATCH] fixup! chore(ffi): avoid hardcoding clang version Address review comments --- bindings/matrix-sdk-crypto-ffi/build.rs | 12 +++++++----- bindings/matrix-sdk-ffi/build.rs | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/bindings/matrix-sdk-crypto-ffi/build.rs b/bindings/matrix-sdk-crypto-ffi/build.rs index 5e9d25df213..f1166e76b57 100644 --- a/bindings/matrix-sdk-crypto-ffi/build.rs +++ b/bindings/matrix-sdk-crypto-ffi/build.rs @@ -1,5 +1,4 @@ use std::{env, error::Error}; -use std::ffi::OsStr; use std::path::PathBuf; use std::process::Command; use vergen::EmitBuilder; @@ -17,16 +16,19 @@ fn setup_x86_64_android_workaround() { // Configure rust to statically link against the `libclang_rt.builtins` supplied with clang. // cargo-ndk sets CC_x86_64-linux-android to the path to `clang`, within the Android NDK. - let cc = PathBuf::from(env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set")); + let clang_path = PathBuf::from(env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set")); - let toolchain_path = cc + // clang_path should now look something like + // `.../sdk/ndk/28.0.12674087/toolchains/llvm/prebuilt/linux-x86_64/bin/clang`. + // We strip `/bin/clang` from the end to get the toolchain path. + let toolchain_path = clang_path .ancestors() .nth(2) .expect("could not find NDK toolchain path") .to_str() .expect("NDK toolchain path is not valid UTF-8"); - let clang_version = get_clang_major_version(&cc); + let clang_version = get_clang_major_version(&clang_path); println!("cargo:rustc-link-search={toolchain_path}/lib/clang/{clang_version}/lib/linux/"); println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android"); @@ -34,7 +36,7 @@ fn setup_x86_64_android_workaround() { } /// Run the clang binary at `clang_path`, and return its major version number -fn get_clang_major_version(clang_path: impl AsRef) -> String { +fn get_clang_major_version(clang_path: &PathBuf) -> String { let clang_output = Command::new(clang_path) .arg("-dumpversion") .output() diff --git a/bindings/matrix-sdk-ffi/build.rs b/bindings/matrix-sdk-ffi/build.rs index 00200e44886..c3175c2470d 100644 --- a/bindings/matrix-sdk-ffi/build.rs +++ b/bindings/matrix-sdk-ffi/build.rs @@ -1,5 +1,4 @@ use std::{env, error::Error}; -use std::ffi::OsStr; use std::path::PathBuf; use std::process::Command; use vergen::EmitBuilder; @@ -17,16 +16,19 @@ fn setup_x86_64_android_workaround() { // Configure rust to statically link against the `libclang_rt.builtins` supplied with clang. // cargo-ndk sets CC_x86_64-linux-android to the path to `clang`, within the Android NDK. - let cc = PathBuf::from(env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set")); + let clang_path = PathBuf::from(env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set")); - let toolchain_path = cc + // clang_path should now look something like + // `.../sdk/ndk/28.0.12674087/toolchains/llvm/prebuilt/linux-x86_64/bin/clang`. + // We strip `/bin/clang` from the end to get the toolchain path. + let toolchain_path = clang_path .ancestors() .nth(2) .expect("could not find NDK toolchain path") .to_str() .expect("NDK toolchain path is not valid UTF-8"); - let clang_version = get_clang_major_version(&cc); + let clang_version = get_clang_major_version(&clang_path); println!("cargo:rustc-link-search={toolchain_path}/lib/clang/{clang_version}/lib/linux/"); println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android"); @@ -34,7 +36,7 @@ fn setup_x86_64_android_workaround() { } /// Run the clang binary at `clang_path`, and return its major version number -fn get_clang_major_version(clang_path: impl AsRef) -> String { +fn get_clang_major_version(clang_path: &PathBuf) -> String { let clang_output = Command::new(clang_path) .arg("-dumpversion") .output()