@@ -43,6 +43,7 @@ pub mod target {
4343 match ( target. architecture , target. operating_system ) {
4444 ( Architecture :: Arm ( _) , OperatingSystem :: Linux )
4545 | ( Architecture :: Aarch64 ( _) , OperatingSystem :: Linux )
46+ | ( Architecture :: Aarch64 ( _) , OperatingSystem :: Darwin )
4647 | ( Architecture :: X86_64 , OperatingSystem :: Darwin )
4748 | ( Architecture :: X86_64 , OperatingSystem :: Linux ) => { }
4849 ( arch, os) => {
@@ -77,15 +78,20 @@ pub mod tpm2_tss {
7778 }
7879
7980 impl Installation {
81+ /// Return an optional list of clang arguments that are platform specific
82+ #[ cfg( feature = "bundled" ) ]
8083 fn platform_args ( ) -> Option < Vec < String > > {
8184 cfg_if:: cfg_if! {
8285 if #[ cfg( windows) ] {
8386 let mut clang_args: Vec <String > = Vec :: new( ) ;
8487 let hklm = winreg:: RegKey :: predef( winreg:: enums:: HKEY_LOCAL_MACHINE ) ;
88+ // Find the windows sdk path from the windows registry
8589 let sdk_entry = hklm. open_subkey( "SOFTWARE\\ WOW6432Node\\ Microsoft\\ Microsoft SDKs\\ Windows\\ v10.0" ) . unwrap( ) ;
90+ // add relevant paths to get to the windows 10.0.17134.0 sdk, which tpm2-tss uses on windows.
8691 let installation_path: String = sdk_entry. get_value( "InstallationFolder" ) . unwrap( ) ;
8792 let ip_pb = PathBuf :: from( installation_path) . join( "Include" ) ;
8893 let windows_sdk = ip_pb. join( "10.0.17134.0" ) ;
94+ // Add paths required for bindgen to find all required headers
8995 clang_args. push( format!( "-I{}" , windows_sdk. join( "ucrt" ) . display( ) ) ) ;
9096 clang_args. push( format!( "-I{}" , windows_sdk. join( "um" ) . display( ) ) ) ;
9197 clang_args. push( format!( "-I{}" , windows_sdk. join( "shared" ) . display( ) ) ) ;
@@ -125,32 +131,56 @@ pub mod tpm2_tss {
125131 repo_path
126132 }
127133
128- #[ cfg( feature = "bundled" ) ]
134+ #[ cfg( all ( feature = "bundled" , not ( windows ) ) ) ]
129135 fn compile_with_autotools ( p : PathBuf ) -> PathBuf {
130136 let output1 = std:: process:: Command :: new ( "./bootstrap" )
131137 . current_dir ( & p)
132138 . output ( )
133139 . expect ( "bootstrap script failed" ) ;
134140 let status = output1. status ;
135141 if !status. success ( ) {
136- panic ! ( "bootstrap script failed with {}:\n {:?}" , status, output1) ;
142+ panic ! ( "{:?}/ bootstrap script failed with {}:\n {:?}" , p , status, output1) ;
137143 }
138144
139145 let mut config = autotools:: Config :: new ( p) ;
140- config. fast_build ( true ) . reconf ( "-ivf" ) . build ( )
146+ config
147+ // Force configuration of the autotools env
148+ . reconf ( "-fiv" )
149+ // skip ./configure if no parameter changes are made
150+ . fast_build ( true )
151+ . enable ( "esys" , None )
152+ // Disable fapi as we only use esys
153+ . disable ( "fapi" , None )
154+ . disable ( "fapi-async-tests" , None )
155+ // Disable integration tests
156+ . disable ( "integration" , None )
157+ // Don't allow weak crypto
158+ . disable ( "weakcrypto" , None )
159+ . build ( )
141160 }
142161
143162 #[ cfg( feature = "bundled" ) ]
144163 /// Uses a bundled build for an installation
145164 pub fn bundled ( ) -> Self {
146165 use std:: io:: Write ;
147166 let out_path = std:: env:: var ( "OUT_DIR" ) . expect ( "No output directory given" ) ;
148- let source_path = Self :: fetch_source (
149- out_path,
150- "tpm2-tss" ,
151- "https://github.com/tpm2-software/tpm2-tss.git" ,
152- MINIMUM_VERSION ,
153- ) ;
167+ let source_path = if let Ok ( tpm_tss_source) = std:: env:: var ( "TPM_TSS_SOURCE_PATH" ) {
168+ eprintln ! ( "using local tpm2-tss from {}" , tpm_tss_source) ;
169+ let Ok ( source_path) = PathBuf :: from ( tpm_tss_source) . canonicalize ( ) else {
170+ panic ! ( "Unable to canonicalize tpm2-tss source path. Does the source path exist?" ) ;
171+ } ;
172+
173+ source_path
174+ } else {
175+ eprintln ! ( "using remote tpm2-tss from https://github.com/tpm2-software/tpm2-tss.git" ) ;
176+ Self :: fetch_source (
177+ out_path,
178+ "tpm2-tss" ,
179+ "https://github.com/tpm2-software/tpm2-tss.git" ,
180+ MINIMUM_VERSION ,
181+ )
182+ } ;
183+
154184 let version_file_name = source_path. join ( "VERSION" ) ;
155185 let mut version_file = std:: fs:: File :: create ( version_file_name)
156186 . expect ( "Unable to create version file for tpm2-tss" ) ;
@@ -332,7 +362,7 @@ pub mod tpm2_tss {
332362 let build_string = match profile. as_str ( ) {
333363 "debug" => "Debug" ,
334364 "release" => "Release" ,
335- _ => panic ! ( "Unknown cargo profile:" ) ,
365+ _ => panic ! ( "Unknown cargo profile: {}" , profile ) ,
336366 } ;
337367 let mut source_path = self
338368 . tss2_esys
@@ -342,7 +372,6 @@ pub mod tpm2_tss {
342372 source_path. pop ( ) ;
343373 source_path. pop ( ) ;
344374 source_path. pop ( ) ;
345- println ! ( "Source path is {}" , source_path. display( ) ) ;
346375 println ! (
347376 "cargo:rustc-link-search=dylib={}" ,
348377 source_path. join( "x64" ) . join( build_string) . display( )
0 commit comments