From d3e87c54e87327ddbd226881d7546ab7696bf683 Mon Sep 17 00:00:00 2001 From: Till Rohrmann Date: Tue, 11 Nov 2025 11:27:04 +0100 Subject: [PATCH 1/2] Let sasl2-sys use autotools to detect CC_ By using autotools to configure sasl2, we gain support for cross compilation because the tool chain is automatically retrieved from CC_. --- sasl2-sys/Cargo.toml | 1 + sasl2-sys/build.rs | 110 +++++++++++++++++++++---------------------- 2 files changed, 54 insertions(+), 57 deletions(-) diff --git a/sasl2-sys/Cargo.toml b/sasl2-sys/Cargo.toml index 9cc4397..2693ed7 100644 --- a/sasl2-sys/Cargo.toml +++ b/sasl2-sys/Cargo.toml @@ -26,6 +26,7 @@ openssl-sys = { version = "0.9.55", optional = true } version-sync = "0.9" [build-dependencies] +autotools = "0.2" cc = "1.0.50" duct = "0.13.3" pkg-config = { version = "0.3.17", optional = true } diff --git a/sasl2-sys/build.rs b/sasl2-sys/build.rs index 6d380c7..93ee584 100644 --- a/sasl2-sys/build.rs +++ b/sasl2-sys/build.rs @@ -67,13 +67,52 @@ fn build_sasl(metadata: &Metadata) { let install_dir = metadata.out_dir.join("install"); - let mut cppflags = env::var("CPPFLAGS").ok().unwrap_or_else(String::new); - let mut cflags = env::var("CFLAGS").ok().unwrap_or_else(String::new); + // Use autotools crate for configuration - it handles CC_ translation automatically + let mut config = autotools::Config::new(&src_dir); + + config + .enable_static() + .disable_shared() + .disable("sample", None) + .disable("checkapop", None) + .disable("cram", None) + .disable("scram", None) + .disable("digest", None) + .disable("otp", None) + .disable("anon", None) + .with("dblib", Some("none")) + .with("pic", None) + .insource(true); // Build in source since SASL doesn't support out-of-tree builds + + if cfg!(feature = "gssapi-vendored") { + config.enable("gssapi", Some(&env::var("DEP_KRB5_SRC_ROOT").unwrap())); + } else { + config.disable("gssapi", None); + } + + if cfg!(feature = "plain") { + config.enable("plain", None); + } else { + config.disable("plain", None); + } + + if cfg!(feature = "scram") { + config.enable("scram", None); + } else { + config.disable("scram", None); + } + + if metadata.target.contains("darwin") { + config.disable("macos-framework", None); + } // If OpenSSL has been vendored, point libsasl2 at the vendored headers. if cfg!(feature = "openssl-sys") { if let Ok(openssl_root) = env::var("DEP_OPENSSL_ROOT") { - cppflags += &format!(" -I{}", Path::new(&openssl_root).join("include").display()); + config.cflag(format!( + "-I{}", + Path::new(&openssl_root).join("include").display() + )); } } @@ -81,50 +120,12 @@ fn build_sasl(metadata: &Metadata) { // linking statically the sasl2 build system subverts libtool to almagamate // plugins into the main library archive, so we need to request PIC in // CFLAGS too. - cflags += " -fPIC"; - - let mut configure_args = vec![ - format!("--prefix={}", install_dir.display()), - "--enable-static".into(), - "--disable-shared".into(), - "--disable-sample".into(), - "--disable-checkapop".into(), - "--disable-cram".into(), - "--disable-scram".into(), - "--disable-digest".into(), - "--disable-otp".into(), - if cfg!(feature = "gssapi-vendored") { - format!("--enable-gssapi={}", env::var("DEP_KRB5_SRC_ROOT").unwrap()) - } else { - "--disable-gssapi".into() - }, - if cfg!(feature = "plain") { - "--enable-plain".into() - } else { - "--disable-plain".into() - }, - if cfg!(feature = "scram") { - "--enable-scram".into() - } else { - "--disable-scram".into() - }, - "--disable-anon".into(), - "--with-dblib=none".into(), - "--with-pic".into(), - format!("CPPFLAGS={}", cppflags), - format!("CFLAGS={}", cflags), - ]; - if metadata.target.contains("darwin") { - configure_args.push("--disable-macos-framework".into()); - } - if metadata.host != metadata.target { - configure_args.push(format!("--host={}", metadata.target)); - } - cmd(src_dir.join("configure"), &configure_args) - .dir(&src_dir) - .env_remove("CONFIG_SITE") - .run() - .expect("configure failed"); + config.cflag("-fPIC"); + + config.config_option("prefix", Some(install_dir.to_str().unwrap())); + + // Run configure only - this handles all the cross-compilation CC_ translation + let build_dir = config.configure(); let is_bsd = metadata.host.contains("dragonflybsd") || metadata.host.contains("freebsd") @@ -134,15 +135,12 @@ fn build_sasl(metadata: &Metadata) { let make = if is_bsd { "gmake" } else { "make" }; let mut make_flags = OsString::new(); - let mut make_args = vec![]; - if let Ok(s) = env::var("NUM_JOBS") { + if env::var("NUM_JOBS").is_ok() { match env::var_os("CARGO_MAKEFLAGS") { // Only do this on non-Windows, since on Windows we could be // invoking mingw32-make which doesn't work with the jobserver. Some(s) if !cfg!(windows) => make_flags = s, - - // Otherwise, let's hope it understands `-jN`. - _ => make_args.push(format!("-j{}", s)), + _ => {} } } @@ -151,7 +149,7 @@ fn build_sasl(metadata: &Metadata) { // on targets in `include` and `common`, so build those directories first. for sub_dir in &["include", "common", "lib"] { cmd!(make, "install") - .dir(src_dir.join(sub_dir)) + .dir(build_dir.join(sub_dir)) .env("MAKEFLAGS", &make_flags) .run() .expect("make failed"); @@ -320,14 +318,12 @@ fn find_sasl(metadata: &Metadata) { } for prefix in &[Path::new("/usr"), Path::new("/usr/local")] { - for lib_dir in vec![ - prefix.join("lib"), + for lib_dir in [prefix.join("lib"), prefix.join("lib64"), prefix.join("lib").join(&metadata.target), prefix .join("lib") - .join(&metadata.target.replace("unknown-linux-gnu", "linux-gnu")), - ] { + .join(metadata.target.replace("unknown-linux-gnu", "linux-gnu"))] { let include_dir = prefix.join("include"); if (lib_dir.join("libsasl2.a").exists() || lib_dir.join("libsasl2.so").exists() From 956c92e5e42e796ec1e863749045ac5a7c604696 Mon Sep 17 00:00:00 2001 From: Till Rohrmann Date: Thu, 13 Nov 2025 16:27:59 +0100 Subject: [PATCH 2/2] Disable tests when cross compiling When cross compiling we cannot run tests. Hence, setting ac_cv_gssapi_supports_spnego to yes to disable them. --- sasl2-sys/build.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sasl2-sys/build.rs b/sasl2-sys/build.rs index 93ee584..28f68da 100644 --- a/sasl2-sys/build.rs +++ b/sasl2-sys/build.rs @@ -84,6 +84,11 @@ fn build_sasl(metadata: &Metadata) { .with("pic", None) .insource(true); // Build in source since SASL doesn't support out-of-tree builds + if metadata.host != metadata.target { + // When cross compiling we cannot run the tests. Let's disable them in this case. + config.env("ac_cv_gssapi_supports_spnego", "yes"); + } + if cfg!(feature = "gssapi-vendored") { config.enable("gssapi", Some(&env::var("DEP_KRB5_SRC_ROOT").unwrap())); } else { @@ -318,12 +323,14 @@ fn find_sasl(metadata: &Metadata) { } for prefix in &[Path::new("/usr"), Path::new("/usr/local")] { - for lib_dir in [prefix.join("lib"), + for lib_dir in [ + prefix.join("lib"), prefix.join("lib64"), prefix.join("lib").join(&metadata.target), prefix .join("lib") - .join(metadata.target.replace("unknown-linux-gnu", "linux-gnu"))] { + .join(metadata.target.replace("unknown-linux-gnu", "linux-gnu")), + ] { let include_dir = prefix.join("include"); if (lib_dir.join("libsasl2.a").exists() || lib_dir.join("libsasl2.so").exists()