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