mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Use emscripten platform tags for Pyodide
This commit is contained in:
parent
aa2448ef83
commit
0cdfb39aa7
3 changed files with 58 additions and 29 deletions
|
@ -68,7 +68,7 @@ impl fmt::Display for Os {
|
||||||
Self::Illumos { .. } => write!(f, "illumos"),
|
Self::Illumos { .. } => write!(f, "illumos"),
|
||||||
Self::Haiku { .. } => write!(f, "haiku"),
|
Self::Haiku { .. } => write!(f, "haiku"),
|
||||||
Self::Android { .. } => write!(f, "android"),
|
Self::Android { .. } => write!(f, "android"),
|
||||||
Self::Pyodide { .. } => write!(f, "pyodide"),
|
Self::Pyodide { major, minor } => write!(f, "pyodide_{major}_{minor}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,8 +71,8 @@ pub enum PlatformTag {
|
||||||
Illumos { release_arch: SmallString },
|
Illumos { release_arch: SmallString },
|
||||||
/// Ex) `solaris_11_4_x86_64`
|
/// Ex) `solaris_11_4_x86_64`
|
||||||
Solaris { release_arch: SmallString },
|
Solaris { release_arch: SmallString },
|
||||||
/// Ex) `pyodide_2024_0_wasm32`
|
/// Ex) `emscripten_3_1_58_wasm32`
|
||||||
Pyodide { major: u16, minor: u16 },
|
Emscripten { major: u16, minor: u16, patch: u16 },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlatformTag {
|
impl PlatformTag {
|
||||||
|
@ -99,7 +99,7 @@ impl PlatformTag {
|
||||||
PlatformTag::Haiku { .. } => Some("Haiku"),
|
PlatformTag::Haiku { .. } => Some("Haiku"),
|
||||||
PlatformTag::Illumos { .. } => Some("Illumos"),
|
PlatformTag::Illumos { .. } => Some("Illumos"),
|
||||||
PlatformTag::Solaris { .. } => Some("Solaris"),
|
PlatformTag::Solaris { .. } => Some("Solaris"),
|
||||||
PlatformTag::Pyodide { .. } => Some("Pyodide"),
|
PlatformTag::Emscripten { .. } => Some("Emscripten"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,13 @@ impl std::fmt::Display for PlatformTag {
|
||||||
Self::Haiku { release_arch } => write!(f, "haiku_{release_arch}"),
|
Self::Haiku { release_arch } => write!(f, "haiku_{release_arch}"),
|
||||||
Self::Illumos { release_arch } => write!(f, "illumos_{release_arch}"),
|
Self::Illumos { release_arch } => write!(f, "illumos_{release_arch}"),
|
||||||
Self::Solaris { release_arch } => write!(f, "solaris_{release_arch}_64bit"),
|
Self::Solaris { release_arch } => write!(f, "solaris_{release_arch}_64bit"),
|
||||||
Self::Pyodide { major, minor } => write!(f, "pyodide_{major}_{minor}_wasm32"),
|
Self::Emscripten {
|
||||||
|
major,
|
||||||
|
minor,
|
||||||
|
patch,
|
||||||
|
} => {
|
||||||
|
write!(f, "emscripten_{major}_{minor}_{patch}_wasm32")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -620,33 +626,49 @@ impl FromStr for PlatformTag {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(rest) = s.strip_prefix("pyodide_") {
|
if let Some(rest) = s.strip_prefix("emscripten_") {
|
||||||
let mid =
|
let rest =
|
||||||
rest.strip_suffix("_wasm32")
|
rest.strip_suffix("_wasm32")
|
||||||
.ok_or_else(|| ParsePlatformTagError::InvalidArch {
|
.ok_or_else(|| ParsePlatformTagError::InvalidArch {
|
||||||
platform: "pyodide",
|
platform: "emscripten",
|
||||||
tag: s.to_string(),
|
tag: s.to_string(),
|
||||||
})?;
|
})?;
|
||||||
let underscore = memchr::memchr(b'_', mid.as_bytes()).ok_or_else(|| {
|
let underscore = memchr::memchr(b'_', rest.as_bytes()).ok_or_else(|| {
|
||||||
ParsePlatformTagError::InvalidFormat {
|
ParsePlatformTagError::InvalidFormat {
|
||||||
platform: "pyodide",
|
platform: "emscripten",
|
||||||
tag: s.to_string(),
|
tag: s.to_string(),
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
let major: u16 = mid[..underscore].parse().map_err(|_| {
|
let major: u16 = rest[..underscore].parse().map_err(|_| {
|
||||||
ParsePlatformTagError::InvalidMajorVersion {
|
ParsePlatformTagError::InvalidMajorVersion {
|
||||||
platform: "pyodide",
|
platform: "emscripten",
|
||||||
tag: s.to_string(),
|
tag: s.to_string(),
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
let rest = &rest[underscore + 1..];
|
||||||
let minor: u16 = mid[underscore + 1..].parse().map_err(|_| {
|
let underscore = memchr::memchr(b'_', rest.as_bytes()).ok_or_else(|| {
|
||||||
|
ParsePlatformTagError::InvalidFormat {
|
||||||
|
platform: "emscripten",
|
||||||
|
tag: s.to_string(),
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
let minor: u16 = rest[..underscore].parse().map_err(|_| {
|
||||||
ParsePlatformTagError::InvalidMinorVersion {
|
ParsePlatformTagError::InvalidMinorVersion {
|
||||||
platform: "pyodide",
|
platform: "emscripten",
|
||||||
tag: s.to_string(),
|
tag: s.to_string(),
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
return Ok(Self::Pyodide { major, minor });
|
let patch: u16 = rest[underscore + 1..].parse().map_err(|_| {
|
||||||
|
ParsePlatformTagError::InvalidMinorVersion {
|
||||||
|
platform: "emscripten",
|
||||||
|
tag: s.to_string(),
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
return Ok(Self::Emscripten {
|
||||||
|
major,
|
||||||
|
minor,
|
||||||
|
patch,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(ParsePlatformTagError::UnknownFormat(s.to_string()))
|
Err(ParsePlatformTagError::UnknownFormat(s.to_string()))
|
||||||
|
@ -934,22 +956,23 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pyodide_platform() {
|
fn emscripten_platform() {
|
||||||
let tag = PlatformTag::Pyodide {
|
let tag = PlatformTag::Emscripten {
|
||||||
major: 2024,
|
major: 3,
|
||||||
minor: 0,
|
minor: 1,
|
||||||
|
patch: 58,
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
PlatformTag::from_str("pyodide_2024_0_wasm32").as_ref(),
|
PlatformTag::from_str("emscripten_3_1_58_wasm32").as_ref(),
|
||||||
Ok(&tag)
|
Ok(&tag)
|
||||||
);
|
);
|
||||||
assert_eq!(tag.to_string(), "pyodide_2024_0_wasm32");
|
assert_eq!(tag.to_string(), "emscripten_3_1_58_wasm32");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
PlatformTag::from_str("pyodide_2024_0_wasm64"),
|
PlatformTag::from_str("emscripten_3_1_58_wasm64"),
|
||||||
Err(ParsePlatformTagError::InvalidArch {
|
Err(ParsePlatformTagError::InvalidArch {
|
||||||
platform: "pyodide",
|
platform: "emscripten",
|
||||||
tag: "pyodide_2024_0_wasm64".to_string()
|
tag: "emscripten_3_1_58_wasm64".to_string()
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -618,10 +618,16 @@ fn compatible_tags(platform: &Platform) -> Result<Vec<PlatformTag>, PlatformErro
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
(Os::Pyodide { major, minor }, Arch::Wasm32) => {
|
(Os::Pyodide { major, minor }, Arch::Wasm32) => {
|
||||||
vec![PlatformTag::Pyodide {
|
// See: https://pyodide.org/en/stable/development/abi.html#pyodide-2024-0
|
||||||
major: *major,
|
if *major == 2024 && *minor == 0 {
|
||||||
minor: *minor,
|
vec![PlatformTag::Emscripten {
|
||||||
}]
|
major: 3,
|
||||||
|
minor: 1,
|
||||||
|
patch: 58,
|
||||||
|
}]
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(PlatformError::OsVersionDetectionError(format!(
|
return Err(PlatformError::OsVersionDetectionError(format!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue