Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/cc-rs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cc-v1.1.31
Choose a base ref
...
head repository: rust-lang/cc-rs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cc-v1.1.32
Choose a head ref
  • 3 commits
  • 16 files changed
  • 2 contributors

Commits on Nov 1, 2024

  1. Use Cargo's target information when possible (#1225)

    * Reduce the need for the host target triple
    
    * Use Cargo's target information when possible
    
    rustc's target triples generally only have a vague resemblance to each
    other and to the information needed by `cc`. Let's instead prefer
    `CARGO_CFG_*` variables when available, since these contain the
    information directly from the compiler itself.
    
    In the cases where it isn't available (i.e. when running outside of a
    build script), we fall back to parsing the target triple, but instead of
    doing it in an ad-hoc fashion with string manipulation, we do it in a
    more structured fashion up front.
    
    * Remove unnecessary derive
    
    * Use pre-generated target information
    
    * Use Cow<'static, str> in Target
    
    * Remove redundant test
    
    * Redo from_cargo_environment_variables to be more error resilient
    
    * Fix after merge
    
    * Appease clippy
    
    * Add support for targets within MSRV
    
    * Fix test
    
    * Fix a few more tests
    
    * Properly match previous behaviour
    
    * Update to Rust 2024-10-25
    
    * Use a `const` and binary search instead of a match
    
    * Fix formatting
    madsmtm authored Nov 1, 2024
    Copy the full SHA
    290a629 View commit details

Commits on Nov 2, 2024

  1. Use rustc's knowledge of LLVM/Clang target triples (#1252)

    * Rename Target -> TargetInfo
    
    * Add LLVM target triple to TargetInfo
    
    * Remove AppleOs wrapper struct
    
    * Simplify SDK name lookup code
    
    * Fix passing --target to Clang
    
    Use the same LLVM target triple as rustc does
    
    * Don't pass `--target` twice on Windows
    
    * Simplify LLVM target triple version removal
    
    * Appease clippy
    
    * Fix naming mistake
    
    * Simplify
    madsmtm authored Nov 2, 2024
    Copy the full SHA
    9c663ca View commit details
  2. chore: release v1.1.32 (#1250)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    github-actions[bot] authored Nov 2, 2024
    Copy the full SHA
    c3ad44e View commit details
7 changes: 4 additions & 3 deletions .github/workflows/regenerate-target-info.yml
Original file line number Diff line number Diff line change
@@ -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'
@@ -51,4 +52,4 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create --base main --title "Update src/target_info.rs" --body "Automatically regenerated in CI"
gh pr create --base main --title "Update src/target/generated.rs" --body "Automatically regenerated in CI"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target
/target
Cargo.lock
.idea
*.iml
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.32](https://github.com/rust-lang/cc-rs/compare/cc-v1.1.31...cc-v1.1.32) - 2024-11-02

### Other

- Use `rustc`'s knowledge of LLVM/Clang target triples ([#1252](https://github.com/rust-lang/cc-rs/pull/1252))
- Use Cargo's target information when possible ([#1225](https://github.com/rust-lang/cc-rs/pull/1225))

## [1.1.31](https://github.com/rust-lang/cc-rs/compare/cc-v1.1.30...cc-v1.1.31) - 2024-10-19

### Other
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cc"
version = "1.1.31"
version = "1.1.32"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/cc-rs"
2 changes: 1 addition & 1 deletion dev-tools/gen-target-info/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::*;
99 changes: 68 additions & 31 deletions dev-tools/gen-target-info/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,89 @@
use gen_target_info::{get_target_specs_from_json, write_target_tuple_mapping, RustcTargetSpecs};
use std::{collections::BTreeMap, fs::File, io::Write as _};
use std::io::Write as _;
use std::{fs::File, io::BufRead};

use gen_target_info::{
get_target_spec_from_msrv, get_target_specs_from_json, get_targets_msrv, 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.
"#;

fn generate_riscv_arch_mapping(f: &mut File, target_specs: &RustcTargetSpecs) {
let riscv_target_mapping = target_specs
.0
.iter()
.filter_map(|(target, target_spec)| {
let arch = target.split_once('-').unwrap().0;
(arch.contains("riscv") && arch != target_spec.arch)
.then_some((arch, &*target_spec.arch))
})
.collect::<BTreeMap<_, _>>();
write_target_tuple_mapping(f, "RISCV_ARCH_MAPPING", &riscv_target_mapping);
}
fn generate_target_mapping(f: &mut File, target_specs: &RustcTargetSpecs) -> std::io::Result<()> {
writeln!(f, "use super::TargetInfo;")?;
writeln!(f, "use std::borrow::Cow;")?;
writeln!(f)?;
writeln!(f, "pub(crate) const LIST: &[(&str, TargetInfo)] = &[")?;

for (triple, spec) in &target_specs.0 {
let full_arch = triple.split_once('-').unwrap().0;
let arch = &spec.arch;
let vendor = spec.vendor.as_deref().unwrap_or("unknown");
let os = spec.os.as_deref().unwrap_or("none");
let env = spec.env.as_deref().unwrap_or("");
let abi = spec.abi.as_deref().unwrap_or("");

// Remove deployment target information from LLVM target triples (we
// will add this in another part of CC).
//
// FIXME(madsmtm): Should become unnecessary after
// https://github.com/rust-lang/rust/pull/131037
let unversioned_llvm_target = if spec.llvm_target.contains("apple") {
let mut components = spec.llvm_target.split("-").collect::<Vec<_>>();

components[2] = components[2].trim_end_matches(|c: char| c.is_numeric() || c == '.');

components.join("-")
} else {
spec.llvm_target.clone()
};

writeln!(f, " (")?;
writeln!(f, " {triple:?},")?;
writeln!(f, " TargetInfo {{")?;
writeln!(f, " full_arch: Cow::Borrowed({full_arch:?}),")?;
writeln!(f, " arch: Cow::Borrowed({arch:?}),")?;
writeln!(f, " vendor: Cow::Borrowed({vendor:?}),")?;
writeln!(f, " os: Cow::Borrowed({os:?}),")?;
writeln!(f, " env: Cow::Borrowed({env:?}),")?;
writeln!(f, " abi: Cow::Borrowed({abi:?}),")?;
writeln!(
f,
" unversioned_llvm_target: Cow::Borrowed({unversioned_llvm_target:?}),"
)?;
writeln!(f, " }},")?;
writeln!(f, " ),")?;
}

writeln!(f, "];")?;

fn generate_windows_triple_mapping(f: &mut File, target_specs: &RustcTargetSpecs) {
let windows_target_mapping = target_specs
.0
.iter()
.filter_map(|(target, target_spec)| {
let rust_target_parts = target.splitn(4, '-').collect::<Vec<_>>();
let os = *rust_target_parts.get(2)?;
(os.contains("windows") && target != &*target_spec.llvm_target)
.then_some((&**target, &*target_spec.llvm_target))
})
.collect::<BTreeMap<_, _>>();
write_target_tuple_mapping(f, "WINDOWS_TRIPLE_MAPPING", &windows_target_mapping);
Ok(())
}

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_msrv().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_msrv(target_triple));
}

// Open file to write to
let manifest_dir = env!("CARGO_MANIFEST_DIR");

let path = format!("{manifest_dir}/../../src/target_info.rs");
let mut f = File::create(path).expect("failed to create src/target_info.rs");
let path = format!("{manifest_dir}/../../src/target/generated.rs");
let mut f = File::create(path).expect("failed to create src/target/generated.rs");

f.write_all(PRELUDE.as_bytes()).unwrap();

// Start generating
generate_riscv_arch_mapping(&mut f, &target_specs);
generate_windows_triple_mapping(&mut f, &target_specs);
generate_target_mapping(&mut f, &target_specs).unwrap();

// Flush the data onto disk
f.flush().unwrap();
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_msrv() -> 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_msrv(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();

2 changes: 2 additions & 0 deletions dev-tools/gen-target-info/src/target_specs.rs
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ pub struct TargetSpec {
pub os: Option<String>,
/// `apple`, `pc`
pub vendor: Option<String>,
pub env: Option<String>,
pub abi: Option<String>,
pub pre_link_args: Option<PreLinkArgs>,
}

Loading