mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-25 16:06:14 -05:00
feat: add brokered macOS service mode
This commit is contained in:
21 files changed
+642
-1426
No files matched your search
+44
-26
@@ -2,6 +2,7 @@ use std::{env, path::PathBuf};
|
||||
|
||||
fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
let libxml2_dir = deps_dir.join("libxml2");
|
||||
let install_dir = out_dir.join("libxml2_install");
|
||||
|
||||
// The temporary location where we will build
|
||||
let build_src = out_dir.join("libxml2_build");
|
||||
@@ -14,6 +15,10 @@ fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
if build_src.exists() {
|
||||
std::fs::remove_dir_all(&build_src).unwrap();
|
||||
}
|
||||
if install_dir.exists() {
|
||||
std::fs::remove_dir_all(&install_dir).unwrap();
|
||||
}
|
||||
std::fs::create_dir_all(&install_dir).unwrap();
|
||||
std::fs::create_dir_all(&build_src).unwrap();
|
||||
|
||||
// Copy the source code to OUT_DIR
|
||||
@@ -25,24 +30,28 @@ fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
fs_extra::dir::copy(&libxml2_dir, &build_src, &options).expect("Failed to copy C source code to OUT_DIR");
|
||||
|
||||
// Build the libxml2 library using autotools
|
||||
let dst = autotools::Config::new(&build_src)
|
||||
.reconf("-ivf")
|
||||
.enable_static()
|
||||
.disable_shared()
|
||||
// Disable optional features that complicate static builds
|
||||
.with("python", Some("no"))
|
||||
.with("icu", Some("no"))
|
||||
.with("http", Some("no"))
|
||||
.with("ftp", Some("no"))
|
||||
.with("catalog", Some("no"))
|
||||
.with("docbook", Some("no"))
|
||||
.with("legacy", Some("no"))
|
||||
.with("threads", Some("no"))
|
||||
.with("zlib", Some("no"))
|
||||
.with("lzma", Some("no"))
|
||||
// Ensure position-independent code (safe for static linking)
|
||||
.cflag("-fPIC")
|
||||
.build();
|
||||
let dst = {
|
||||
let mut config = autotools::Config::new(&build_src);
|
||||
config
|
||||
.out_dir(&install_dir)
|
||||
.reconf("-ivf")
|
||||
.enable_static()
|
||||
.disable_shared()
|
||||
// Disable optional features that complicate static builds
|
||||
.with("python", Some("no"))
|
||||
.with("icu", Some("no"))
|
||||
.with("http", Some("no"))
|
||||
.with("ftp", Some("no"))
|
||||
.with("catalog", Some("no"))
|
||||
.with("docbook", Some("no"))
|
||||
.with("legacy", Some("no"))
|
||||
.with("threads", Some("no"))
|
||||
.with("zlib", Some("no"))
|
||||
.with("lzma", Some("no"))
|
||||
// Ensure position-independent code (safe for static linking)
|
||||
.cflag("-fPIC");
|
||||
config.build()
|
||||
};
|
||||
|
||||
let lib_dir = dst.join("lib");
|
||||
let include_dir = dst.join("include/libxml2");
|
||||
@@ -61,6 +70,7 @@ fn build_libxml2(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
|
||||
fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
let openconnect_dir = deps_dir.join("openconnect");
|
||||
let install_dir = out_dir.join("openconnect_install");
|
||||
|
||||
// The temporary location where we will build
|
||||
let build_src = out_dir.join("openconnect_build");
|
||||
@@ -73,6 +83,10 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
if build_src.exists() {
|
||||
std::fs::remove_dir_all(&build_src).unwrap();
|
||||
}
|
||||
if install_dir.exists() {
|
||||
std::fs::remove_dir_all(&install_dir).unwrap();
|
||||
}
|
||||
std::fs::create_dir_all(&install_dir).unwrap();
|
||||
std::fs::create_dir_all(&build_src).unwrap();
|
||||
|
||||
// Copy the source code to OUT_DIR
|
||||
@@ -83,15 +97,13 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
|
||||
fs_extra::dir::copy(&openconnect_dir, &build_src, &options).expect("Failed to copy C source code to OUT_DIR");
|
||||
|
||||
// Build the OpenConnect library using autotools
|
||||
// We explicitly enable static and disable shared to ensure we get a .a file.
|
||||
// .reconf("-ivf") is CRITICAL for git submodules because 'configure'
|
||||
// usually doesn't exist yet and needs to be generated.
|
||||
// Build the OpenConnect library using autotools. Keep the upstream LGPL
|
||||
// library dynamically linked on macOS so it remains replaceable in the app
|
||||
// bundle. Other platforms retain the existing static-link behavior.
|
||||
let mut config = autotools::Config::new(&build_src);
|
||||
config
|
||||
.out_dir(&install_dir)
|
||||
.reconf("-ivf")
|
||||
.enable_static()
|
||||
.disable_shared()
|
||||
.disable("nls", None) // disable translations to save space
|
||||
.disable("docs", None)
|
||||
.disable("dsa-tests", None)
|
||||
@@ -105,10 +117,14 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
config.disable_static().enable_shared();
|
||||
config.ldflag("-liconv");
|
||||
config.env("LIBS", "-liconv");
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
config.enable_static().disable_shared();
|
||||
|
||||
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
|
||||
{
|
||||
config.ldflag("-L/usr/local/lib");
|
||||
@@ -121,10 +137,12 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
let lib_dir = dst.join("lib");
|
||||
let include_dir = dst.join("include");
|
||||
|
||||
// Tell rustc where to find the static library
|
||||
println!("cargo:rustc-link-search=native={}", lib_dir.display());
|
||||
|
||||
// Static linking of openconnect
|
||||
#[cfg(target_os = "macos")]
|
||||
println!("cargo:rustc-link-lib=dylib=openconnect");
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
println!("cargo:rustc-link-lib=static=openconnect");
|
||||
|
||||
// Export include path for downstream use (bindgen / cc)
|
||||
|
||||
Reference in new issue
Block a user