Skip to content

Commit

Permalink
use apple_sdk::SdkSearch instead of xcrun
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanregner committed Apr 5, 2024
1 parent c8f2633 commit 1bb854f
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions bindgen/src/sdk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO: change this module to thin wrapper of apple_sdk::SdkPath and related utilities

use apple_sdk::Platform;
use apple_sdk::{AppleSdk, Platform, SimpleSdk};
use std::{
path::{Path, PathBuf},
str::FromStr,
Expand All @@ -12,6 +12,8 @@ use thiserror::Error;
pub enum SdkPathError {
#[error("apple_sdk::Error")]
AppleSdkError(apple_sdk::Error),
#[error("sdk not found")]
AppleSdkNotFound,
#[error("path is not sdk path")]
InvalidPath(PathBuf),
#[error("xcrun lookup failed")]
Expand All @@ -31,19 +33,15 @@ impl TryFrom<&Platform> for SdkPath {
type Error = SdkPathError;

fn try_from(platform: &Platform) -> Result<Self, Self::Error> {
use std::process::Command;
let output = Command::new("xcrun")
.args(&[
"--sdk",
&platform.filesystem_name().to_lowercase(),
"--show-sdk-path",
])
.output()
.map_err(SdkPathError::XcrunError)?
.stdout;
let path = std::str::from_utf8(&output)
.expect("invalid output from `xcrun`")
.trim_end();
let sdks = apple_sdk::SdkSearch::default()
.platform(platform.clone())
.search::<SimpleSdk>()
.map_err(SdkPathError::AppleSdkError)?;
let sdk = sdks
.into_iter()
.next()
.ok_or(SdkPathError::AppleSdkNotFound)?;
let path = sdk.path();
Ok(Self(PathBuf::from(path)))
}
}
Expand Down

0 comments on commit 1bb854f

Please sign in to comment.