cross-rs/cross · error

invalid linux version, got

Error message

invalid linux version, got {linux_version}

What it means

configure_target validates the Linux kernel version string used to fill CT_LINUX template values. It must split on '.' into exactly 2 or 3 numeric components (major.minor[.patch]); otherwise it bails with this error. Subsequent parse::<u32> failures also surface as different errors, so this message specifically means the component count is wrong.

Solutions

  1. Provide the version as major.minor or major.minor.patch, e.g. '6.1' or '6.1.55'
  2. Strip a leading 'v' and any distro suffix from the kernel version before calling
  3. Validate with a regex like ^\d+\.\d+(\.\d+)?$ before invoking configure_crosstool

Example fix

// before
let linux_version = "6.1.0-13-amd64";
// after
let linux_version = "6.1.0";
Defensive patterns

Strategy: validation

Validate before calling

let re = regex::Regex::new(r"^\d+\.\d+(\.\d+)?$").unwrap();
assert!(re.is_match(linux_version), "linux version must be major.minor[.patch], got: {linux_version}");

Type guard

fn is_valid_linux_version(v: &str) -> bool {
    let parts: Vec<&str> = v.split('.').collect();
    (2..=3).contains(&parts.len()) && parts.iter().all(|p| p.parse::<u32>().is_ok())
}

Try / catch

match configure_crosstool(&target) {
    Ok(cfg) => cfg,
    Err(e) if e.to_string().contains("invalid linux version") => {
        eprintln!("normalize LINUX_VERSION to X.Y[.Z] (strip 'v' and distro suffixes)");
        std::process::exit(1);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: configure_crosstool is invoked for a 'linux' target with linux_version like '6', '6.1.0.2' (four components), an empty string, or a string using separators other than dots.

Common situations: Misconfigured CI variable (e.g. 'v6.1' with a leading v, or '6-1'), passing a full kernel release string like '6.1.0-13-amd64' from `uname -r`, or an empty env var.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of cross-rs/cross@8c1a8aa4b6 (2026-09-13). Data as JSON: /api/errors/864339d8934fb53c. Report an issue: GitHub.

Appendix: source

Thrown at xtask/src/crosstool.rs:369

        configure_newlib(newlib_version)?
    } else {
        eyre::bail!("unsupported rust target for file {file_name}: unknown libc version");
    };
    if libc.starts_with('\n') {
        libc.remove(0);
    }
    contents = contents
        .replacen(&format!("%CT_{key}_V%"), &libc_v, 1)
        .replacen(&format!("%CT_{key}%"), &libc, 1);
    if let Some(extras) = extras {
        contents = contents.replacen(&format!("%CT_{key}_EXTRAS%"), &extras, 1);
    }

    // configure the `CT_LINUX` values
    if file_name.contains("linux") {
        let linux_versions: Vec<&str> = linux_version.split('.').collect();
        if !matches!(linux_versions.len(), 2 | 3) {
            eyre::bail!("invalid linux version, got {linux_version}");
        }
        let linux_major = linux_versions[0].parse::<u32>()?;
        let linux_minor = linux_versions[1].parse::<u32>()?;
        let linux_patch = linux_versions.get(2).unwrap_or(&"0").parse::<u32>()?;
        let ct_linux_v = format!(
            r#"CT_LINUX_V_{linux_major}_{linux_minor}=y
# CT_LINUX_NO_VERSIONS is not set
CT_LINUX_VERSION="{linux_major}.{linux_minor}.{linux_patch}""#
        );
        let mut ct_linux = String::new();
        if linux_major < 4 || (linux_major == 4 && linux_minor < 8) {
            ct_linux.push_str("\nCT_LINUX_older_than_4_8=y");
            ct_linux.push_str("\nCT_LINUX_4_8_or_older=y");
        } else {
            ct_linux.push_str("\nCT_LINUX_later_than_4_8=y");
            ct_linux.push_str("\nCT_LINUX_4_8_or_later=y");
        }
        if linux_major < 3 || (linux_major == 3 && linux_minor < 7) {

View on GitHub (pinned to 8c1a8aa4b6)