From 613f577a0dcdafb62e3fc76fcf1c2523256e7a95 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Thu, 10 Oct 2024 03:07:39 +0800 Subject: [PATCH] fix: build errors on custom bin target names (#1623) --- crates/build/src/build.rs | 2 +- crates/build/src/utils.rs | 31 +++---------------------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/crates/build/src/build.rs b/crates/build/src/build.rs index 4ecf7527aa..b19207d406 100644 --- a/crates/build/src/build.rs +++ b/crates/build/src/build.rs @@ -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) diff --git a/crates/build/src/utils.rs b/crates/build/src/utils.rs index ed61ffa594..ac5dd03c19 100644 --- a/crates/build/src/utils.rs +++ b/crates/build/src/utils.rs @@ -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 { - 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) @@ -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) }