Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: build errors on custom bin target names #1623

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/build/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn execute_build_program(
// Temporary backward compatibility with the deprecated behavior of copying the ELF file.
// TODO: add option to turn off this behavior
if target_elf_paths.len() == 1 {
copy_elf_to_output_dir(args, &program_metadata)?;
copy_elf_to_output_dir(args, &program_metadata, &target_elf_paths[0].1)?;
}

Ok(target_elf_paths)
Expand Down
31 changes: 3 additions & 28 deletions crates/build/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,14 @@ use anyhow::Result;
use cargo_metadata::{camino::Utf8PathBuf, Metadata};
use chrono::Local;

use crate::{BuildArgs, BUILD_TARGET, HELPER_TARGET_SUBDIR};
use crate::{BuildArgs, BUILD_TARGET};

/// Copy the ELF to the specified output directory.
pub(crate) fn copy_elf_to_output_dir(
args: &BuildArgs,
program_metadata: &cargo_metadata::Metadata,
elf_path: &Utf8PathBuf,
) -> Result<Utf8PathBuf> {
let root_package = program_metadata.root_package();
let root_package_name = root_package.as_ref().map(|p| &p.name);

// The ELF is written to a target folder specified by the program's package. If built with
// Docker, includes /docker after HELPER_TARGET_SUBDIR.
let target_dir_suffix = if args.docker {
format!("{}/{}", HELPER_TARGET_SUBDIR, "docker")
} else {
HELPER_TARGET_SUBDIR.to_string()
};

// The ELF's file name is the binary name if it's specified. Otherwise, it is the root package
// name.
let original_elf_file_name = if !args.binary.is_empty() {
args.binary.clone()
} else {
root_package_name.unwrap().clone()
};

let original_elf_path = program_metadata
.target_directory
.join(target_dir_suffix)
.join(BUILD_TARGET)
.join("release")
.join(original_elf_file_name);

// The order of precedence for the ELF name is:
// 1. --elf_name flag
// 2. --binary flag + -elf suffix (defaults to riscv32im-succinct-zkvm-elf)
Expand All @@ -55,7 +30,7 @@ pub(crate) fn copy_elf_to_output_dir(
let result_elf_path = elf_dir.join(elf_name);

// Copy the ELF to the specified output directory.
fs::copy(original_elf_path, &result_elf_path)?;
fs::copy(elf_path, &result_elf_path)?;

Ok(result_elf_path)
}
Expand Down
Loading