Struct SdkSearch

Source
pub struct SdkSearch { /* private fields */ }
Expand description

Search parameters for locating an Apple SDK.

This type can be used to construct a search for an Apple SDK given user chosen search parameters.

The search algorithm is essentially:

  1. Iterate through each registered search location.
  2. Discover candidate SDKs and filter.
  3. Globally sort (if enabled).

§Search Locations

Search mechanisms / locations are represented via SdkSearchLocation and internally the searcher maintains a vector of locations. The default search locations are:

  1. Use path specified by SDKROOT environment variable, if defined.
  2. Find SDKs within the Developer Directory defined by the DEVELOPER_DIR environment variable.
  3. Find SDKs within the path configured with xcode-select --switch.
  4. Find SDKs within the system installed Xcode application.
  5. Find SDKs within the system installed Xcode Command Line Tools.

Simply call Self::location() to register a new location. If the default locations are not desirable, construct an empty instance via Self::empty() and register your explicit list of locations.

An attempt is made to only search a given location at most once. This is done in order to avoid redundant work. If a location is specified multiple times - even via different SdkSearchLocation variants - subsequent searches of that location will yield no distinct results. Duplicate SDKs can occur in the returned list.

§Filtering

Filters can be registered to control which SDKs are emitted from the search.

By default, no filtering is performed. This means all SDKs in all search locations are returned. This can return SDKs belonging to multiple platforms (e.g. macOS and iOS).

The following functions control filtering:

If you are looking for an SDK to use (e.g. for compilation), you should at least use a platform filter. Otherwise you may see SDKs for platforms you aren’t targeting! It is also an encouraged practice to specify a minimum or maximum SDK version to use.

If you know you are targeting a specific OS version, applying a targeting filter via Self::deployment_target() is recommended. However, this filter is not always reliable. See the caveats in its documentation.

§Sorting

By default, the returned list of SDKs is the chained result of SDKs discovered in all registered search locations. The order of the SDK within each search location is likely the sorted order of directory names as they appear on the filesystem.

If using an SDK for compilation, sorting by the SDK version is likely desired. Using the latest/newest SDK that supports a given deployment target is generally a best practice.

Implementations§

Source§

impl SdkSearch

Source

pub fn empty() -> Self

Obtain an instance with an empty set of search locations.

The search will not resolve any SDKs unless a search location is registered with the instance.

Source

pub fn progress_callback(self, callback: SdkProgressCallback) -> Self

Define a function that will be called to provide updates on SDK search status.

Source

pub fn location(self, location: SdkSearchLocation) -> Self

Add a location to search.

The location will be appended to the current search location list.

Source

pub fn platform(self, platform: Platform) -> Self

Set the SDK platform to search for.

If you do not call this, SDKs for all platforms are returned.

If you are looking for a specific SDK to use, you probably want to call this. If you are searching for all available SDKs, you probably don’t want to call this.

Source

pub fn minimum_version(self, version: impl Into<SdkVersion>) -> Self

Minimum SDK version to require.

Effectively imposes a >= filter on found SDKs.

If using SimpleSdk and the SDK version could not be determined from the filesystem path, the version is assumed to be 0.0 and this filter will likely exclude the SDK.

Source

pub fn maximum_version(self, version: impl Into<SdkVersion>) -> Self

Maximum SDK version to return.

Effectively imposes a <= filter on found SDKs.

Source

pub fn deployment_target( self, target: impl ToString, version: impl Into<SdkVersion>, ) -> Self

Deployment target that the SDK must support.

When set, only SDKs that support targeting the given target-version pair will be returned. Example values are (macosx, 10.15).

Only modern SDKs with SDKSettings.json files advertise their targeting settings in a way that allows this filter to work.

Attempting to use this filter on SimpleSdk will result in a run-time error at search time since these SDKs do not parse SDKSettings files.

Source

pub fn sorting(self, sorting: SdkSorting) -> Self

Define the sorting order for returned SDKs.

Default is SdkSorting::None.

Source

pub fn search<SDK: AppleSdk>(&self) -> Result<Vec<SDK>, Error>

Perform a search, yielding found SDKs sorted by the search’s preferences.

May return an empty vector.

Source

pub fn filter_sdk<SDK: AppleSdk>(&self, sdk: &SDK) -> Result<bool, Error>

Whether an SDK matches our search filter.

This is exposed as a convenience method to allow custom implementations of SDK searching using the filtering logic on this type.

Trait Implementations§

Source§

impl Clone for SdkSearch

Source§

fn clone(&self) -> SdkSearch

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for SdkSearch

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.