compiler/rustc/build.rs RUST 42 lines View on github.com → Search inside
1use std::{env, path};23use rustc_windows_rc::{VersionInfoFileType, compile_windows_resource_file};45fn main() {6    let target_os = env::var("CARGO_CFG_TARGET_OS");7    let target_env = env::var("CARGO_CFG_TARGET_ENV");8    if Ok("windows") == target_os.as_deref() && Ok("msvc") == target_env.as_deref() {9        set_windows_exe_options();10    } else {11        // Avoid rerunning the build script every time.12        println!("cargo:rerun-if-changed=build.rs");13    }14}1516// Add a manifest file to rustc.exe.17fn set_windows_exe_options() {18    set_windows_resource();19    set_windows_manifest();20}2122fn set_windows_resource() {23    let stem = path::PathBuf::from("rustc_main_resource");24    let file_description = "rustc";25    let res_file = compile_windows_resource_file(&stem, file_description, VersionInfoFileType::App);26    println!("cargo:rustc-link-arg={}", res_file.display());27}2829fn set_windows_manifest() {30    static WINDOWS_MANIFEST_FILE: &str = "Windows Manifest.xml";3132    let mut manifest = env::current_dir().unwrap();33    manifest.push(WINDOWS_MANIFEST_FILE);3435    println!("cargo:rerun-if-changed={WINDOWS_MANIFEST_FILE}");36    // Embed the Windows application manifest file.37    println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFEST:EMBED");38    println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFESTINPUT:{}", manifest.to_str().unwrap());39    // Turn linker warnings into errors.40    println!("cargo:rustc-link-arg-bin=rustc-main=/WX");41}

Code quality findings 8

Warning: '.unwrap()' will panic on None/Err variants. Prefer using pattern matching (match, if let), combinators (map, and_then), or the '?' operator for robust error handling.
warning correctness unwrap-usage
let mut manifest = env::current_dir().unwrap();
Warning: '.unwrap()' will panic on None/Err variants. Prefer using pattern matching (match, if let), combinators (map, and_then), or the '?' operator for robust error handling.
warning correctness unwrap-usage
println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFESTINPUT:{}", manifest.to_str().unwrap());
Info: Direct printing to stdout/stderr. For application logging, prefer using a logging facade like `log` or `tracing` for better control over levels, formatting, and output destinations.
info maintainability println-macro
println!("cargo:rerun-if-changed=build.rs");
Info: Direct printing to stdout/stderr. For application logging, prefer using a logging facade like `log` or `tracing` for better control over levels, formatting, and output destinations.
info maintainability println-macro
println!("cargo:rustc-link-arg={}", res_file.display());
Info: Direct printing to stdout/stderr. For application logging, prefer using a logging facade like `log` or `tracing` for better control over levels, formatting, and output destinations.
info maintainability println-macro
println!("cargo:rerun-if-changed={WINDOWS_MANIFEST_FILE}");
Info: Direct printing to stdout/stderr. For application logging, prefer using a logging facade like `log` or `tracing` for better control over levels, formatting, and output destinations.
info maintainability println-macro
println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFEST:EMBED");
Info: Direct printing to stdout/stderr. For application logging, prefer using a logging facade like `log` or `tracing` for better control over levels, formatting, and output destinations.
info maintainability println-macro
println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFESTINPUT:{}", manifest.to_str().unwrap());
Info: Direct printing to stdout/stderr. For application logging, prefer using a logging facade like `log` or `tracing` for better control over levels, formatting, and output destinations.
info maintainability println-macro
println!("cargo:rustc-link-arg-bin=rustc-main=/WX");

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.