Skip to content
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

Setup cargo environment for cargo rustc --print #15026

Merged
merged 2 commits into from
Jan 7, 2025
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
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use std::sync::Arc;

use crate::core::compiler::unit_dependencies::build_unit_dependencies;
use crate::core::compiler::unit_graph::{self, UnitDep, UnitGraph};
use crate::core::compiler::{standard_lib, CrateType, TargetInfo};
use crate::core::compiler::{apply_env_config, standard_lib, CrateType, TargetInfo};
use crate::core::compiler::{BuildConfig, BuildContext, BuildRunner, Compilation};
use crate::core::compiler::{CompileKind, CompileMode, CompileTarget, RustcTargetData, Unit};
use crate::core::compiler::{DefaultExecutor, Executor, UnitInterner};
Expand Down Expand Up @@ -188,6 +188,7 @@ pub fn print<'a>(
}
let target_info = TargetInfo::new(gctx, &build_config.requested_kinds, &rustc, *kind)?;
let mut process = rustc.process();
apply_env_config(gctx, &mut process)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(can add a test if desired, just tell me where)

See https://github.com/rust-lang/cargo/blob/master/tests/testsuite/rustc.rs

Looks like we have --print tests in there. Unsure about custom targets.

We generally ask that PRs are split into

  • One commit that adds the test, showing the currently broken behavior (ie it passes)
  • The fix commit that updates the test to pass with the change

This makes the diff between the two commits show the change in behavior

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah makes sense, will split the commit

process.args(&target_info.rustflags);
if let Some(args) = target_rustc_args {
process.args(args);
Expand Down
31 changes: 31 additions & 0 deletions tests/testsuite/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,37 @@ windows
.run();
}

#[cargo_test]
fn rustc_with_print_cfg_config_toml_env() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file(
"targets/best-target.json",
r#"{
"llvm-target": "x86_64-unknown-none",
"target-pointer-width": "64",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"arch": "x86_64"
}"#,
)
.file(
".cargo/config.toml",
r#"
[build]
target = "best-target"
[env]
RUST_TARGET_PATH = { value = "./targets", relative = true }
"#,
)
.file("src/main.rs", r#"fn main() {} "#)
.build();

p.cargo("rustc -Z unstable-options --print cfg")
.masquerade_as_nightly_cargo(&["print"])
.with_stdout_data(str!["..."].unordered())
.run();
}

#[cargo_test]
fn precedence() {
// Ensure that the precedence of cargo-rustc is only lower than RUSTFLAGS,
Expand Down
Loading