diff --git a/bindgen/src/sdk.rs b/bindgen/src/sdk.rs index 6329f33..68f0c1c 100644 --- a/bindgen/src/sdk.rs +++ b/bindgen/src/sdk.rs @@ -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, @@ -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")] @@ -31,19 +33,15 @@ impl TryFrom<&Platform> for SdkPath { type Error = SdkPathError; fn try_from(platform: &Platform) -> Result { - 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::() + .map_err(SdkPathError::AppleSdkError)?; + let sdk = sdks + .into_iter() + .next() + .ok_or(SdkPathError::AppleSdkNotFound)?; + let path = sdk.path(); Ok(Self(PathBuf::from(path))) } }