@@ -43,6 +43,7 @@ pub mod target {
43
43
match ( target. architecture , target. operating_system ) {
44
44
( Architecture :: Arm ( _) , OperatingSystem :: Linux )
45
45
| ( Architecture :: Aarch64 ( _) , OperatingSystem :: Linux )
46
+ | ( Architecture :: Aarch64 ( _) , OperatingSystem :: Darwin )
46
47
| ( Architecture :: X86_64 , OperatingSystem :: Darwin )
47
48
| ( Architecture :: X86_64 , OperatingSystem :: Linux ) => { }
48
49
( arch, os) => {
@@ -77,15 +78,20 @@ pub mod tpm2_tss {
77
78
}
78
79
79
80
impl Installation {
81
+ /// Return an optional list of clang arguments that are platform specific
82
+ #[ cfg( feature = "bundled" ) ]
80
83
fn platform_args ( ) -> Option < Vec < String > > {
81
84
cfg_if:: cfg_if! {
82
85
if #[ cfg( windows) ] {
83
86
let mut clang_args: Vec <String > = Vec :: new( ) ;
84
87
let hklm = winreg:: RegKey :: predef( winreg:: enums:: HKEY_LOCAL_MACHINE ) ;
88
+ // Find the windows sdk path from the windows registry
85
89
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.
86
91
let installation_path: String = sdk_entry. get_value( "InstallationFolder" ) . unwrap( ) ;
87
92
let ip_pb = PathBuf :: from( installation_path) . join( "Include" ) ;
88
93
let windows_sdk = ip_pb. join( "10.0.17134.0" ) ;
94
+ // Add paths required for bindgen to find all required headers
89
95
clang_args. push( format!( "-I{}" , windows_sdk. join( "ucrt" ) . display( ) ) ) ;
90
96
clang_args. push( format!( "-I{}" , windows_sdk. join( "um" ) . display( ) ) ) ;
91
97
clang_args. push( format!( "-I{}" , windows_sdk. join( "shared" ) . display( ) ) ) ;
@@ -125,32 +131,63 @@ pub mod tpm2_tss {
125
131
repo_path
126
132
}
127
133
128
- #[ cfg( feature = "bundled" ) ]
134
+ #[ cfg( all ( feature = "bundled" , not ( windows ) ) ) ]
129
135
fn compile_with_autotools ( p : PathBuf ) -> PathBuf {
130
136
let output1 = std:: process:: Command :: new ( "./bootstrap" )
131
137
. current_dir ( & p)
132
138
. output ( )
133
139
. expect ( "bootstrap script failed" ) ;
134
140
let status = output1. status ;
135
141
if !status. success ( ) {
136
- panic ! ( "bootstrap script failed with {}:\n {:?}" , status, output1) ;
142
+ panic ! (
143
+ "{:?}/bootstrap script failed with {}:\n {:?}" ,
144
+ p, status, output1
145
+ ) ;
137
146
}
138
147
139
148
let mut config = autotools:: Config :: new ( p) ;
140
- config. fast_build ( true ) . reconf ( "-ivf" ) . build ( )
149
+ config
150
+ // Force configuration of the autotools env
151
+ . reconf ( "-fiv" )
152
+ // skip ./configure if no parameter changes are made
153
+ . fast_build ( true )
154
+ . enable ( "esys" , None )
155
+ // Disable fapi as we only use esys
156
+ . disable ( "fapi" , None )
157
+ . disable ( "fapi-async-tests" , None )
158
+ // Disable integration tests
159
+ . disable ( "integration" , None )
160
+ // Don't allow weak crypto
161
+ . disable ( "weakcrypto" , None )
162
+ . build ( )
141
163
}
142
164
143
165
#[ cfg( feature = "bundled" ) ]
144
166
/// Uses a bundled build for an installation
145
167
pub fn bundled ( ) -> Self {
146
168
use std:: io:: Write ;
147
169
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
- ) ;
170
+ let source_path = if let Ok ( tpm_tss_source) = std:: env:: var ( "TPM_TSS_SOURCE_PATH" ) {
171
+ eprintln ! ( "using local tpm2-tss from {}" , tpm_tss_source) ;
172
+ let Ok ( source_path) = PathBuf :: from ( tpm_tss_source) . canonicalize ( ) else {
173
+ panic ! (
174
+ "Unable to canonicalize tpm2-tss source path. Does the source path exist?"
175
+ ) ;
176
+ } ;
177
+
178
+ source_path
179
+ } else {
180
+ eprintln ! (
181
+ "using remote tpm2-tss from https://github.com/tpm2-software/tpm2-tss.git"
182
+ ) ;
183
+ Self :: fetch_source (
184
+ out_path,
185
+ "tpm2-tss" ,
186
+ "https://github.com/tpm2-software/tpm2-tss.git" ,
187
+ MINIMUM_VERSION ,
188
+ )
189
+ } ;
190
+
154
191
let version_file_name = source_path. join ( "VERSION" ) ;
155
192
let mut version_file = std:: fs:: File :: create ( version_file_name)
156
193
. expect ( "Unable to create version file for tpm2-tss" ) ;
@@ -298,11 +335,14 @@ pub mod tpm2_tss {
298
335
. clang_arg( tss2_tcti_tbs. include_dir_arg( ) )
299
336
. header( tss2_tcti_tbs. header_file_arg( ) ) ;
300
337
}
338
+
339
+ #[ cfg( feature = "bundled" ) ]
301
340
if let Some ( clang_args) = Self :: platform_args( ) {
302
341
for arg in clang_args {
303
342
builder = builder. clang_arg( arg) ;
304
343
}
305
344
}
345
+
306
346
builder
307
347
}
308
348
}
@@ -332,7 +372,7 @@ pub mod tpm2_tss {
332
372
let build_string = match profile. as_str ( ) {
333
373
"debug" => "Debug" ,
334
374
"release" => "Release" ,
335
- _ => panic ! ( "Unknown cargo profile:" ) ,
375
+ _ => panic ! ( "Unknown cargo profile: {}" , profile ) ,
336
376
} ;
337
377
let mut source_path = self
338
378
. tss2_esys
@@ -342,7 +382,6 @@ pub mod tpm2_tss {
342
382
source_path. pop ( ) ;
343
383
source_path. pop ( ) ;
344
384
source_path. pop ( ) ;
345
- println ! ( "Source path is {}" , source_path. display( ) ) ;
346
385
println ! (
347
386
"cargo:rustc-link-search=dylib={}" ,
348
387
source_path. join( "x64" ) . join( build_string) . display( )
0 commit comments