From 3f992193ca282a0cccdfc6ae65fc70e069c3bb3b Mon Sep 17 00:00:00 2001 From: DarkSky Date: Sun, 21 Nov 2021 00:03:46 +0800 Subject: [PATCH 1/2] add static linking support for windows --- Cargo.toml | 3 +++ build.rs | 21 +++++++++++++++++++++ src/lib.rs | 9 ++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 build.rs 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..ad6c362 --- /dev/null +++ b/build.rs @@ -0,0 +1,21 @@ +#[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()); + println!("cargo:rustc-link-lib=static:-bundle={}", "sciter.static"); + if cfg!(feature = "skia") { + println!("cargo:rustc-link-lib=static:-bundle={}", "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)] From ea2bfd5956f8f02e228de9034a853bb9d51cbb54 Mon Sep 17 00:00:00 2001 From: DarkSky Date: Sun, 21 Nov 2021 00:08:58 +0800 Subject: [PATCH 2/2] nightly feature gate --- build.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/build.rs b/build.rs index ad6c362..7fc6c3d 100644 --- a/build.rs +++ b/build.rs @@ -1,20 +1,28 @@ #[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()); - println!("cargo:rustc-link-lib=static:-bundle={}", "sciter.static"); - if cfg!(feature = "skia") { - println!("cargo:rustc-link-lib=static:-bundle={}", "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"); - } - + 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"))))]