2023-03-29 05:18:48 +03:00
|
|
|
fn main() {
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
2023-03-29 05:32:12 +03:00
|
|
|
use std::io::Write;
|
|
|
|
use std::path::Path;
|
2023-03-29 05:45:52 +03:00
|
|
|
|
|
|
|
let repo_dir = std::env::current_dir()
|
|
|
|
.ok()
|
|
|
|
.and_then(|cwd| cwd.parent().map(|p| p.to_path_buf()))
|
|
|
|
.unwrap();
|
|
|
|
let windows_dir = repo_dir.join("assets").join("windows");
|
|
|
|
|
2023-03-29 05:18:48 +03:00
|
|
|
let rcfile_name = Path::new(&std::env::var_os("OUT_DIR").unwrap()).join("resource.rc");
|
|
|
|
let mut rcfile = std::fs::File::create(&rcfile_name).unwrap();
|
|
|
|
write!(
|
|
|
|
rcfile,
|
|
|
|
r#"
|
|
|
|
#include <winres.h>
|
|
|
|
1 RT_MANIFEST "{win}\\console.manifest"
|
|
|
|
"#,
|
|
|
|
win = windows_dir.display().to_string().replace("\\", "\\\\"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
drop(rcfile);
|
|
|
|
|
|
|
|
// Obtain MSVC environment so that the rc compiler can find the right headers.
|
|
|
|
// https://github.com/nabijaczleweli/rust-embed-resource/issues/11#issuecomment-603655972
|
|
|
|
let target = std::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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
embed_resource::compile(rcfile_name);
|
|
|
|
}
|
|
|
|
}
|