fn compile(opt: &Opt, package: &str, target: &str) -> CVResult<(PathBuf, Vec<PathBuf>)> {
    let mut cmd = Command::new("cargo");
    cmd.arg("build").arg("--manifest-path").arg(&opt.cargo_toml);

    if !opt.features.is_empty() {
        cmd.arg("--features").arg(opt.features.join(","));
    }

    if opt.tests || !opt.test.is_empty() {
        cmd.arg("--tests");
    }
    if opt.no_default_features {
        cmd.arg("--no-default-features");
    }

    // The following line is not present because we care about the target It is
    // there to allow us to use -Clto to build crates whose dependencies invoke
    // proc_macros.
    // FIXME: "=="?
    cmd.arg(format!("--target={}", target))
        .args(vec!["-v"; opt.verbose.saturating_sub(1)])
        .envs(get_build_envs(&opt)?)
        .output_info(&opt, Verbosity::Normal)?;
    // .env("PATH", ...)

    // Find the target directory
    // (This may not be inside the crate if using workspaces)
    info_at!(&opt, Verbosity::Trivial, "  Getting target directory");
    let target_dir = get_meta_target_directory(&opt)?;

    // {target_dir}/{target}/debug/deps/{package}*.bc
    // where the file name has exactly one 1 '.' (because later we add similar
    // files, with multiple dots, and we don't want them here)
    // and the file has a main function.
    let bc_files = glob(
        &glob::Pattern::escape(
            target_dir
                .clone()
                .append(target)
                .append("debug")
                .append("deps")
                .append(package)
                .to_str()
                .ok_or("not UTF-8")?,
        )
        .append("*.bc"),
    )?
    .filter_map(Result::ok)
    // Filter only files that have exactly one '.'
    .filter(|p| {
        p.file_name()
            .map(|f| f.to_string_lossy().matches('.').count() == 1)
            .unwrap_or(false)
    })
    .filter(|p| count_symbols(&opt, p, &["main", "_main"]).map_or(false, |c| c > 0))
    .collect::<Vec<_>>();

    // Make sure there is only one such file.
    let bc_file: PathBuf = match bc_files.as_slice() {
        [_] => {
            // Move element 0 out of the Vec (and into `bcfile`).
            (bc_files as Vec<_>).remove(0)
        }
        [] => {
            if opt.tests || !opt.test.is_empty() {
                Err("  FAILED: Use --tests with library crates")?
            } else {
                Err(format!("  FAILED: Test {} unable to find the right bitcode file - should you have used --tests?", &package))?
            }
        }
        _ => {
            error!(
                "    Ambiguous bitcode files {}",
                bc_files
                    .iter()
                    .map(|p| p.to_string_lossy())
                    .collect::<Vec<_>>()
                    .join(", ")
            );
            Err(format!("  FAILED: Test {} compilation error", &package))?
        }
    };

    // {targetdir}/{target}/debug/build/ * /out/ *.o"
    let c_files = glob(
        &glob::Pattern::escape(
            target_dir
                .clone()
                .append(target)
                .append("debug")
                .append("build")
                .to_str()
                .ok_or("not UTF-8")?,
        )
        .append("/*/out/*.o"),
    )?
    .filter_map(Result::ok)
    .collect::<Vec<_>>();

    // build_plan = read_build_plan(crate, flags)
    // print(json.dumps(build_plan, indent=4, sort_keys=True))
    Ok((bc_file, c_files))
}
/// Compile a crate for verification.
/// Return a bcfile for the entire (linked) crate, and c object files that need
/// to be linked with the bcfile.
Compile a crate for verification.
Return a bcfile for the entire (linked) crate, and c object files that need
to be linked with the bcfile.
Compile a crate for verification . Return a bcfile for the entire ( linked ) crate and c object files that need to be linked with the bcfile .
fn compile(opt: &Opt, package: &str, target: &str) -> CVResult<(PathBuf, Vec<PathBuf>)> {
    let mut cmd = Command::new("cargo");
    cmd.arg("build").arg("--manifest-path").arg(&opt.cargo_toml);
    if !opt.features.is_empty() {
        cmd.arg("--features").arg(opt.features.join(","));
    }
    if opt.tests || !opt.test.is_empty() {
        cmd.arg("--tests");
    }
    if opt.no_default_features {
        cmd.arg("--no-default-features");
    }
    // The following line is not present because we care about the target It is
    // there to allow us to use -Clto to build crates whose dependencies invoke
    // proc_macros.
    // FIXME: "=="?
    cmd.arg(format!("--target={}", target))
        .args(vec!["-v"; opt.verbose.saturating_sub(1)])
        .envs(get_build_envs(&opt)?)
        .output_info(&opt, Verbosity::Normal)?;
    // .env("PATH", ...)
    // Find the target directory
    // (This may not be inside the crate if using workspaces)
    info_at!(&opt, Verbosity::Trivial, "  Getting target directory");
    let target_dir = get_meta_target_directory(&opt)?;
    // {target_dir}/{target}/debug/deps/{package}*.bc
    // where the file name has exactly one 1 '.' (because later we add similar
    // files, with multiple dots, and we don't want them here)
    // and the file has a main function.
    let bc_files = glob(
        &glob::Pattern::escape(
            target_dir
                .clone()
                .append(target)
                .append("debug")
                .append("deps")
                .append(package)
                .to_str()
                .ok_or("not UTF-8")?,
        )
        .append("*.bc"),
    )?
    .filter_map(Result::ok)
    // Filter only files that have exactly one '.'
    .filter(|p| {
        p.file_name()
            .map(|f| f.to_string_lossy().matches('.').count() == 1)
            .unwrap_or(false)
    })
    .filter(|p| count_symbols(&opt, p, &["main", "_main"]).map_or(false, |c| c > 0))
    .collect::<Vec<_>>();
    // Make sure there is only one such file.
    let bc_file: PathBuf = match bc_files.as_slice() {
        [_] => {
            // Move element 0 out of the Vec (and into `bcfile`).
            (bc_files as Vec<_>).remove(0)
        }
        [] => {
            if opt.tests || !opt.test.is_empty() {
                Err("  FAILED: Use --tests with library crates")?
            } else {
                Err(format!("  FAILED: Test {} unable to find the right bitcode file - should you have used --tests?", &package))?
            }
        }
        _ => {
            error!(
                "    Ambiguous bitcode files {}",
                bc_files
                    .iter()
                    .map(|p| p.to_string_lossy())
                    .collect::<Vec<_>>()
                    .join(", ")
            );
            Err(format!("  FAILED: Test {} compilation error", &package))?
        }
    };
    // {targetdir}/{target}/debug/build/ * /out/ *.o"
    let c_files = glob(
        &glob::Pattern::escape(
            target_dir
                .clone()
                .append(target)
                .append("debug")
                .append("build")
                .to_str()
                .ok_or("not UTF-8")?,
        )
        .append("/*/out/*.o"),
    )?
    .filter_map(Result::ok)
    .collect::<Vec<_>>();
    // build_plan = read_build_plan(crate, flags)
    // print(json.dumps(build_plan, indent=4, sort_keys=True))
    Ok((bc_file, c_files))
}
fn compile ( opt : & Opt , package : & str , target : & str ) -> CVResult < ( PathBuf , Vec < PathBuf > ) > { let mut cmd = Command :: new ( " " ) ; cmd . arg ( " " ) . arg ( " " ) . arg ( & opt . cargo_toml ) ; if ! opt . features . is_empty ( ) { cmd . arg ( " " ) . arg ( opt . features . join ( " " ) ) ; } if opt . tests || ! opt . test . is_empty ( ) { cmd . arg ( " " ) ; } if opt . no_default_features { cmd . arg ( " " ) ; } // The following line is not present because we care about the target It is // there to allow us to use -Clto to build crates whose dependencies invoke // proc_macros. // FIXME: "=="? cmd . arg ( format ! ( " " target ) ) . args ( vec ! [ " " opt verbose saturating_sub ( 1 ) ] ) . envs ( get_build_envs ( & opt ) ? ) . output_info ( & opt , Verbosity :: Normal ) ? ; // .env("PATH", ...) // Find the target directory // (This may not be inside the crate if using workspaces) info_at ! ( opt Verbosity Trivial " " ) ; let target_dir = get_meta_target_directory ( & opt ) ? ; // {target_dir}/{target}/debug/deps/{package}*.bc // where the file name has exactly one 1 '.' (because later we add similar // files, with multiple dots, and we don't want them here) // and the file has a main function. let bc_files = glob ( & glob :: Pattern :: escape ( target_dir . clone ( ) . append ( target ) . append ( " " ) . append ( " " ) . append ( package ) . to_str ( ) . ok_or ( " " ) ? , ) . append ( " " ) , ) ? . filter_map ( Result :: ok ) // Filter only files that have exactly one '.' . filter ( | p | { p . file_name ( ) . map ( | f | f . to_string_lossy ( ) . matches ( '.' ) . count ( ) == 1 ) . unwrap_or ( false ) } ) . filter ( | p | count_symbols ( & opt , p , & [ " " , " " ] ) . map_or ( false , | c | c > 0 ) ) . collect :: < Vec < _ > > ( ) ; // Make sure there is only one such file. let bc_file : PathBuf = match bc_files . as_slice ( ) { [ _ ] => { // Move element 0 out of the Vec (and into `bcfile`). ( bc_files as Vec < _ > ) . remove ( 0 ) } [ ] => { if opt . tests || ! opt . test . is_empty ( ) { Err ( " " ) ? } else { Err ( format ! ( " " package ) ) ? } } _ => { error ! ( " " bc_files iter ( ) map ( p p to_string_lossy ( ) ) collect Vec ( ) join ( " " ) ) ; Err ( format ! ( " " package ) ) ? } } ; // {targetdir}/{target}/debug/build/ * /out/ *.o" let c_files = glob ( & glob :: Pattern :: escape ( target_dir . clone ( ) . append ( target ) . append ( " " ) . append ( " " ) . to_str ( ) . ok_or ( " " ) ? , ) . append ( " " ) , ) ? . filter_map ( Result :: ok ) . collect :: < Vec < _ > > ( ) ; // build_plan = read_build_plan(crate, flags) // print(json.dumps(build_plan, indent=4, sort_keys=True)) Ok ( ( bc_file , c_files ) ) }
Compile a crate for verification.
Compile a crate for verification .
opt
&Opt
package
&str
target
&str
opt
&Opt
package
&str
target
&str