Skip to content

Commit

Permalink
Add support for targets within MSRV
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Oct 8, 2024
1 parent 1d2bafc commit d6a1dbd
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/regenerate-target-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/gen-target-info/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
19 changes: 16 additions & 3 deletions dev-tools/gen-target-info/src/main.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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");
Expand Down
45 changes: 42 additions & 3 deletions dev-tools/gen-target-info/src/read.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
use std::process;

use crate::RustcTargetSpecs;
use crate::{RustcTargetSpecs, TargetSpec};

pub fn get_targets_rust_1_63() -> Vec<u8> {
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");
Expand All @@ -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();

Expand Down
32 changes: 32 additions & 0 deletions src/target/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@ pub(crate) fn get(target_triple: &str) -> Option<Target> {
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(),
Expand Down Expand Up @@ -669,6 +677,14 @@ pub(crate) fn get(target_triple: &str) -> Option<Target> {
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(),
Expand Down Expand Up @@ -1885,6 +1901,14 @@ pub(crate) fn get(target_triple: &str) -> Option<Target> {
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(),
Expand Down Expand Up @@ -2013,6 +2037,14 @@ pub(crate) fn get(target_triple: &str) -> Option<Target> {
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(),
Expand Down

0 comments on commit d6a1dbd

Please sign in to comment.