Skip to content

Commit

Permalink
Fix framework version parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Nov 23, 2023
1 parent aa64157 commit 5db5caa
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 26 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ env:
# compiling C code, even if just running a `check`/`clippy` build.
INTERESTING_FEATURES: malloc,block,verify,unstable-private
UNSTABLE_FEATURES: unstable-autoreleasesafe,unstable-c-unwind
LATEST_MACOS_FEATURE: unstable-frameworks-macos-13
LATEST_MACOS_FEATURE: unstable-frameworks-macos-14
# Required when we want to use a different runtime than the default `apple`
OTHER_RUNTIME: --no-default-features --features=std
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
Expand Down Expand Up @@ -356,6 +356,9 @@ jobs:
fail-fast: true
matrix:
include:
- name: Test macOS 13
os: macos-13
frameworks: macos-13
- name: Test macOS 11
os: macos-11
frameworks: macos-11
Expand Down
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/header-translator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ proc-macro2 = "1.0.66"
syn = { version = "2.0", features = ["parsing"] }
heck = "0.4"
semver = { version = "1.0", features = ["serde"] }
lenient_semver_parser = "0.4"
51 changes: 46 additions & 5 deletions crates/header-translator/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::collections::{HashMap, HashSet};
use std::error::Error;
use std::fmt;
use std::fs;
use std::path::Path;

use semver::Version;
use serde::Deserialize;

use crate::data;
Expand Down Expand Up @@ -60,6 +62,40 @@ impl Config {
}
}

fn get_version<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Option<Version>, D::Error> {
use serde::de;

struct VersionVisitor;

impl de::Visitor<'_> for VersionVisitor {
type Value = Option<Version>;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a version string")
}

fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(None)
}

fn visit_borrowed_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(Some(
lenient_semver_parser::parse::<Version>(v).map_err(de::Error::custom)?,
))
}
}

deserializer.deserialize_str(VersionVisitor)
}

#[derive(Deserialize, Debug, Default, Clone, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct LibraryData {
Expand All @@ -82,15 +118,20 @@ pub struct LibraryData {
#[serde(default)]
pub extra_features: Vec<String>,
#[serde(default)]
pub macos: Option<semver::VersionReq>,
#[serde(deserialize_with = "get_version")]
pub macos: Option<Version>,
#[serde(default)]
pub maccatalyst: Option<semver::VersionReq>,
#[serde(deserialize_with = "get_version")]
pub maccatalyst: Option<Version>,
#[serde(default)]
pub ios: Option<semver::VersionReq>,
#[serde(deserialize_with = "get_version")]
pub ios: Option<Version>,
#[serde(default)]
pub tvos: Option<semver::VersionReq>,
#[serde(deserialize_with = "get_version")]
pub tvos: Option<Version>,
#[serde(default)]
pub watchos: Option<semver::VersionReq>,
#[serde(deserialize_with = "get_version")]
pub watchos: Option<Version>,
#[serde(default)]
pub examples: Vec<Example>,
}
Expand Down
24 changes: 18 additions & 6 deletions crates/header-translator/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fmt::{self, Write};
use std::fs;
use std::path::Path;
use std::str::FromStr;

use crate::config::{Config, LibraryData};
use crate::library::Library;
use crate::stmt::Stmt;

use semver::VersionReq;

#[derive(Debug, PartialEq)]
pub struct Output {
pub libraries: BTreeMap<String, Library>,
Expand Down Expand Up @@ -75,6 +76,9 @@ impl Output {
]
.into_iter()
.collect();
let mut macos_14_features: BTreeSet<String> = vec!["unstable-frameworks-macos-13".into()]
.into_iter()
.collect();
let mut gnustep_features: BTreeSet<String> = vec![].into_iter().collect();

for (mut library_name, library) in &config.libraries {
Expand All @@ -89,16 +93,20 @@ impl Output {
let _ = features.insert(library_name.to_string(), library_features.collect());

if let Some(version) = &library.macos {
if version.matches(&semver::Version::from_str("10.12.0").unwrap()) {
if VersionReq::parse("<=10.12").unwrap().matches(version) {
macos_10_12_features.insert(format!("{library_name}_all"));
} else if version.matches(&semver::Version::from_str("10.13.0").unwrap()) {
} else if VersionReq::parse("<=10.13").unwrap().matches(version) {
macos_10_13_features.insert(format!("{library_name}_all"));
} else if version.matches(&semver::Version::from_str("11.0.0").unwrap()) {
} else if VersionReq::parse("<=11.0").unwrap().matches(version) {
macos_11_features.insert(format!("{library_name}_all"));
} else if version.matches(&semver::Version::from_str("12.0.0").unwrap()) {
} else if VersionReq::parse("<=12.0").unwrap().matches(version) {
macos_12_features.insert(format!("{library_name}_all"));
} else {
} else if VersionReq::parse("<=13.0").unwrap().matches(version) {
macos_13_features.insert(format!("{library_name}_all"));
} else if VersionReq::parse("<=14.0").unwrap().matches(version) {
macos_14_features.insert(format!("{library_name}_all"));
} else {
error!(?library_name, "has library that does not fit any version");
}
}

Expand Down Expand Up @@ -127,6 +135,10 @@ impl Output {
"unstable-frameworks-macos-13".into(),
macos_13_features.into_iter().collect(),
);
let _ = features.insert(
"unstable-frameworks-macos-14".into(),
macos_14_features.into_iter().collect(),
);
let _ = features.insert(
"unstable-frameworks-gnustep".into(),
gnustep_features.into_iter().collect(),
Expand Down
31 changes: 17 additions & 14 deletions crates/icrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5597,6 +5597,7 @@ unstable-frameworks-macos-10-12 = [
"InputMethodKit_all",
"LocalAuthentication_all",
"MapKit_all",
"MediaPlayer_all",
"MetalKit_all",
"Metal_all",
"OSAKit_all",
Expand All @@ -5607,7 +5608,6 @@ unstable-frameworks-macos-10-12 = [
]
unstable-frameworks-macos-10-13 = [
"ExternalAccessory_all",
"MediaPlayer_all",
"unstable-example-delegate",
"unstable-example-metal",
"unstable-example-nspasteboard",
Expand All @@ -5616,36 +5616,39 @@ unstable-frameworks-macos-10-13 = [
]
unstable-frameworks-macos-11 = [
"Accessibility_all",
"AdSupport_all",
"AuthenticationServices_all",
"AutomaticAssessmentConfiguration_all",
"BusinessChat_all",
"ClassKit_all",
"DeviceCheck_all",
"FileProviderUI_all",
"FileProvider_all",
"IdentityLookup_all",
"LinkPresentation_all",
"SoundAnalysis_all",
"Speech_all",
"UniformTypeIdentifiers_all",
"UserNotifications_all",
"unstable-frameworks-macos-10-13",
]
unstable-frameworks-macos-12 = [
"AdServices_all",
"DataDetection_all",
"LocalAuthenticationEmbeddedUI_all",
"MailKit_all",
"MetricKit_all",
"unstable-frameworks-macos-11",
]
unstable-frameworks-macos-13 = [
"AdServices_all",
"AdSupport_all",
"AuthenticationServices_all",
"AutomaticAssessmentConfiguration_all",
"BackgroundAssets_all",
"BusinessChat_all",
"CallKit_all",
"DeviceCheck_all",
"ExtensionKit_all",
"FileProviderUI_all",
"FileProvider_all",
"HealthKit_all",
"IdentityLookup_all",
"LinkPresentation_all",
"MetalFX_all",
"SoundAnalysis_all",
"Speech_all",
"UserNotifications_all",
"unstable-example-browser",
"unstable-frameworks-macos-12",
]
unstable-frameworks-macos-14 = [
"unstable-frameworks-macos-13",
]

0 comments on commit 5db5caa

Please sign in to comment.