@@ -475,6 +475,53 @@ fn build_wolfssl(wolfssl_src: &Path) -> PathBuf {
475475 conf. build ( )
476476}
477477
478+ /**
479+ * Export WolfSSL configuration to JSON for CI consumption
480+ */
481+ fn export_wolfssl_config ( config_contents : & str , out_dir : & Path ) -> std:: io:: Result < ( ) > {
482+ use std:: io:: Write ;
483+
484+ // Create a simple JSON structure with just the wolfssl configuration
485+ let config_file_path = out_dir. join ( "wolfssl_config.json" ) ;
486+ let mut config_file = File :: create ( & config_file_path) ?;
487+
488+ // Write the configuration as a simple JSON object
489+ writeln ! ( config_file, "{{" ) ?;
490+ writeln ! ( config_file, " \" wolfssl_configure_command\" : {:?}" , config_contents. trim( ) ) ?;
491+ writeln ! ( config_file, "}}" ) ?;
492+
493+ println ! ( "cargo::warning=WolfSSL config exported to: {}" , config_file_path. display( ) ) ;
494+
495+ // Also copy to target directory for Earthly/CI to pick up
496+ let target_dir = env:: var ( "CARGO_TARGET_DIR" ) . unwrap_or_else ( |_| {
497+ // If no CARGO_TARGET_DIR is set, we need to go up one level from wolfssl-sys to the workspace root
498+ "../target" . to_string ( )
499+ } ) ;
500+
501+ // Determine the build profile (debug or release)
502+ let profile = if cfg ! ( debug_assertions) { "debug" } else { "release" } ;
503+
504+ // For native builds, cargo puts artifacts directly in target/{profile}
505+ // For cross-compilation, it uses target/{target-triple}/{profile}
506+ // But we want to always put our config in target/{profile} for simplicity
507+ let target_config_path = PathBuf :: from ( & target_dir) . join ( & profile) . join ( "wolfssl_config.json" ) ;
508+
509+ // Create target directory if it doesn't exist
510+ if let Some ( parent) = target_config_path. parent ( ) {
511+ if let Err ( e) = fs:: create_dir_all ( parent) {
512+ println ! ( "cargo::warning=Failed to create directory {}: {}" , parent. display( ) , e) ;
513+ return Ok ( ( ) ) ;
514+ }
515+ }
516+
517+ match fs:: copy ( & config_file_path, & target_config_path) {
518+ Ok ( _) => println ! ( "cargo::warning=WolfSSL config also copied to: {}" , target_config_path. display( ) ) ,
519+ Err ( e) => println ! ( "cargo::warning=Failed to copy config to {}: {}" , target_config_path. display( ) , e) ,
520+ }
521+
522+ Ok ( ( ) )
523+ }
524+
478525fn main ( ) -> std:: io:: Result < ( ) > {
479526 // Get the build directory
480527 let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
@@ -492,6 +539,23 @@ fn main() -> std::io::Result<()> {
492539 // Configure and build WolfSSL
493540 let wolfssl_install_dir = build_wolfssl ( & wolfssl_src) ;
494541
542+ // Export config for CI consumption (Unix builds only, Windows uses MSBuild)
543+ if build_target:: target_os ( ) != build_target:: Os :: Windows {
544+ let mut config_path = PathBuf :: from ( & wolfssl_install_dir) ;
545+ config_path. push ( "build/configure.prev" ) ;
546+ if let Ok ( contents) = fs:: read_to_string ( config_path) {
547+ println ! ( "cargo::warning=WolfSSL config:{}" , contents) ;
548+ export_wolfssl_config ( & contents, & out_dir) ?;
549+ }
550+ } else {
551+ // For Windows builds, export the user_settings.h content as config
552+ let settings_path = wolfssl_install_dir. join ( "wolfssl" ) . join ( "user_settings.h" ) ;
553+ if let Ok ( contents) = fs:: read_to_string ( settings_path) {
554+ println ! ( "cargo::warning=WolfSSL Windows config (user_settings.h):{}" , contents) ;
555+ export_wolfssl_config ( & contents, & out_dir) ?;
556+ }
557+ }
558+
495559 // We want to block some macros as they are incorrectly creating duplicate values
496560 // https://github.com/rust-lang/rust-bindgen/issues/687
497561 // TODO: Reach out to tlspuffin and ask if we can incorporate this code and credit them
0 commit comments