diff --git a/Cargo.toml b/Cargo.toml index 0a6d376..7d09ecc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,9 @@ extension = [] # Otherwise, links statically to `libsciter-gtk.so` or `libsciter.dylib`. dynamic = [] +# Only for windows static linking +skia = [] + # Build this crate specifically for Sciter.Lite versions # which are incompatible with the regular ones. windowless = [] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..7fc6c3d --- /dev/null +++ b/build.rs @@ -0,0 +1,29 @@ +#[cfg(all(windows, not(feature = "dynamic")))] +fn main() { + use std::{env, path::PathBuf}; + if let Ok(path) = env::var("SCITER_STATIC_LIBRARY") { + let lib_dir = PathBuf::from(path); + println!("cargo:rustc-link-search=native={}", lib_dir.display()); + if cfg!(feature = "nightly") { + // -bundle allow msvc linker link the library with ltcg + // this is a nightly feature now: https://github.com/rust-lang/rust/issues/81490 + println!("cargo:rustc-link-lib=static:-bundle={}", "sciter.static"); + if cfg!(feature = "skia") { + println!("cargo:rustc-link-lib=static:-bundle={}", "atls"); + } + } else { + println!("cargo:rustc-link-lib=static={}", "sciter.static"); + if cfg!(feature = "skia") { + println!("cargo:rustc-link-lib=static={}", "atls"); + } + } + println!("cargo:rustc-link-lib={}", "Comdlg32"); + println!("cargo:rustc-link-lib={}", "windowscodecs"); + println!("cargo:rustc-link-lib={}", "Wininet"); + } else { + println!("cargo:warning=Set SCITER_STATIC_LIBRARY to link static library"); + } +} + +#[cfg(not(all(windows, not(feature = "dynamic"))))] +fn main() {} diff --git a/src/lib.rs b/src/lib.rs index 5f7de96..88051a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -129,7 +129,7 @@ pub use capi::scapi::{ISciterAPI}; use capi::scgraphics::SciterGraphicsAPI; use capi::screquest::SciterRequestAPI; -#[cfg(windows)] +#[cfg(all(windows, feature = "dynamic"))] mod ext { // Note: // Sciter 4.x shipped with universal "sciter.dll" library for different builds: @@ -217,6 +217,13 @@ mod ext { } } +#[cfg(all(windows, not(feature = "dynamic")))] +mod ext { + use capi::scapi::{ISciterAPI}; + + extern "C" { pub fn SciterAPI() -> *const ISciterAPI; } +} + #[cfg(all(feature = "dynamic", unix))] mod ext { #![allow(non_snake_case, non_camel_case_types)]