build.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use std::{env, path::PathBuf};
  2. fn main() {
  3. let tauri_path = PathBuf::from("../../../ui");
  4. let mut tauri_impl_path = tauri_path.clone();
  5. let mut build = cc::Build::new();
  6. build
  7. .include(&tauri_path)
  8. .flag_if_supported("-std=c11")
  9. .flag_if_supported("-w");
  10. if env::var("DEBUG").is_err() {
  11. build.define("NDEBUG", None);
  12. } else {
  13. build.define("DEBUG", None);
  14. }
  15. let target = env::var("TARGET").unwrap();
  16. if target.contains("windows") {
  17. tauri_impl_path.push("tauri-windows.c");
  18. build.define("WEBVIEW_WINAPI", None);
  19. for &lib in &["ole32", "comctl32", "oleaut32", "uuid", "gdi32"] {
  20. println!("cargo:rustc-link-lib={}", lib);
  21. }
  22. } else if target.contains("linux") || target.contains("bsd") {
  23. tauri_impl_path.push("tauri-gtk.c");
  24. let webkit = pkg_config::Config::new()
  25. .atleast_version("2.8")
  26. .probe("webkit2gtk-4.0")
  27. .unwrap();
  28. for path in webkit.include_paths {
  29. build.include(path);
  30. }
  31. build.define("WEBVIEW_GTK", None);
  32. } else if target.contains("apple") {
  33. tauri_impl_path.push("tauri-cocoa.m");
  34. build
  35. .define("WEBVIEW_COCOA", None)
  36. .flag("-x")
  37. .flag("objective-c");
  38. println!("cargo:rustc-link-lib=framework=Cocoa");
  39. println!("cargo:rustc-link-lib=framework=WebKit");
  40. } else {
  41. panic!("unsupported target");
  42. }
  43. build
  44. .file(tauri_impl_path.into_os_string().into_string().unwrap())
  45. .file("tauri.c");
  46. build.compile("tauri");
  47. }