From 1bb854f5311b41a6138e3ac8341388cadd0aa1ad Mon Sep 17 00:00:00 2001 From: Nathan Regner Date: Thu, 4 Apr 2024 20:28:51 -0600 Subject: [PATCH] use apple_sdk::SdkSearch instead of xcrun https://github.com/youknowone/apple-sys/issues/4 --- bindgen/src/sdk.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) 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))) } }