Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions crates/rattler_virtual_packages/src/defaults.rs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use those in a follow-up PR in pixi

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Default virtual package versions to use when the actual version cannot be
//! detected from the host system, for example when detecting virtual packages
//! for a platform other than the current one (see
//! [`crate::VirtualPackages::detect_for_platform`]).

use rattler_conda_types::{Platform, Version};

/// The default `glibc` version to use when the version cannot be detected.
///
/// This is the `glibc` version that ships with RHEL 8 and Debian 10.
pub fn default_glibc_version() -> Version {
"2.28".parse().unwrap()
}

/// The default Linux kernel version to use when the version cannot be
/// detected.
///
/// This is the kernel version that ships with RHEL 8.
pub fn default_linux_version() -> Version {
"4.18".parse().unwrap()
}

/// The default Windows version to use when the version cannot be detected.
pub fn default_windows_version() -> Version {
"10.0".parse().unwrap()
}

/// Returns the default macOS version to use when the version cannot be
/// detected, or `None` if the given platform is not a macOS platform.
pub fn default_mac_os_version(platform: Platform) -> Option<Version> {
match platform {
Platform::Osx64 | Platform::OsxArm64 => Some("13.0".parse().unwrap()),
_ => None,
}
}
Comment thread
pavelzw marked this conversation as resolved.
Resolved
116 changes: 99 additions & 17 deletions crates/rattler_virtual_packages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//! example.

pub mod cuda;
pub mod defaults;
pub mod libc;
pub mod linux;
pub mod osx;
Expand Down Expand Up @@ -307,14 +308,15 @@ impl VirtualPackages {
/// # Cross-compilation defaults
///
/// When cross-compiling (targeting a platform different from the current one), the following
/// defaults are used if no override is provided:
/// defaults are used if no override is provided (see the [`defaults`] module):
///
/// - **Windows** (`__win`): No version specified
/// - **Linux** (`__linux`): Version 0
/// - **OSX** (`__osx`): Version 0
/// - **Windows** (`__win`): [`defaults::default_windows_version`]
/// - **Linux** (`__linux`): [`defaults::default_linux_version`]
/// - **OSX** (`__osx`): [`defaults::default_mac_os_version`]
/// - **iOS** (`__ios`): Version 0 (minimum supported iOS version)
/// - **Android** (`__android`): Version 0 (minimum supported API level)
/// - **`LibC`** (`__glibc`): `glibc` with version 0 (only for Linux platforms)
/// - **`LibC`** (`__glibc`): `glibc` with [`defaults::default_glibc_version`] (only for Linux
/// platforms)
/// - **CUDA** (`__cuda`): Not included (None)
/// - **Archspec**: Platform-specific minimal architecture (e.g., `x86_64` for `osx-64`)
pub fn detect_for_platform(
Expand All @@ -328,29 +330,49 @@ impl VirtualPackages {
} else {
// When cross-compiling, respect overrides but fall back to defaults
let win = if platform.is_windows() {
// Check override first, fall back to default (no version)
virtual_packages
.win
.or_else(|| Some(Windows { version: None }))

@pavelzw pavelzw Aug 5, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this None before while in all other places we used 0? maybe we should make it non-optional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baszalmstra do you have opinions on this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont remember no. I think it might be because the version was added later.

// Check override first, fall back to the default version
virtual_packages.win.or_else(|| {
let version = defaults::default_windows_version();
log_default_virtual_package(
"__win",
platform,
&version,
Windows::DEFAULT_ENV_NAME,
);
Some(Windows {
version: Some(version),
})
})
} else {
None
};

let linux = if platform.is_linux() {
virtual_packages.linux.or_else(|| {
Some(Linux {
version: Version::major(0),
})
let version = defaults::default_linux_version();
log_default_virtual_package(
"__linux",
platform,
&version,
Linux::DEFAULT_ENV_NAME,
);
Some(Linux { version })
})
} else {
None
};

let osx = if platform.is_osx() {
// Check override first, fall back to version 0
// Check override first, fall back to the default version
virtual_packages.osx.or_else(|| {
Some(Osx {
version: Version::major(0),
defaults::default_mac_os_version(platform).map(|version| {
log_default_virtual_package(
"__osx",
platform,
&version,
Osx::DEFAULT_ENV_NAME,
);
Osx { version }
})
})
} else {
Expand Down Expand Up @@ -380,11 +402,18 @@ impl VirtualPackages {
};

let libc = if platform.is_linux() {
// Check override first, fall back to glibc 0
// Check override first, fall back to the default glibc version
virtual_packages.libc.or_else(|| {
let version = defaults::default_glibc_version();
log_default_virtual_package(
"__glibc",
platform,
&version,
LibC::DEFAULT_ENV_NAME,
);
Some(LibC {
family: "glibc".into(),
version: Version::major(0),
version,
})
})
} else {
Expand Down Expand Up @@ -415,6 +444,19 @@ impl VirtualPackages {
}
}

/// Logs that the version of a virtual package could not be detected for the
/// target platform and that a default version is assumed instead.
fn log_default_virtual_package(
name: &str,
platform: Platform,
version: &Version,
env_var_name: &str,
) {
tracing::info!(
"cannot detect the version of the virtual package '{name}' when targeting '{platform}', assuming version {version}; set the {env_var_name} environment variable to override"
);
}

impl From<VirtualPackage> for GenericVirtualPackage {
fn from(package: VirtualPackage) -> Self {
match package {
Expand Down Expand Up @@ -1428,6 +1470,46 @@ mod test {
assert!(win_names.contains(&"__archspec".to_string()));
}

#[test]
fn test_cross_platform_default_versions() {
// When targeting a platform whose virtual packages cannot be detected
// on the host, the pixi default versions are used instead of 0. The
// host's own platform family is skipped because there the detected
// (host) versions take precedence over the defaults.
let overrides = VirtualPackageOverrides::default();
let current = Platform::current();

if !current.is_linux() {
let packages =
VirtualPackages::detect_for_platform(Platform::Linux64, &overrides).unwrap();
assert_eq!(
packages.linux.expect("__linux should be present").version,
defaults::default_linux_version()
);
let libc = packages.libc.expect("__glibc should be present");
assert_eq!(libc.family, "glibc");
assert_eq!(libc.version, defaults::default_glibc_version());
}

if !current.is_osx() {
let packages =
VirtualPackages::detect_for_platform(Platform::OsxArm64, &overrides).unwrap();
assert_eq!(
packages.osx.expect("__osx should be present").version,
defaults::default_mac_os_version(Platform::OsxArm64).unwrap()
);
}

if !current.is_windows() {
let packages =
VirtualPackages::detect_for_platform(Platform::Win64, &overrides).unwrap();
assert_eq!(
packages.win.expect("__win should be present").version,
Some(defaults::default_windows_version())
);
}
}

#[test]
fn test_ios_android_virtual_packages() {
// Cross-compiling to an ios-* subdir yields __ios (falling back to
Expand Down
Loading