Skip to content

Commit

Permalink
fixup! chore(ffi): avoid hardcoding clang version
Browse files Browse the repository at this point in the history
cargo fmt
  • Loading branch information
richvdh committed Dec 11, 2024
1 parent 923fe51 commit a3a5d18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
21 changes: 11 additions & 10 deletions bindings/matrix-sdk-crypto-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{env, error::Error};
use std::path::PathBuf;
use std::process::Command;
use std::{env, error::Error, path::PathBuf, process::Command};

use vergen::EmitBuilder;

/// Adds a temporary workaround for an issue with the Rust compiler and Android
Expand All @@ -13,10 +12,14 @@ fn setup_x86_64_android_workaround() {
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
if target_arch == "x86_64" && target_os == "android" {
// Configure rust to statically link against the `libclang_rt.builtins` supplied with clang.
// 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 clang_path = PathBuf::from(env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set"));
// cargo-ndk sets CC_x86_64-linux-android to the path to `clang`, within the
// Android NDK.
let clang_path = PathBuf::from(
env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set"),
);

// clang_path should now look something like
// `.../sdk/ndk/28.0.12674087/toolchains/llvm/prebuilt/linux-x86_64/bin/clang`.
Expand All @@ -37,10 +40,8 @@ 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: &PathBuf) -> String {
let clang_output = Command::new(clang_path)
.arg("-dumpversion")
.output()
.expect("failed to start clang");
let clang_output =
Command::new(clang_path).arg("-dumpversion").output().expect("failed to start clang");

if !clang_output.status.success() {
panic!("failed to run clang: {}", String::from_utf8_lossy(&clang_output.stderr));
Expand Down
21 changes: 11 additions & 10 deletions bindings/matrix-sdk-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{env, error::Error};
use std::path::PathBuf;
use std::process::Command;
use std::{env, error::Error, path::PathBuf, process::Command};

use vergen::EmitBuilder;

/// Adds a temporary workaround for an issue with the Rust compiler and Android
Expand All @@ -13,10 +12,14 @@ fn setup_x86_64_android_workaround() {
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
if target_arch == "x86_64" && target_os == "android" {
// Configure rust to statically link against the `libclang_rt.builtins` supplied with clang.
// 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 clang_path = PathBuf::from(env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set"));
// cargo-ndk sets CC_x86_64-linux-android to the path to `clang`, within the
// Android NDK.
let clang_path = PathBuf::from(
env::var("CC_x86_64-linux-android").expect("CC_x86_64-linux-android not set"),
);

// clang_path should now look something like
// `.../sdk/ndk/28.0.12674087/toolchains/llvm/prebuilt/linux-x86_64/bin/clang`.
Expand All @@ -37,10 +40,8 @@ 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: &PathBuf) -> String {
let clang_output = Command::new(clang_path)
.arg("-dumpversion")
.output()
.expect("failed to start clang");
let clang_output =
Command::new(clang_path).arg("-dumpversion").output().expect("failed to start clang");

if !clang_output.status.success() {
panic!("failed to run clang: {}", String::from_utf8_lossy(&clang_output.stderr));
Expand Down

0 comments on commit a3a5d18

Please sign in to comment.