| 1 | use std::{env, path::PathBuf, process::Command}; |
| 2 | |
| 3 | fn main() { |
| 4 | println!("cargo:rerun-if-changed=src/assets/icons/zipelo.ico"); |
| 5 | println!("cargo:rerun-if-env-changed=RC"); |
| 6 | println!("cargo:rerun-if-env-changed=CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER"); |
| 7 | if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") |
| 8 | || env::var_os("CARGO_FEATURE_UI").is_none() |
| 9 | { |
| 10 | return; |
| 11 | } |
| 12 | let output = PathBuf::from(env::var_os("OUT_DIR").unwrap()); |
| 13 | let icon = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()) |
| 14 | .join("src/assets/icons/zipelo.ico"); |
| 15 | let resource = output.join("zipelo.rc"); |
| 16 | std::fs::write( |
| 17 | &resource, |
| 18 | format!( |
| 19 | "1 ICON \"{}\"\n", |
| 20 | icon.display().to_string().replace('\\', "/") |
| 21 | ), |
| 22 | ) |
| 23 | .unwrap(); |
| 24 | let msvc = env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc"); |
| 25 | let compiled = output.join(if msvc { "zipelo.res" } else { "zipelo.o" }); |
| 26 | let compiler = env::var("RC").unwrap_or_else(|_| { |
| 27 | if msvc { |
| 28 | "rc.exe" |
| 29 | } else { |
| 30 | "x86_64-w64-mingw32-windres" |
| 31 | } |
| 32 | .into() |
| 33 | }); |
| 34 | let mut command = Command::new(compiler); |
| 35 | if msvc { |
| 36 | command |
| 37 | .arg("/nologo") |
| 38 | .arg(format!("/fo{}", compiled.display())) |
| 39 | .arg(&resource); |
| 40 | } else { |
| 41 | if let Ok(preprocessor) = env::var("CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER") { |
| 42 | command.arg(format!("--preprocessor={preprocessor}")).args([ |
| 43 | "--preprocessor-arg=-E", |
| 44 | "--preprocessor-arg=-xc", |
| 45 | "--preprocessor-arg=-DRC_INVOKED", |
| 46 | ]); |
| 47 | } |
| 48 | command |
| 49 | .arg("-i") |
| 50 | .arg(&resource) |
| 51 | .arg("-o") |
| 52 | .arg(&compiled) |
| 53 | .arg("-O") |
| 54 | .arg("coff"); |
| 55 | } |
| 56 | assert!( |
| 57 | command |
| 58 | .status() |
| 59 | .expect("Windows 리소스 컴파일러가 필요함") |
| 60 | .success() |
| 61 | ); |
| 62 | println!( |
| 63 | "cargo:rustc-link-arg-bin=zipelo-ui-memory-app={}", |
| 64 | compiled.display() |
| 65 | ); |
| 66 | } |