mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-23 23:46:13 -05:00
feat: prepare 3.0.0 release
This commit is contained in:
252 files changed
+26210
-7457
No files matched your search
+67
-69
@@ -1,37 +1,8 @@
|
||||
use std::{env, path::PathBuf, process::Command};
|
||||
|
||||
fn apply_patches(patches_dir: &PathBuf, build_src: &PathBuf) {
|
||||
let patches = std::fs::read_dir(patches_dir)
|
||||
.expect("Failed to read patches directory")
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter(|entry| entry.path().extension().and_then(|s| s.to_str()) == Some("patch"))
|
||||
.map(|entry| entry.path())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Sort patches to ensure they are applied in order
|
||||
let mut patches = patches;
|
||||
patches.sort();
|
||||
|
||||
for patch in patches {
|
||||
println!("cargo:rerun-if-changed={}", patch.display());
|
||||
println!("Applying patch: {}", patch.display());
|
||||
|
||||
let status = Command::new("patch")
|
||||
.arg("-p1") // Strip one level of path (standard for git diffs)
|
||||
.arg("-i") // Input file
|
||||
.arg(&patch)
|
||||
.current_dir(build_src) // Run INSIDE the copied dir
|
||||
.status()
|
||||
.expect("Failed to execute patch command");
|
||||
|
||||
if !status.success() {
|
||||
panic!("Failed to apply patch file: {}", patch.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
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");
|
||||
@@ -44,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
|
||||
@@ -55,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");
|
||||
@@ -91,12 +70,12 @@ 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 patches_dir = deps_dir.join("patches");
|
||||
let install_dir = out_dir.join("openconnect_install");
|
||||
|
||||
// The temporary location where we will build
|
||||
let build_src = out_dir.join("openconnect_build");
|
||||
|
||||
// Track changes so cargo rebuilds if patch or submodule changes
|
||||
// Track changes so cargo rebuilds if submodule changes
|
||||
println!("cargo:rerun-if-changed={}", openconnect_dir.display());
|
||||
|
||||
// Prepare the build directory
|
||||
@@ -104,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
|
||||
@@ -114,18 +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");
|
||||
|
||||
// Apply all patches from the patches directory
|
||||
apply_patches(&patches_dir, &build_src);
|
||||
|
||||
// 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)
|
||||
@@ -139,10 +117,14 @@ fn build_openconnect(deps_dir: &PathBuf, out_dir: &PathBuf) -> PathBuf {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
config.disable_static().enable_shared().without("gnutls", None);
|
||||
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");
|
||||
@@ -155,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)
|
||||
@@ -173,6 +157,14 @@ fn main() {
|
||||
let deps_dir = PathBuf::from(manifest_dir).join("deps");
|
||||
|
||||
let oc_dst = build_openconnect(&deps_dir, &out_dir);
|
||||
println!(
|
||||
"cargo:rustc-env=OPENCONNECT_PROTOCOL_BUILD={}",
|
||||
oc_dst.join("build").display()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=OPENCONNECT_PROTOCOL_SOURCE={}",
|
||||
out_dir.join("openconnect_build").display()
|
||||
);
|
||||
|
||||
// Only statically link libxml2 if `LIBXML2_STATIC` is set
|
||||
if env::var("LIBXML2_STATIC").is_ok() {
|
||||
@@ -184,14 +176,20 @@ fn main() {
|
||||
|
||||
// Using pkg-config to find system deps
|
||||
pkg_config::probe_library("zlib").unwrap();
|
||||
pkg_config::probe_library("liblz4").unwrap();
|
||||
pkg_config::probe_library("gnutls").unwrap();
|
||||
#[cfg(target_os = "macos")]
|
||||
pkg_config::probe_library("openssl").unwrap();
|
||||
|
||||
// Below are required by gnutls
|
||||
pkg_config::probe_library("p11-kit-1").unwrap();
|
||||
pkg_config::probe_library("hogweed").unwrap();
|
||||
pkg_config::probe_library("nettle").unwrap();
|
||||
pkg_config::probe_library("gmp").unwrap();
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
pkg_config::probe_library("liblz4").unwrap();
|
||||
pkg_config::probe_library("gnutls").unwrap();
|
||||
|
||||
// Below are required by gnutls
|
||||
pkg_config::probe_library("p11-kit-1").unwrap();
|
||||
pkg_config::probe_library("hogweed").unwrap();
|
||||
pkg_config::probe_library("nettle").unwrap();
|
||||
pkg_config::probe_library("gmp").unwrap();
|
||||
}
|
||||
|
||||
// Compile the vpn.c file
|
||||
println!("cargo:rerun-if-changed=src/ffi/vpn.c");
|
||||
|
||||
Reference in new issue
Block a user