1use std::{env, path};23use rustc_windows_rc::{VersionInfoFileType, compile_windows_resource_file};45fn main(){6let target_os = env::var("CARGO_CFG_TARGET_OS");7let target_env = env::var("CARGO_CFG_TARGET_ENV");8ifOk("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(){23let stem = path::PathBuf::from("rustc_main_resource");24let file_description ="rustc";25let 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(){30staticWINDOWS_MANIFEST_FILE:&str ="Windows Manifest.xml";3132letmut 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: '.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.
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: 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: 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: 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: 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: 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.