pub fn generate_elf_paths(
    metadata: &cargo_metadata::Metadata,
    args: Option<&BuildArgs>,
) -> Result<Vec<(String, Utf8PathBuf)>> {
    let mut target_elf_paths = vec![];
    let packages_to_iterate = if let Some(args) = args {
        if !args.packages.is_empty() {
            args.packages
                .iter()
                .map(|wanted_package| {
                    metadata
                        .packages
                        .iter()
                        .find(|p| p.name == *wanted_package)
                        .ok_or_else(|| {
                            anyhow::anyhow!("cannot find package named {}", wanted_package)
                        })
                        .map(|p| p.id.clone())
                })
                .collect::<anyhow::Result<Vec<_>>>()?
        } else {
            metadata.workspace_default_members.to_vec()
        }
    } else {
        metadata.workspace_default_members.to_vec()
    };

    for program_crate in packages_to_iterate {
        let program = metadata
            .packages
            .iter()
            .find(|p| p.id == program_crate)
            .ok_or_else(|| anyhow::anyhow!("cannot find package for {}", program_crate))?;

        for bin_target in program.targets.iter().filter(|t| {
            t.kind.contains(&"bin".to_owned()) && t.crate_types.contains(&"bin".to_owned())
        }) {
            // Filter out irrelevant targets if `--bin` is used.
            if let Some(args) = args {
                if !args.binaries.is_empty() && !args.binaries.contains(&bin_target.name) {
                    continue;
                }
            }

            let elf_path = metadata.target_directory.join(HELPER_TARGET_SUBDIR);
            let elf_path = match args {
                Some(args) if args.docker => elf_path.join("docker"),
                _ => elf_path,
            };
            let elf_path = elf_path.join(BUILD_TARGET).join("release").join(&bin_target.name);

            target_elf_paths.push((bin_target.name.to_owned(), elf_path));
        }
    }

    Ok(target_elf_paths)
}
Collects the list of targets that would be built and their output ELF file paths.
crates/build/src/build.rs