Skip to content

Commit 7695a58

Browse files
billatarmtgonzalezorlandoarm
authored andcommitted
build: drop configuring external mbedtls
This also fixes a possible header mismatch, as the interface feature was wanting an external mbedtls header file to build against, but would generate the bindings and compile the shim library against the local vendored mbedtls. On an ABI change, things would have been broken. To fix this, and not require the vendored package, use the externally supplied mbedtls found through the env var or pkg-config. Signed-off-by: Bill Roberts <[email protected]>
1 parent d763203 commit 7695a58

File tree

1 file changed

+42
-44
lines changed

1 file changed

+42
-44
lines changed

psa-crypto-sys/build.rs

+42-44
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mod common {
6464

6565
use std::env;
6666
use std::io::{Error, ErrorKind, Result};
67-
use std::path::{Path, PathBuf};
67+
use std::path::PathBuf;
6868

6969
#[cfg(any(feature = "prefix", feature = "operations"))]
7070
pub fn get_external_mbedtls() -> Option<Result<(String, String)>> {
@@ -133,41 +133,6 @@ mod common {
133133
))
134134
}
135135

136-
pub fn configure_mbed_crypto() -> Result<()> {
137-
let mbedtls_dir = String::from("./vendor");
138-
let mbedtls_config = mbedtls_dir + "/scripts/config.py";
139-
140-
println!("cargo:rerun-if-changed=src/c/shim.c");
141-
println!("cargo:rerun-if-changed=src/c/shim.h");
142-
143-
let out_dir = env::var("OUT_DIR").unwrap();
144-
145-
// Check for Mbed TLS sources
146-
if !Path::new(&mbedtls_config).exists() {
147-
return Err(Error::new(
148-
ErrorKind::Other,
149-
"MbedTLS config.py is missing. Have you run 'git submodule update --init'?",
150-
));
151-
}
152-
153-
// Configure the MbedTLS build for making Mbed Crypto
154-
if !::std::process::Command::new(mbedtls_config)
155-
.arg("--write")
156-
.arg(&(out_dir + "/" + CONFIG_FILE))
157-
.arg("crypto")
158-
.status()
159-
.map_err(|_| Error::new(ErrorKind::Other, "configuring mbedtls failed"))?
160-
.success()
161-
{
162-
return Err(Error::new(
163-
ErrorKind::Other,
164-
"config.py returned an error status",
165-
));
166-
}
167-
168-
Ok(())
169-
}
170-
171136
#[cfg(feature = "prefix")]
172137
// Cargo provides the crate version from Cargo.toml in the environment.
173138
const VERSION: &str = env!("CARGO_PKG_VERSION");
@@ -282,10 +247,8 @@ mod interface {
282247
pub fn script_interface() -> Result<()> {
283248
let include_dir = common::get_external_mbedtls_include_only()?;
284249

285-
// TODO: Does interface need the vendored mbedtls?
286-
common::configure_mbed_crypto()?;
287-
common::generate_mbed_crypto_bindings(include_dir.clone(), false)?;
288-
let _ = common::compile_shim_library(include_dir, true, false)?;
250+
common::generate_mbed_crypto_bindings(include_dir.clone(), true)?;
251+
let _ = common::compile_shim_library(include_dir, true, true)?;
289252
Ok(())
290253
}
291254
}
@@ -297,12 +260,47 @@ mod operations {
297260
use super::common::prefix;
298261
use cmake::Config;
299262
use std::env;
300-
use std::io::Result;
301263
#[cfg(feature = "prefix")]
302264
use std::io::Write;
303-
use std::path::PathBuf;
265+
use std::io::{Error, ErrorKind, Result};
266+
use std::path::{Path, PathBuf};
304267
use walkdir::WalkDir;
305268

269+
pub fn configure_mbed_crypto() -> Result<()> {
270+
let mbedtls_dir = String::from("./vendor");
271+
let mbedtls_config = mbedtls_dir + "/scripts/config.py";
272+
273+
println!("cargo:rerun-if-changed=src/c/shim.c");
274+
println!("cargo:rerun-if-changed=src/c/shim.h");
275+
276+
let out_dir = env::var("OUT_DIR").unwrap();
277+
278+
// Check for Mbed TLS sources
279+
if !Path::new(&mbedtls_config).exists() {
280+
return Err(Error::new(
281+
ErrorKind::Other,
282+
"MbedTLS config.py is missing. Have you run 'git submodule update --init'?",
283+
));
284+
}
285+
286+
// Configure the MbedTLS build for making Mbed Crypto
287+
if !::std::process::Command::new(mbedtls_config)
288+
.arg("--write")
289+
.arg(&(out_dir + "/" + common::CONFIG_FILE))
290+
.arg("crypto")
291+
.status()
292+
.map_err(|_| Error::new(ErrorKind::Other, "configuring mbedtls failed"))?
293+
.success()
294+
{
295+
return Err(Error::new(
296+
ErrorKind::Other,
297+
"config.py returned an error status",
298+
));
299+
}
300+
301+
Ok(())
302+
}
303+
306304
fn compile_mbed_crypto() -> Result<PathBuf> {
307305
let mbedtls_dir = String::from("./vendor");
308306
let out_dir = env::var("OUT_DIR").unwrap();
@@ -360,7 +358,7 @@ mod operations {
360358
}
361359
None => {
362360
println!("Did not find external MBEDTLS, building MbedTLS!");
363-
common::configure_mbed_crypto()?;
361+
configure_mbed_crypto()?;
364362
let mut mbed_lib_dir = compile_mbed_crypto()?;
365363
let mut mbed_include_dir = mbed_lib_dir.clone();
366364
mbed_lib_dir.push("lib");
@@ -407,7 +405,7 @@ mod operations {
407405
}
408406
None => {
409407
println!("Did not find environment variables, building MbedTLS!");
410-
common::configure_mbed_crypto()?;
408+
configure_mbed_crypto()?;
411409
let mut mbed_lib_dir = compile_mbed_crypto()?;
412410
let mut mbed_include_dir = mbed_lib_dir.clone();
413411
mbed_lib_dir.push("lib");

0 commit comments

Comments
 (0)