1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use cmd_runner::{run_cmd_shell, run_cmd_shell_with_color, YellowStderr};
16 use std::{fs, path};
17 
18 use crate::CargoOptions;
19 
check_ukey2_ffi( root: &path::Path, cargo_options: &CargoOptions, ) -> anyhow::Result<()>20 pub(crate) fn check_ukey2_ffi(
21     root: &path::Path,
22     cargo_options: &CargoOptions,
23 ) -> anyhow::Result<()> {
24     log::info!("Checking Ukey2 ffi");
25     let ffi_dir = root.join("connections/ukey2/ukey2_c_ffi");
26 
27     let locked_arg = if cargo_options.locked { "--locked" } else { "" };
28 
29     // Default build, RustCrypto
30     run_cmd_shell(&ffi_dir, format!("cargo build {locked_arg} --quiet --release --lib"))?;
31     // BoringSSL
32     run_cmd_shell(
33         &ffi_dir,
34         format!("cargo build {locked_arg} --quiet --no-default-features --features=boringssl"),
35     )?;
36     run_cmd_shell(&ffi_dir, "cargo clippy --no-default-features --features=boringssl")?;
37 
38     // now run cmake build
39     let ffi_build_dir = ffi_dir.join("cpp/build");
40     fs::create_dir_all(&ffi_build_dir)?;
41     run_cmd_shell_with_color::<YellowStderr>(&ffi_build_dir, "cmake ..")?;
42     run_cmd_shell_with_color::<YellowStderr>(&ffi_build_dir, "cmake --build .")?;
43     run_cmd_shell_with_color::<YellowStderr>(&ffi_build_dir, "ctest")?;
44     Ok(())
45 }
46