Skip to content

Commit 34a148c

Browse files
committed
Fix framework version parsing
1 parent 3d7d46e commit 34a148c

File tree

6 files changed

+106
-26
lines changed

6 files changed

+106
-26
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ env:
5353
# compiling C code, even if just running a `check`/`clippy` build.
5454
INTERESTING_FEATURES: malloc,block,verify,unstable-private
5555
UNSTABLE_FEATURES: unstable-autoreleasesafe,unstable-c-unwind
56-
LATEST_MACOS_FEATURE: unstable-frameworks-macos-13
56+
LATEST_MACOS_FEATURE: unstable-frameworks-macos-14
5757
# Required when we want to use a different runtime than the default `apple`
5858
OTHER_RUNTIME: --no-default-features --features=std
5959
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
@@ -356,6 +356,9 @@ jobs:
356356
fail-fast: true
357357
matrix:
358358
include:
359+
- name: Test macOS 13
360+
os: macos-13
361+
frameworks: macos-13
359362
- name: Test macOS 11
360363
os: macos-11
361364
frameworks: macos-11

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/header-translator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ proc-macro2 = "1.0.66"
2020
syn = { version = "2.0", features = ["parsing"] }
2121
heck = "0.4"
2222
semver = { version = "1.0", features = ["serde"] }
23+
lenient_semver_parser = "0.4"

crates/header-translator/src/config.rs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::collections::{HashMap, HashSet};
22
use std::error::Error;
3+
use std::fmt;
34
use std::fs;
45
use std::path::Path;
56

7+
use semver::Version;
68
use serde::Deserialize;
79

810
use crate::data;
@@ -60,6 +62,40 @@ impl Config {
6062
}
6163
}
6264

65+
fn get_version<'de, D: serde::Deserializer<'de>>(
66+
deserializer: D,
67+
) -> Result<Option<Version>, D::Error> {
68+
use serde::de;
69+
70+
struct VersionVisitor;
71+
72+
impl de::Visitor<'_> for VersionVisitor {
73+
type Value = Option<Version>;
74+
75+
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
76+
formatter.write_str("a version string")
77+
}
78+
79+
fn visit_none<E>(self) -> Result<Self::Value, E>
80+
where
81+
E: de::Error,
82+
{
83+
Ok(None)
84+
}
85+
86+
fn visit_borrowed_str<E>(self, v: &str) -> Result<Self::Value, E>
87+
where
88+
E: de::Error,
89+
{
90+
Ok(Some(
91+
lenient_semver_parser::parse::<Version>(v).map_err(de::Error::custom)?,
92+
))
93+
}
94+
}
95+
96+
deserializer.deserialize_str(VersionVisitor)
97+
}
98+
6399
#[derive(Deserialize, Debug, Default, Clone, PartialEq, Eq)]
64100
#[serde(deny_unknown_fields)]
65101
pub struct LibraryData {
@@ -82,15 +118,20 @@ pub struct LibraryData {
82118
#[serde(default)]
83119
pub extra_features: Vec<String>,
84120
#[serde(default)]
85-
pub macos: Option<semver::VersionReq>,
121+
#[serde(deserialize_with = "get_version")]
122+
pub macos: Option<Version>,
86123
#[serde(default)]
87-
pub maccatalyst: Option<semver::VersionReq>,
124+
#[serde(deserialize_with = "get_version")]
125+
pub maccatalyst: Option<Version>,
88126
#[serde(default)]
89-
pub ios: Option<semver::VersionReq>,
127+
#[serde(deserialize_with = "get_version")]
128+
pub ios: Option<Version>,
90129
#[serde(default)]
91-
pub tvos: Option<semver::VersionReq>,
130+
#[serde(deserialize_with = "get_version")]
131+
pub tvos: Option<Version>,
92132
#[serde(default)]
93-
pub watchos: Option<semver::VersionReq>,
133+
#[serde(deserialize_with = "get_version")]
134+
pub watchos: Option<Version>,
94135
#[serde(default)]
95136
pub examples: Vec<Example>,
96137
}

crates/header-translator/src/output.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};
22
use std::fmt::{self, Write};
33
use std::fs;
44
use std::path::Path;
5-
use std::str::FromStr;
65

76
use crate::config::{Config, LibraryData};
87
use crate::library::Library;
98
use crate::stmt::Stmt;
109

10+
use semver::VersionReq;
11+
1112
#[derive(Debug, PartialEq)]
1213
pub struct Output {
1314
pub libraries: BTreeMap<String, Library>,
@@ -75,6 +76,9 @@ impl Output {
7576
]
7677
.into_iter()
7778
.collect();
79+
let mut macos_14_features: BTreeSet<String> = vec!["unstable-frameworks-macos-13".into()]
80+
.into_iter()
81+
.collect();
7882
let mut gnustep_features: BTreeSet<String> = vec![].into_iter().collect();
7983

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

9195
if let Some(version) = &library.macos {
92-
if version.matches(&semver::Version::from_str("10.12.0").unwrap()) {
96+
if VersionReq::parse("<=10.12").unwrap().matches(version) {
9397
macos_10_12_features.insert(format!("{library_name}_all"));
94-
} else if version.matches(&semver::Version::from_str("10.13.0").unwrap()) {
98+
} else if VersionReq::parse("<=10.13").unwrap().matches(version) {
9599
macos_10_13_features.insert(format!("{library_name}_all"));
96-
} else if version.matches(&semver::Version::from_str("11.0.0").unwrap()) {
100+
} else if VersionReq::parse("<=11.0").unwrap().matches(version) {
97101
macos_11_features.insert(format!("{library_name}_all"));
98-
} else if version.matches(&semver::Version::from_str("12.0.0").unwrap()) {
102+
} else if VersionReq::parse("<=12.0").unwrap().matches(version) {
99103
macos_12_features.insert(format!("{library_name}_all"));
100-
} else {
104+
} else if VersionReq::parse("<=13.0").unwrap().matches(version) {
101105
macos_13_features.insert(format!("{library_name}_all"));
106+
} else if VersionReq::parse("<=14.0").unwrap().matches(version) {
107+
macos_14_features.insert(format!("{library_name}_all"));
108+
} else {
109+
error!(?library_name, "has library that does not fit any version");
102110
}
103111
}
104112

@@ -127,6 +135,10 @@ impl Output {
127135
"unstable-frameworks-macos-13".into(),
128136
macos_13_features.into_iter().collect(),
129137
);
138+
let _ = features.insert(
139+
"unstable-frameworks-macos-14".into(),
140+
macos_14_features.into_iter().collect(),
141+
);
130142
let _ = features.insert(
131143
"unstable-frameworks-gnustep".into(),
132144
gnustep_features.into_iter().collect(),

crates/icrate/Cargo.toml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5597,6 +5597,7 @@ unstable-frameworks-macos-10-12 = [
55975597
"InputMethodKit_all",
55985598
"LocalAuthentication_all",
55995599
"MapKit_all",
5600+
"MediaPlayer_all",
56005601
"MetalKit_all",
56015602
"Metal_all",
56025603
"OSAKit_all",
@@ -5607,7 +5608,6 @@ unstable-frameworks-macos-10-12 = [
56075608
]
56085609
unstable-frameworks-macos-10-13 = [
56095610
"ExternalAccessory_all",
5610-
"MediaPlayer_all",
56115611
"unstable-example-delegate",
56125612
"unstable-example-metal",
56135613
"unstable-example-nspasteboard",
@@ -5616,36 +5616,39 @@ unstable-frameworks-macos-10-13 = [
56165616
]
56175617
unstable-frameworks-macos-11 = [
56185618
"Accessibility_all",
5619+
"AdSupport_all",
5620+
"AuthenticationServices_all",
5621+
"AutomaticAssessmentConfiguration_all",
5622+
"BusinessChat_all",
56195623
"ClassKit_all",
5624+
"DeviceCheck_all",
5625+
"FileProviderUI_all",
5626+
"FileProvider_all",
5627+
"IdentityLookup_all",
5628+
"LinkPresentation_all",
5629+
"SoundAnalysis_all",
5630+
"Speech_all",
56205631
"UniformTypeIdentifiers_all",
5632+
"UserNotifications_all",
56215633
"unstable-frameworks-macos-10-13",
56225634
]
56235635
unstable-frameworks-macos-12 = [
5636+
"AdServices_all",
56245637
"DataDetection_all",
56255638
"LocalAuthenticationEmbeddedUI_all",
56265639
"MailKit_all",
56275640
"MetricKit_all",
56285641
"unstable-frameworks-macos-11",
56295642
]
56305643
unstable-frameworks-macos-13 = [
5631-
"AdServices_all",
5632-
"AdSupport_all",
5633-
"AuthenticationServices_all",
5634-
"AutomaticAssessmentConfiguration_all",
56355644
"BackgroundAssets_all",
5636-
"BusinessChat_all",
56375645
"CallKit_all",
5638-
"DeviceCheck_all",
56395646
"ExtensionKit_all",
5640-
"FileProviderUI_all",
5641-
"FileProvider_all",
56425647
"HealthKit_all",
5643-
"IdentityLookup_all",
5644-
"LinkPresentation_all",
56455648
"MetalFX_all",
5646-
"SoundAnalysis_all",
5647-
"Speech_all",
5648-
"UserNotifications_all",
56495649
"unstable-example-browser",
56505650
"unstable-frameworks-macos-12",
56515651
]
5652+
unstable-frameworks-macos-14 = [
5653+
"unstable-frameworks-macos-13",
5654+
]

0 commit comments

Comments
 (0)