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:
- Iterate through each registered search location.
- Discover candidate SDKs and filter.
- 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:
- Use path specified by
SDKROOT
environment variable, if defined. - Find SDKs within the Developer Directory defined by the
DEVELOPER_DIR
environment variable. - Find SDKs within the path configured with
xcode-select --switch
. - Find SDKs within the system installed Xcode application.
- 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
impl SdkSearch
Sourcepub fn empty() -> Self
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.
Sourcepub fn progress_callback(self, callback: SdkProgressCallback) -> Self
pub fn progress_callback(self, callback: SdkProgressCallback) -> Self
Define a function that will be called to provide updates on SDK search status.
Sourcepub fn location(self, location: SdkSearchLocation) -> Self
pub fn location(self, location: SdkSearchLocation) -> Self
Add a location to search.
The location will be appended to the current search location list.
Sourcepub fn platform(self, platform: Platform) -> Self
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.
Sourcepub fn minimum_version(self, version: impl Into<SdkVersion>) -> Self
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.
Sourcepub fn maximum_version(self, version: impl Into<SdkVersion>) -> Self
pub fn maximum_version(self, version: impl Into<SdkVersion>) -> Self
Maximum SDK version to return.
Effectively imposes a <=
filter on found SDKs.
Sourcepub fn deployment_target(
self,
target: impl ToString,
version: impl Into<SdkVersion>,
) -> Self
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.
Sourcepub fn sorting(self, sorting: SdkSorting) -> Self
pub fn sorting(self, sorting: SdkSorting) -> Self
Define the sorting order for returned SDKs.
Default is SdkSorting::None.