use std::env; use std::path::PathBuf; use cmake::Config; fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); // Build the IoT TCP Adapter Proxy C++ library let cpp_dst = Config::new("vendor/aws-iot-securetunneling-localproxy") .define("CMAKE_CXX_FLAGS", "-static") .define("BUILD_SHARED_LIBS", "OFF") .define("Boost_USE_STATIC_LIBS", "ON") .build_target("tcp_adapter_proxy") .out_dir(out_dir.join("cpp_build")) .build(); println!("cargo:rustc-link-search=native={}", cpp_dst.join("build").display()); println!("cargo:rustc-link-lib=static=tcp_adapter_proxy"); // Build the C wrapper library let wrapper_dst = Config::new("src/cpp") .define("CMAKE_C_FLAGS", "-static") .define("BUILD_SHARED_LIBS", "OFF") .build_target("tcp_adapter_proxy_wrapper") .out_dir(out_dir.join("wrapper_build")) .build(); println!("cargo:rustc-link-search=native={}", wrapper_dst.join("build").display()); println!("cargo:rustc-link-lib=static=tcp_adapter_proxy_wrapper"); // Link other required libraries println!("cargo:rustc-link-lib=static=stdc++"); println!("cargo:rustc-link-lib=static=ssl"); println!("cargo:rustc-link-lib=static=crypto"); // Boost libraries println!("cargo:rustc-link-lib=static=boost_system"); println!("cargo:rustc-link-lib=static=boost_log"); println!("cargo:rustc-link-lib=static=boost_thread"); println!("cargo:rustc-link-lib=static=boost_filesystem"); println!("cargo:rustc-link-lib=static=boost_regex"); println!("cargo:rustc-link-lib=static=boost_chrono"); println!("cargo:rustc-link-lib=static=boost_atomic"); println!("cargo:rustc-link-lib=static=protobuf-lite"); // Musl-specific static libraries println!("cargo:rustc-link-lib=static=c"); println!("cargo:rustc-link-lib=static=dl"); println!("cargo:rustc-link-lib=static=pthread"); // Set the path to search for libraries println!("cargo:rustc-link-search=native=/usr/local/lib"); println!("cargo:rustc-link-search=native=/usr/lib"); println!("cargo:rustc-link-search=native=/lib"); println!("cargo:rerun-if-changed=TcpAdapterProxyWrapper.h"); let bindings = bindgen::Builder::default() .header("src/cpp/TcpAdapterProxyWrapper.h") .generate() .expect("Unable to generate bindings"); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); // Rebuild if the wrapper changes println!("cargo:rerun-if-changed=src/cpp/TcpAdapterProxyWrapper.h"); // Force static linking of the C runtime println!("cargo:rustc-link-arg=-static"); println!("cargo:rustc-link-arg=-static-libgcc"); println!("cargo:rustc-link-arg=-no-pie"); }