--- a/build.rs +++ b/build.rs @@ -24,8 +24,14 @@ cfg!(target_os = "macos") } +// alkane-toolkit patch: real wxGTK3 support on Linux via wx-config +// (upstream stubbed every non-Windows/macOS target). +fn is_linux() -> bool { + cfg!(target_os = "linux") +} + fn is_stub() -> bool { - cfg!(feature = "stub_lib") || (!is_windows() && !is_osx()) + cfg!(feature = "stub_lib") || (!is_windows() && !is_osx() && !is_linux()) } fn main() -> Result<(), Box> { @@ -35,6 +41,9 @@ if is_stub() { return Ok(()); } + if is_linux() { + return Ok(()); // libs are linked inside build_linux() + } let wx_libs = get_libs(&wx_path)?; @@ -80,7 +89,7 @@ fn download_dist() -> Result> { let dist_path = Path::new("./dist/"); let wx_path = PathBuf::from(format!("./dist/{}", WX_PATH)); - if wx_path.exists() || is_stub() { + if wx_path.exists() || is_stub() || is_linux() { return Ok(wx_path); } println!("cargo:warning=wx-rs: Downloading source to './dist/"); @@ -107,8 +116,14 @@ return Ok(()); } println!("cargo:rerun-if-changed=cpp_src/wxbridge.cpp"); + println!("cargo:rerun-if-changed=cpp_src/widgets_bridge.cpp"); + + // alkane-toolkit patch: compile the bridge (upstream + widgets extension) + // against the wx shown by $WX_RS_WXCONFIG (default `wx-config`). + if is_linux() { + return build_linux(); + } - //panic!("{}", wx_path.to_str().unwrap()); if is_windows() { build_msvc(wx_path)?; } else { @@ -217,6 +232,59 @@ )?) } +fn build_linux() -> Result<(), Box> { + // alkane-toolkit patch: GTK3 build driven entirely by wx-config, so the + // same code builds against our vendored static wx 3.3.3 (WX_RS_WXCONFIG + // pointing at its prefix) or any system wxGTK3. + let wxconfig = env::var("WX_RS_WXCONFIG").unwrap_or_else(|_| String::from("wx-config")); + let cxxflags = String::from_utf8( + Command::new(&wxconfig).arg("--cxxflags").output()?.stdout, + )?; + let libs = String::from_utf8(Command::new(&wxconfig).arg("--libs").output()?.stdout)?; + // The widget bridge uses GTK directly (zebra-striping CSS), so add GTK's own + // include paths. Best-effort: if pkg-config or gtk3-dev is missing the flags + // are simply empty and the GTK-only code stays disabled. + let gtk_cflags = Command::new("pkg-config") + .args(["--cflags", "gtk+-3.0"]) + .output() + .ok() + .filter(|o| o.status.success()) + .and_then(|o| String::from_utf8(o.stdout).ok()) + .unwrap_or_default(); + + let mut build = cc::Build::new(); + build.cpp(true) + .file("cpp_src/wxbridge.cpp") + .file("cpp_src/widgets_bridge.cpp"); + for f in cxxflags.split_whitespace() { + build.flag(f); + } + for f in gtk_cflags.split_whitespace() { + build.flag(f); + } + build.compile("wxbridge"); + + for flag in libs.split_whitespace() { + if flag.starts_with('/') && flag.ends_with(".a") { + // static wx builds: wx-config emits the archive as a full path + let file = flag.rsplit('/').next().unwrap_or(flag); + let stem = file + .strip_prefix("lib") + .unwrap_or(file) + .strip_suffix(".a") + .unwrap_or(file); + println!("cargo:rustc-link-lib=static={}", stem); + } else if let Some(lib) = flag.strip_prefix("-l") { + println!("cargo:rustc-link-lib={}", lib); + } else if let Some(path) = flag.strip_prefix("-L") { + println!("cargo:rustc-link-search=native={}", path); + } else if flag == "-pthread" { + println!("cargo:rustc-link-arg=-pthread"); + } + } + Ok(()) +} + fn embed_resource_file(wx_path: &PathBuf) { /* This was cribbed from https://github.com/nabijaczleweli/rust-embed-resource