Skip to content
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
4 changes: 2 additions & 2 deletions src/bin/cc-shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> ExitCode {

// Find the first nonexistent candidate file to which the program's args can be written.
let candidate = (0..).find_map(|i| {
let candidate = out_dir.join(format!("out{}", i));
let candidate = out_dir.join(format!("out{i}"));

if candidate.exists() {
// If the file exists, commands have already run. Try again.
Expand All @@ -45,7 +45,7 @@ fn main() -> ExitCode {

(|| {
for arg in args.clone() {
writeln!(f, "{}", arg)?;
writeln!(f, "{arg}")?;
}

f.flush()?;
Expand Down
8 changes: 4 additions & 4 deletions src/command_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ impl CargoOutput {

pub(crate) fn print_metadata(&self, s: &dyn Display) {
if self.metadata {
println!("{}", s);
println!("{s}");
}
}

pub(crate) fn print_warning(&self, arg: &dyn Display) {
if self.warnings {
println!("cargo:warning={}", arg);
println!("cargo:warning={arg}");
}
}

Expand All @@ -71,7 +71,7 @@ impl CargoOutput {
println!("cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT");
}
if self.debug {
println!("{}", arg);
println!("{arg}");
}
}

Expand Down Expand Up @@ -375,7 +375,7 @@ pub(crate) fn spawn(cmd: &mut Command, cargo_output: &CargoOutput) -> Result<Chi
}
}

cargo_output.print_debug(&format_args!("running: {:?}", cmd));
cargo_output.print_debug(&format_args!("running: {cmd:?}"));

let cmd = ResetStderr(cmd);
let child = cmd
Expand Down
3 changes: 1 addition & 2 deletions src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ impl<'this> RustcCodegenFlags<'this> {
tool.args.push(flag);
} else {
build.cargo_output.print_warning(&format!(
"Inherited flag {:?} is not supported by the currently used CC",
flag
"Inherited flag {flag:?} is not supported by the currently used CC"
));
}
};
Expand Down
76 changes: 37 additions & 39 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl Error {

impl From<io::Error> for Error {
fn from(e: io::Error) -> Error {
Error::new(ErrorKind::IOError, format!("{}", e))
Error::new(ErrorKind::IOError, format!("{e}"))
}
}

Expand Down Expand Up @@ -1463,7 +1463,7 @@ impl Build {

if self.link_lib_modifiers.is_empty() {
self.cargo_output
.print_metadata(&format_args!("cargo:rustc-link-lib=static={}", lib_name));
.print_metadata(&format_args!("cargo:rustc-link-lib=static={lib_name}"));
} else {
self.cargo_output.print_metadata(&format_args!(
"cargo:rustc-link-lib=static:{}={}",
Expand Down Expand Up @@ -1551,7 +1551,7 @@ impl Build {
bad => panic!("unsupported cudart option: {}", bad),
};
self.cargo_output
.print_metadata(&format_args!("cargo:rustc-link-lib={}", lib));
.print_metadata(&format_args!("cargo:rustc-link-lib={lib}"));
}
}

Expand Down Expand Up @@ -1965,7 +1965,7 @@ impl Build {
ToolFamily::Msvc { .. } => ':',
ToolFamily::Gnu | ToolFamily::Clang { .. } => '=',
};
cmd.push_cc_arg(format!("-std{}{}", separator, std).into());
cmd.push_cc_arg(format!("-std{separator}{std}").into());
}
for directory in self.include_directories.iter() {
cmd.args.push("-I".into());
Expand Down Expand Up @@ -2011,9 +2011,9 @@ impl Build {
}
for (key, value) in self.definitions.iter() {
if let Some(ref value) = *value {
cmd.args.push(format!("-D{}={}", key, value).into());
cmd.args.push(format!("-D{key}={value}").into());
} else {
cmd.args.push(format!("-D{}", key).into());
cmd.args.push(format!("-D{key}").into());
}
}

Expand Down Expand Up @@ -2069,7 +2069,7 @@ impl Build {
if opt_level == "z" && !cmd.is_like_clang() {
cmd.push_opt_unless_duplicate("-Os".into());
} else {
cmd.push_opt_unless_duplicate(format!("-O{}", opt_level).into());
cmd.push_opt_unless_duplicate(format!("-O{opt_level}").into());
}

if cmd.is_like_clang() && target.os == "android" {
Expand Down Expand Up @@ -2498,7 +2498,7 @@ impl Build {
match (self.cpp_set_stdlib.as_ref(), cmd.family) {
(None, _) => {}
(Some(stdlib), ToolFamily::Gnu) | (Some(stdlib), ToolFamily::Clang { .. }) => {
cmd.push_cc_arg(format!("-stdlib=lib{}", stdlib).into());
cmd.push_cc_arg(format!("-stdlib=lib{stdlib}").into());
}
_ => {
self.cargo_output.print_warning(&format_args!("cpp_set_stdlib is specified, but the {:?} compiler does not support this option, ignored", cmd.family));
Expand Down Expand Up @@ -2553,11 +2553,11 @@ impl Build {
cmd.arg("-PreDefine");
if let Some(ref value) = *value {
if let Ok(i) = value.parse::<i32>() {
cmd.arg(format!("{} SETA {}", key, i));
cmd.arg(format!("{key} SETA {i}"));
} else if value.starts_with('"') && value.ends_with('"') {
cmd.arg(format!("{} SETS {}", key, value));
cmd.arg(format!("{key} SETS {value}"));
} else {
cmd.arg(format!("{} SETS \"{}\"", key, value));
cmd.arg(format!("{key} SETS \"{value}\""));
}
} else {
cmd.arg(format!("{} SETL {}", key, "{TRUE}"));
Expand All @@ -2570,9 +2570,9 @@ impl Build {

for (key, value) in self.definitions.iter() {
if let Some(ref value) = *value {
cmd.arg(format!("-D{}={}", key, value));
cmd.arg(format!("-D{key}={value}"));
} else {
cmd.arg(format!("-D{}", key));
cmd.arg(format!("-D{key}"));
}
}
}
Expand Down Expand Up @@ -2619,7 +2619,7 @@ impl Build {
// MSVC linker will also be passed foo.lib, so be sure that both
// exist for now.

let lib_dst = dst.with_file_name(format!("{}.lib", lib_name));
let lib_dst = dst.with_file_name(format!("{lib_name}.lib"));
let _ = fs::remove_file(&lib_dst);
match fs::hard_link(dst, &lib_dst).or_else(|_| {
// if hard-link fails, just copy (ignoring the number of bytes written)
Expand Down Expand Up @@ -2852,7 +2852,7 @@ impl Build {
ToolFamily::Clang { zig_cc: false },
);
t.args.push("/c".into());
t.args.push(format!("{}.bat", tool).into());
t.args.push(format!("{tool}.bat").into());
Some(t)
} else {
Some(Tool::new(
Expand All @@ -2876,7 +2876,7 @@ impl Build {
msvc.to_string()
} else {
let cc = if target.abi == "llvm" { clang } else { gnu };
format!("{}.exe", cc)
format!("{cc}.exe")
}
} else if target.os == "ios"
|| target.os == "watchos"
Expand All @@ -2902,9 +2902,9 @@ impl Build {
"wr-cc".to_string()
}
} else if target.arch == "arm" && target.vendor == "kmc" {
format!("arm-kmc-eabi-{}", gnu)
format!("arm-kmc-eabi-{gnu}")
} else if target.arch == "aarch64" && target.vendor == "kmc" {
format!("aarch64-kmc-elf-{}", gnu)
format!("aarch64-kmc-elf-{gnu}")
} else if target.os == "nto" {
// See for details: https://github.com/rust-lang/cc-rs/pull/1319
if self.cpp {
Expand All @@ -2917,7 +2917,7 @@ impl Build {
match prefix {
Some(prefix) => {
let cc = if target.abi == "llvm" { clang } else { gnu };
format!("{}-{}", prefix, cc)
format!("{prefix}-{cc}")
}
None => default.to_string(),
}
Expand Down Expand Up @@ -2988,7 +2988,7 @@ impl Build {
tool.has_internal_target_arg = true;
tool.path.set_file_name(clang.trim_start_matches('-'));
tool.path.set_extension("exe");
tool.args.push(format!("--target={}", target).into());
tool.args.push(format!("--target={target}").into());

// Additionally, shell scripts for target i686-linux-android versions 16 to 24
// pass the `mstackrealign` option so we do that here as well.
Expand Down Expand Up @@ -3275,11 +3275,11 @@ impl Build {
// Windows use bat files so we have to be a bit more specific
if cfg!(windows) {
let mut cmd = self.cmd("cmd");
name = format!("em{}.bat", tool).into();
name = format!("em{tool}.bat").into();
cmd.arg("/c").arg(&name);
Some(cmd)
} else {
name = format!("em{}", tool).into();
name = format!("em{tool}").into();
Some(self.cmd(&name))
}
} else if target.arch == "wasm32" || target.arch == "wasm64" {
Expand All @@ -3290,7 +3290,7 @@ impl Build {
// of "llvm-ar"...
let compiler = self.get_base_compiler().ok()?;
if compiler.is_like_clang() {
name = format!("llvm-{}", tool).into();
name = format!("llvm-{tool}").into();
self.search_programs(
&mut self.cmd(&compiler.path),
&name,
Expand All @@ -3309,7 +3309,7 @@ impl Build {
Some(t) => t,
None => {
if target.os == "android" {
name = format!("llvm-{}", tool).into();
name = format!("llvm-{tool}").into();
match Command::new(&name).arg("--version").status() {
Ok(status) if status.success() => (),
_ => {
Expand Down Expand Up @@ -3361,15 +3361,15 @@ impl Build {
// but the OS comes bundled with a GNU-compatible variant.
//
// Use the GNU-variant to match other Unix systems.
name = format!("g{}", tool).into();
name = format!("g{tool}").into();
self.cmd(&name)
} else if target.os == "vxworks" {
name = format!("wr-{}", tool).into();
name = format!("wr-{tool}").into();
self.cmd(&name)
} else if target.os == "nto" {
// Ref: https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.utilities/topic/a/ar.html
name = match target.full_arch {
"i586" => format!("ntox86-{}", tool).into(),
"i586" => format!("ntox86-{tool}").into(),
"x86" | "aarch64" | "x86_64" => {
format!("nto{}-{}", target.arch, tool).into()
}
Expand Down Expand Up @@ -3582,7 +3582,7 @@ impl Build {
.and_then(|path_entries| {
env::split_paths(path_entries).find_map(|path_entry| {
for prefix in prefixes {
let target_compiler = format!("{}{}{}", prefix, suffix, extension);
let target_compiler = format!("{prefix}{suffix}{extension}");
if path_entry.join(&target_compiler).exists() {
return Some(prefix);
}
Expand Down Expand Up @@ -3706,7 +3706,7 @@ impl Build {
// <https://github.com/rust-lang/cc-rs/pull/1215> for details.
if self.emit_rerun_if_env_changed && !provided_by_cargo(v) && v != "PATH" {
self.cargo_output
.print_metadata(&format_args!("cargo:rerun-if-env-changed={}", v));
.print_metadata(&format_args!("cargo:rerun-if-env-changed={v}"));
}
let r = env::var_os(v).map(Arc::from);
self.cargo_output.print_metadata(&format_args!(
Expand Down Expand Up @@ -3735,7 +3735,7 @@ impl Build {
Some(s) => Ok(s),
None => Err(Error::new(
ErrorKind::EnvVarNotFound,
format!("Environment variable {} not defined.", v),
format!("Environment variable {v} not defined."),
)),
}
}
Expand All @@ -3745,7 +3745,7 @@ impl Build {
env.to_str().map(String::from).ok_or_else(|| {
Error::new(
ErrorKind::EnvVarNotFound,
format!("Environment variable {} is not valid utf-8.", v),
format!("Environment variable {v} is not valid utf-8."),
)
})
}
Expand Down Expand Up @@ -3956,8 +3956,7 @@ impl Build {
// If below 10.9, we ignore it and let the SDK's target definitions handle it.
if major == 10 && minor < 9 {
self.cargo_output.print_warning(&format_args!(
"macOS deployment target ({}) too low, it will be increased",
deployment_target_ver
"macOS deployment target ({deployment_target_ver}) too low, it will be increased"
));
return None;
}
Expand All @@ -3968,8 +3967,7 @@ impl Build {
// If below 10.7, we ignore it and let the SDK's target definitions handle it.
if major < 7 {
self.cargo_output.print_warning(&format_args!(
"iOS deployment target ({}) too low, it will be increased",
deployment_target_ver
"iOS deployment target ({deployment_target_ver}) too low, it will be increased"
));
return None;
}
Expand Down Expand Up @@ -4140,7 +4138,7 @@ impl Default for Build {
}

fn fail(s: &str) -> ! {
eprintln!("\n\nerror occurred in cc-rs: {}\n\n", s);
eprintln!("\n\nerror occurred in cc-rs: {s}\n\n");
std::process::exit(1);
}

Expand Down Expand Up @@ -4202,13 +4200,13 @@ fn autodetect_android_compiler(raw_target: &str, gnu: &str, clang: &str) -> Stri
.replace("armv7", "arm")
.replace("thumbv7neon", "arm")
.replace("thumbv7", "arm");
let gnu_compiler = format!("{}-{}", target, gnu);
let clang_compiler = format!("{}-{}", target, clang);
let gnu_compiler = format!("{target}-{gnu}");
let clang_compiler = format!("{target}-{clang}");

// On Windows, the Android clang compiler is provided as a `.cmd` file instead
// of a `.exe` file. `std::process::Command` won't run `.cmd` files unless the
// `.cmd` is explicitly appended to the command name, so we do that here.
let clang_compiler_cmd = format!("{}-{}.cmd", target, clang);
let clang_compiler_cmd = format!("{target}-{clang}.cmd");

// Check if gnu compiler is present
// if not, use clang
Expand Down
5 changes: 2 additions & 3 deletions src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ impl Tool {

let family = detect_family(&path, &args).unwrap_or_else(|e| {
cargo_output.print_warning(&format_args!(
"Compiler family detection failed due to error: {}",
e
"Compiler family detection failed due to error: {e}"
));
match path.file_name().map(OsStr::to_string_lossy) {
Some(fname) if fname.contains("clang-cl") => ToolFamily::Msvc { clang_cl: true },
Expand Down Expand Up @@ -505,7 +504,7 @@ impl ToolFamily {
ToolFamily::Gnu | ToolFamily::Clang { .. } => {
cmd.push_cc_arg(
dwarf_version
.map_or_else(|| "-g".into(), |v| format!("-gdwarf-{}", v))
.map_or_else(|| "-g".into(), |v| format!("-gdwarf-{v}"))
.into(),
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/windows/find_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,11 @@ pub fn find_vs_version() -> Result<VsVers, String> {
"14.0" => Ok(VsVers::Vs14),
vers => Err(format!(
"\n\n\
unsupported or unknown VisualStudio version: {}\n\
unsupported or unknown VisualStudio version: {vers}\n\
if another version is installed consider running \
the appropriate vcvars script before building this \
crate\n\
",
vers
"
)),
},
_ => {
Expand Down
Loading