Skip to content

Commit

Permalink
Include free-threaded builds in the release artifacts (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored Oct 2, 2024
1 parent 1baca22 commit 09bc4f5
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches) -> Result<()

let build_suffix = &stripped_name[triple_start + triple.len() + 1..];

if !release
.suffixes
.iter()
.any(|suffix| build_suffix == *suffix)
{
if !release.suffixes(None).any(|suffix| build_suffix == suffix) {
println!("{} not a release artifact for triple", name);
continue;
}
Expand Down Expand Up @@ -356,14 +352,14 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
let mut wanted_filenames = BTreeMap::new();
for version in python_versions {
for (triple, release) in RELEASE_TRIPLES.iter() {
let python_version = pep440_rs::Version::from_str(version)?;
if let Some(req) = &release.python_version_requirement {
let python_version = pep440_rs::Version::from_str(version)?;
if !req.contains(&python_version) {
continue;
}
}

for suffix in &release.suffixes {
for suffix in release.suffixes(Some(&python_version)) {
wanted_filenames.insert(
format!(
"cpython-{}-{}-{}-{}.tar.zst",
Expand Down
131 changes: 131 additions & 0 deletions src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,68 @@ pub struct TripleRelease {
pub install_only_suffix: &'static str,
/// Minimum Python version this triple is released for.
pub python_version_requirement: Option<VersionSpecifier>,
/// Additional build suffixes to release conditional on the Python version.
pub conditional_suffixes: Vec<ConditionalSuffixes>,
}

/// Describes additional build suffixes conditional on the Python version.
///
/// e.g., free-threaded builds which are only available for Python 3.13+.
pub struct ConditionalSuffixes {
/// The minimum Python version to include these suffixes for.
pub python_version_requirement: VersionSpecifier,
/// Build suffixes to release.
pub suffixes: Vec<&'static str>,
}

impl TripleRelease {
pub fn suffixes<'a>(
&'a self,
python_version: Option<&'a pep440_rs::Version>,
) -> impl Iterator<Item = &'static str> + 'a {
self.suffixes
.iter()
.copied()
.chain(
self.conditional_suffixes
.iter()
.flat_map(move |conditional| {
if python_version.is_none()
|| python_version.is_some_and(|python_version| {
conditional
.python_version_requirement
.contains(python_version)
})
{
conditional.suffixes.iter().copied()
} else {
[].iter().copied()
}
}),
)
}
}

pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::new(|| {
let mut h = BTreeMap::new();

// macOS.
let macos_suffixes = vec!["debug", "pgo", "pgo+lto"];
let macos_suffixes_313 = vec![
"freethreaded+debug",
"freethreaded+pgo",
"freethreaded+pgo+lto",
];
h.insert(
"aarch64-apple-darwin",
TripleRelease {
suffixes: macos_suffixes.clone(),
install_only_suffix: "pgo+lto",
python_version_requirement: None,
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13.0rc0").unwrap(),
suffixes: macos_suffixes_313.clone(),
}],
},
);
h.insert(
Expand All @@ -52,6 +101,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: macos_suffixes,
install_only_suffix: "pgo+lto",
python_version_requirement: None,
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13.0rc0").unwrap(),
suffixes: macos_suffixes_313.clone(),
}],
},
);

Expand All @@ -62,6 +115,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: vec!["pgo"],
install_only_suffix: "pgo",
python_version_requirement: None,
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: vec!["freethreaded+pgo"],
}],
},
);
h.insert(
Expand All @@ -70,6 +127,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: vec!["pgo"],
install_only_suffix: "pgo",
python_version_requirement: None,
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: vec!["freethreaded+pgo"],
}],
},
);

Expand All @@ -81,6 +142,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: vec!["pgo"],
install_only_suffix: "pgo",
python_version_requirement: None,
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: vec!["freethreaded+pgo"],
}],
},
);
h.insert(
Expand All @@ -89,19 +154,37 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: vec!["pgo"],
install_only_suffix: "pgo",
python_version_requirement: None,
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: vec!["freethreaded+pgo"],
}],
},
);

// Linux.
let linux_suffixes_pgo = vec!["debug", "pgo", "pgo+lto"];
let linux_suffixes_nopgo = vec!["debug", "lto", "noopt"];
let linux_suffixes_pgo_freethreaded = vec![
"freethreaded+debug",
"freethreaded+pgo",
"freethreaded+pgo+lto",
];
let linux_suffixes_nopgo_freethreaded = vec![
"freethreaded+debug",
"freethreaded+lto",
"freethreaded+noopt",
];

h.insert(
"aarch64-unknown-linux-gnu",
TripleRelease {
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: None,
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);

Expand All @@ -111,6 +194,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);

Expand All @@ -120,6 +207,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);

Expand All @@ -129,6 +220,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);

Expand All @@ -138,6 +233,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);

Expand All @@ -147,6 +246,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_pgo.clone(),
install_only_suffix: "pgo+lto",
python_version_requirement: None,
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_pgo_freethreaded.clone(),
}],
},
);
h.insert(
Expand All @@ -155,6 +258,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_pgo.clone(),
install_only_suffix: "pgo+lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_pgo_freethreaded.clone(),
}],
},
);
h.insert(
Expand All @@ -163,6 +270,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_pgo.clone(),
install_only_suffix: "pgo+lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_pgo_freethreaded.clone(),
}],
},
);
h.insert(
Expand All @@ -171,6 +282,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);
h.insert(
Expand All @@ -179,6 +294,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: None,
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);
h.insert(
Expand All @@ -187,6 +306,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);
h.insert(
Expand All @@ -195,6 +318,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);
h.insert(
Expand All @@ -203,6 +330,10 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);

Expand Down

0 comments on commit 09bc4f5

Please sign in to comment.