Skip to content

Commit

Permalink
fix: build errors on custom bin target names (#1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI authored Oct 9, 2024
1 parent 9987854 commit 613f577
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
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

0 comments on commit 613f577

Please sign in to comment.