From cbc44996ec842b325ebd74a25d22edd3c72f9ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AD=90=E5=87=8C?= Date: Fri, 24 May 2024 13:11:12 +0800 Subject: [PATCH 1/2] build: remove the redundant path prefixes --- sudo/build.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sudo/build.rs b/sudo/build.rs index d4688c4..b13eea4 100644 --- a/sudo/build.rs +++ b/sudo/build.rs @@ -93,17 +93,17 @@ fn build_rpc() { let cl_path = cc::windows_registry::find_tool(target.as_str(), "cl.exe").expect("Failed to find cl.exe"); // add cl.exe to our path - let mut path = std::env::var("PATH").unwrap(); + let mut path = env::var("PATH").unwrap(); path.push(';'); path.push_str(cl_path.path().parent().unwrap().to_str().unwrap()); - std::env::set_var("PATH", path); + env::set_var("PATH", path); // Great! we've now finally got a path to midl.exe, and cl.exe is on the PATH // Now we can actually run midl.exe, to compile the IDL file. This will // generate a bunch of files in the OUT_DIR which we need to do RPC. - let mut cmd = std::process::Command::new(midl_path); + let mut cmd = Command::new(midl_path); cmd.arg("../cpp/rpc/sudo_rpc.idl"); cmd.arg("/h").arg("sudo_rpc.h"); cmd.arg("/target").arg("NT100"); // LOAD BEARING: Enables system_handle @@ -166,7 +166,7 @@ fn build_logging() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - let mut cmd = std::process::Command::new(mc_path); + let mut cmd = Command::new(mc_path); cmd.arg("-h").arg(&out_dir); cmd.arg("-r").arg(&out_dir); cmd.arg("../cpp/logging/instrumentation.man"); @@ -233,14 +233,14 @@ fn main() -> io::Result<()> { .expect("Failed to generate resources"); // witchcraft to get windows.h from the SDK to be able to be found, for the resource compiler - let target = std::env::var("TARGET").unwrap(); + let target = env::var("TARGET").unwrap(); if let Some(tool) = cc::windows_registry::find_tool(target.as_str(), "cl.exe") { for (key, value) in tool.env() { - std::env::set_var(key, value); + env::set_var(key, value); } } - if std::env::var_os("CARGO_CFG_WINDOWS").is_some() { + if env::var_os("CARGO_CFG_WINDOWS").is_some() { // TODO:MSFT // Re-add the following: // From 56277c6c046427ca7a00ff9167dca1bbd297dd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AD=90=E5=87=8C?= Date: Fri, 24 May 2024 13:24:42 +0800 Subject: [PATCH 2/2] build: add the warm notice when failed to execute the powershell script for generating related resources --- sudo/build.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sudo/build.rs b/sudo/build.rs index b13eea4..e80dfd9 100644 --- a/sudo/build.rs +++ b/sudo/build.rs @@ -219,7 +219,7 @@ fn main() -> io::Result<()> { // powershell -c .pipelines\convert-resx-to-rc.ps1 .\ no_existy.h res.h no_existy.rc out.rc resource_ids.rs // to generate the resources - Command::new("powershell") + let generate_resources_result = Command::new("powershell") .arg("-NoProfile") .arg("-c") .arg("..\\.pipelines\\convert-resx-to-rc.ps1") @@ -232,6 +232,18 @@ fn main() -> io::Result<()> { .status() .expect("Failed to generate resources"); + if !generate_resources_result.success() { + println!( + "\nFailed to generate resources by executing powershell script: {}.", + generate_resources_result + ); + println!( + "Maybe you haven't granted the access to execute the powershell script on this system." + ); + println!("For more details, please execute the `cargo build` command with the `-vv` flag."); + std::process::exit(1); + } + // witchcraft to get windows.h from the SDK to be able to be found, for the resource compiler let target = env::var("TARGET").unwrap(); if let Some(tool) = cc::windows_registry::find_tool(target.as_str(), "cl.exe") {