From d6a1dbdfc85479f5a6dd1a2898904bfb775105bd Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 8 Oct 2024 23:26:10 +0200 Subject: [PATCH] Add support for targets within MSRV --- .github/workflows/regenerate-target-info.yml | 5 ++- dev-tools/gen-target-info/src/lib.rs | 2 +- dev-tools/gen-target-info/src/main.rs | 19 +++++++-- dev-tools/gen-target-info/src/read.rs | 45 ++++++++++++++++++-- src/target/generated.rs | 32 ++++++++++++++ 5 files changed, 94 insertions(+), 9 deletions(-) diff --git a/.github/workflows/regenerate-target-info.yml b/.github/workflows/regenerate-target-info.yml index 9d30a4a1..c3b92546 100644 --- a/.github/workflows/regenerate-target-info.yml +++ b/.github/workflows/regenerate-target-info.yml @@ -19,12 +19,13 @@ jobs: git checkout -b regenerate-target-info-${{ github.run_id }} - name: Install rust + # Install both MSRV and current nightly run: | - rustup toolchain install stable nightly --no-self-update --profile minimal + rustup toolchain install 1.63 stable nightly --no-self-update --profile minimal - name: Create lockfile run: cargo update - + - uses: Swatinem/rust-cache@v2 with: cache-all-crates: 'true' diff --git a/dev-tools/gen-target-info/src/lib.rs b/dev-tools/gen-target-info/src/lib.rs index c53839a6..48bb5550 100644 --- a/dev-tools/gen-target-info/src/lib.rs +++ b/dev-tools/gen-target-info/src/lib.rs @@ -2,7 +2,7 @@ mod target_specs; pub use target_specs::*; mod read; -pub use read::get_target_specs_from_json; +pub use read::*; mod write; pub use write::*; diff --git a/dev-tools/gen-target-info/src/main.rs b/dev-tools/gen-target-info/src/main.rs index 835e5c49..68e552e7 100644 --- a/dev-tools/gen-target-info/src/main.rs +++ b/dev-tools/gen-target-info/src/main.rs @@ -1,7 +1,10 @@ -use std::fs::File; use std::io::Write as _; +use std::{fs::File, io::BufRead}; -use gen_target_info::{get_target_specs_from_json, RustcTargetSpecs}; +use gen_target_info::{ + get_target_spec_from_rust_1_63, get_target_specs_from_json, get_targets_rust_1_63, + RustcTargetSpecs, +}; const PRELUDE: &str = r#"//! This file is generated code. Please edit the generator //! in dev-tools/gen-target-info if you need to make changes. @@ -44,7 +47,17 @@ fn generate_target_mapping(f: &mut File, target_specs: &RustcTargetSpecs) -> std } fn main() { - let target_specs = get_target_specs_from_json(); + // Primarily use information from nightly. + let mut target_specs = get_target_specs_from_json(); + // Next, read from MSRV to support old, removed targets. + for target_triple in get_targets_rust_1_63().lines() { + let target_triple = target_triple.unwrap(); + let target_triple = target_triple.trim(); + target_specs + .0 + .entry(target_triple.to_string()) + .or_insert_with(|| get_target_spec_from_rust_1_63(target_triple)); + } // Open file to write to let manifest_dir = env!("CARGO_MANIFEST_DIR"); diff --git a/dev-tools/gen-target-info/src/read.rs b/dev-tools/gen-target-info/src/read.rs index fc31f463..d0e88d81 100644 --- a/dev-tools/gen-target-info/src/read.rs +++ b/dev-tools/gen-target-info/src/read.rs @@ -1,6 +1,44 @@ use std::process; -use crate::RustcTargetSpecs; +use crate::{RustcTargetSpecs, TargetSpec}; + +pub fn get_targets_rust_1_63() -> Vec { + let mut cmd = process::Command::new("rustc"); + cmd.args(["+1.63", "--print", "target-list"]); + cmd.stdout(process::Stdio::piped()); + cmd.stderr(process::Stdio::inherit()); + + let process::Output { status, stdout, .. } = cmd.output().unwrap(); + + if !status.success() { + panic!("{:?} failed with non-zero exit status: {}", cmd, status) + } + + stdout +} + +pub fn get_target_spec_from_rust_1_63(target: &str) -> TargetSpec { + let mut cmd = process::Command::new("rustc"); + cmd.args([ + "+1.63", + "-Zunstable-options", + "--print", + "target-spec-json", + "--target", + target, + ]); + cmd.env("RUSTC_BOOTSTRAP", "1"); + cmd.stdout(process::Stdio::piped()); + cmd.stderr(process::Stdio::inherit()); + + let process::Output { status, stdout, .. } = cmd.output().unwrap(); + + if !status.success() { + panic!("{:?} failed with non-zero exit status: {}", cmd, status) + } + + serde_json::from_slice(&stdout).unwrap() +} pub fn get_target_specs_from_json() -> RustcTargetSpecs { let mut cmd = process::Command::new("rustc"); @@ -9,8 +47,9 @@ pub fn get_target_specs_from_json() -> RustcTargetSpecs { "-Zunstable-options", "--print", "all-target-specs-json", - ]) - .stdout(process::Stdio::piped()); + ]); + cmd.stdout(process::Stdio::piped()); + cmd.stderr(process::Stdio::inherit()); let process::Output { status, stdout, .. } = cmd.output().unwrap(); diff --git a/src/target/generated.rs b/src/target/generated.rs index 6b1b986b..6daee7c5 100644 --- a/src/target/generated.rs +++ b/src/target/generated.rs @@ -485,6 +485,14 @@ pub(crate) fn get(target_triple: &str) -> Option { env: "newlib".into(), abi: "eabihf".into(), }, + "armv7-apple-ios" => Target { + full_arch: "armv7".into(), + arch: "arm".into(), + vendor: "apple".into(), + os: "ios".into(), + env: "".into(), + abi: "".into(), + }, "armv7-linux-androideabi" => Target { full_arch: "armv7".into(), arch: "arm".into(), @@ -669,6 +677,14 @@ pub(crate) fn get(target_triple: &str) -> Option { env: "".into(), abi: "eabihf".into(), }, + "asmjs-unknown-emscripten" => Target { + full_arch: "asmjs".into(), + arch: "wasm32".into(), + vendor: "unknown".into(), + os: "emscripten".into(), + env: "".into(), + abi: "".into(), + }, "avr-unknown-gnu-atmega328" => Target { full_arch: "avr".into(), arch: "avr".into(), @@ -1885,6 +1901,14 @@ pub(crate) fn get(target_triple: &str) -> Option { env: "msvc".into(), abi: "".into(), }, + "x86_64-sun-solaris" => Target { + full_arch: "x86_64".into(), + arch: "x86_64".into(), + vendor: "sun".into(), + os: "solaris".into(), + env: "".into(), + abi: "".into(), + }, "x86_64-unikraft-linux-musl" => Target { full_arch: "x86_64".into(), arch: "x86_64".into(), @@ -2013,6 +2037,14 @@ pub(crate) fn get(target_triple: &str) -> Option { env: "".into(), abi: "".into(), }, + "x86_64-unknown-none-linuxkernel" => Target { + full_arch: "x86_64".into(), + arch: "x86_64".into(), + vendor: "unknown".into(), + os: "none".into(), + env: "gnu".into(), + abi: "".into(), + }, "x86_64-unknown-openbsd" => Target { full_arch: "x86_64".into(), arch: "x86_64".into(),