Skip to content

fix(dist/triple): ensure dist::triple::known is up to date with platforms #3841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 8, 2024
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ version = "0.52.0"

[dev-dependencies]
enum-map = "2.5.0"
platforms.workspace = true
proptest.workspace = true
rustup-macros.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
trycmd = "0.15.0"

[build-dependencies]
once_cell.workspace = true
platforms.workspace = true
regex = "1"

[workspace]
Expand All @@ -138,6 +140,7 @@ once_cell = "1.18.0"
opentelemetry = "0.23"
opentelemetry_sdk = { version = "0.23", features = ["rt-tokio"] }
opentelemetry-otlp = "0.16"
platforms = "3.4"
proptest = "1.1.0"
rustup-macros = { path = "rustup-macros" }
tempfile = "3.8"
Expand Down
22 changes: 11 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
use std::env;

include!("src/dist/triple.rs");
use platforms::Platform;

fn from_build() -> Result<PartialTargetTriple, String> {
let triple = if let Ok(triple) = env::var("RUSTUP_OVERRIDE_BUILD_TRIPLE") {
triple
fn from_build() -> Result<String, String> {
let triple =
env::var("RUSTUP_OVERRIDE_BUILD_TRIPLE").unwrap_or_else(|_| env::var("TARGET").unwrap());
if Platform::ALL.iter().any(|p| p.target_triple == triple) {
Ok(triple)
} else {
env::var("TARGET").unwrap()
};
PartialTargetTriple::new(&triple).ok_or(triple)
Err(triple)
}
}

fn main() {
println!("cargo:rerun-if-env-changed=RUSTUP_OVERRIDE_BUILD_TRIPLE");
println!("cargo:rerun-if-env-changed=TARGET");
match from_build() {
Ok(triple) => eprintln!("Computed build based partial target triple: {triple:#?}"),
Ok(triple) => eprintln!("Computed build based on target triple: {triple:#?}"),
Err(s) => {
eprintln!("Unable to parse target '{s}' as a PartialTargetTriple");
eprintln!("Unable to parse target '{s}' as a known target triple");
eprintln!(
"If you are attempting to bootstrap a new target you may need to adjust the\n\
permitted values found in src/dist/triple.rs"
"If you are attempting to bootstrap a new target, you might need to update `platforms` to a newer version"
);
std::process::abort();
}
Expand Down
52 changes: 4 additions & 48 deletions src/dist/triple.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,7 @@
use once_cell::sync::Lazy;
use regex::Regex;

// These lists contain the targets known to rustup, and used to build
// the PartialTargetTriple.

static LIST_ARCHS: &[&str] = &[
"i386",
"i586",
"i686",
"x86_64",
"arm",
"armv7",
"armv7s",
"aarch64",
"mips",
"mipsel",
"mips64",
"mips64el",
"powerpc",
"powerpc64",
"powerpc64le",
"riscv64gc",
"s390x",
"loongarch64",
];
static LIST_OSES: &[&str] = &[
"pc-windows",
"unknown-linux",
"apple-darwin",
"unknown-netbsd",
"apple-ios",
"linux",
"rumprun-netbsd",
"unknown-freebsd",
"unknown-illumos",
];
static LIST_ENVS: &[&str] = &[
"gnu",
"gnux32",
"msvc",
"gnueabi",
"gnueabihf",
"gnuabi64",
"androideabi",
"android",
"musl",
];
pub mod known;

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct PartialTargetTriple {
Expand All @@ -71,9 +27,9 @@ impl PartialTargetTriple {
static RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(&format!(
r"^(?:-({}))?(?:-({}))?(?:-({}))?$",
LIST_ARCHS.join("|"),
LIST_OSES.join("|"),
LIST_ENVS.join("|")
known::LIST_ARCHS.join("|"),
known::LIST_OSES.join("|"),
known::LIST_ENVS.join("|")
))
.unwrap()
});
Expand Down
159 changes: 159 additions & 0 deletions src/dist/triple/known.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
pub static LIST_ARCHS: &[&str] = &[
"aarch64",
"aarch64_be",
"arm",
"arm64_32",
"arm64e",
"arm64ec",
"armeb",
"armebv7r",
"armv4t",
"armv5te",
"armv6",
"armv6k",
"armv7",
"armv7a",
"armv7k",
"armv7r",
"armv7s",
"armv8r",
"avr",
"bpfeb",
"bpfel",
"csky",
"hexagon",
"i386",
"i586",
"i686",
"loongarch64",
"m68k",
"mips",
"mips64",
"mips64el",
"mipsel",
"mipsisa32r6",
"mipsisa32r6el",
"mipsisa64r6",
"mipsisa64r6el",
"msp430",
"nvptx64",
"powerpc",
"powerpc64",
"powerpc64le",
"riscv32gc",
"riscv32i",
"riscv32im",
"riscv32ima",
"riscv32imac",
"riscv32imafc",
"riscv32imc",
"riscv64",
"riscv64gc",
"riscv64imac",
"s390x",
"sparc",
"sparc64",
"sparcv9",
"thumbv4t",
"thumbv5te",
"thumbv6m",
"thumbv7a",
"thumbv7em",
"thumbv7m",
"thumbv7neon",
"thumbv8m.base",
"thumbv8m.main",
"wasm32",
"wasm64",
"x86_64",
"x86_64h",
];
pub static LIST_OSES: &[&str] = &[
"apple-darwin",
"apple-ios",
"apple-tvos",
"apple-watchos",
"esp-espidf",
"fortanix-unknown",
"fuchsia",
"ibm-aix",
"kmc-solid_asp3",
"linux",
"nintendo-3ds",
"nintendo-switch",
"none",
"nvidia-cuda",
"openwrt-linux",
"pc-nto",
"pc-solaris",
"pc-windows",
"risc0-zkvm",
"sony-psp",
"sony-psx",
"sony-vita",
"sun-solaris",
"unikraft-linux",
"unknown-dragonfly",
"unknown-emscripten",
"unknown-freebsd",
"unknown-fuchsia",
"unknown-gnu",
"unknown-haiku",
"unknown-hermit",
"unknown-hurd",
"unknown-illumos",
"unknown-l4re",
"unknown-linux",
"unknown-netbsd",
"unknown-none",
"unknown-nto",
"unknown-openbsd",
"unknown-redox",
"unknown-teeos",
"unknown-uefi",
"unknown-unknown",
"unknown-xous",
"uwp-windows",
"wasi",
"wasip1",
"wasip1-threads",
"wasip2",
"win7-windows",
"wrs-vxworks",
];
pub static LIST_ENVS: &[&str] = &[
"android",
"androideabi",
"atmega328",
"eabi",
"eabihf",
"elf",
"freestanding",
"gnu",
"gnu_ilp32",
"gnuabi64",
"gnuabiv2",
"gnuabiv2hf",
"gnueabi",
"gnueabihf",
"gnullvm",
"gnuspe",
"gnux32",
"macabi",
"msvc",
"musl",
"muslabi64",
"musleabi",
"musleabihf",
"newlibeabihf",
"ohos",
"qnx700",
"qnx710",
"sgx",
"sim",
"softfloat",
"spe",
"uclibc",
"uclibceabi",
"uclibceabihf",
];
49 changes: 4 additions & 45 deletions src/toolchain/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,54 +491,13 @@ mod tests {
use proptest::{collection::vec, prelude::*, string::string_regex};

use crate::{
dist::dist::PartialToolchainDesc,
dist::{
dist::PartialToolchainDesc,
triple::known::{LIST_ARCHS, LIST_ENVS, LIST_OSES},
},
toolchain::names::{CustomToolchainName, ResolvableToolchainName, ToolchainName},
};

//Duplicated from triple.rs as a pragmatic step. TODO: remove duplication.
static LIST_ARCHS: &[&str] = &[
"i386",
"i586",
"i686",
"x86_64",
"arm",
"armv7",
"armv7s",
"aarch64",
"mips",
"mipsel",
"mips64",
"mips64el",
"powerpc",
"powerpc64",
"powerpc64le",
"riscv64gc",
"s390x",
"loongarch64",
];
static LIST_OSES: &[&str] = &[
"pc-windows",
"unknown-linux",
"apple-darwin",
"unknown-netbsd",
"apple-ios",
"linux",
"rumprun-netbsd",
"unknown-freebsd",
"unknown-illumos",
];
static LIST_ENVS: &[&str] = &[
"gnu",
"gnux32",
"msvc",
"gnueabi",
"gnueabihf",
"gnuabi64",
"androideabi",
"android",
"musl",
];

fn partial_toolchain_desc_re() -> String {
let triple_re = format!(
r"(-({}))?(?:-({}))?(?:-({}))?",
Expand Down
Loading
Loading