MCPcopy Create free account
hub / github.com/BitVM/BitVM / copy_binary_to_elfs_folder

Function copy_binary_to_elfs_folder

header-chain/header-chain-guest/build.rs:111–203  ·  view source on GitHub ↗
(network: String)

Source from the content-addressed store, hash-verified

109}
110
111fn copy_binary_to_elfs_folder(network: String) {
112 let current_dir = env::current_dir().expect("Failed to get current dir");
113 // base_dir will be /home/ozan/workspace/BitVM/
114 let base_dir = current_dir
115 .join("../..")
116 .canonicalize()
117 .expect("Failed to canonicalize base_dir");
118
119 // Create elfs directory if it doesn't exist
120 let elfs_dir = base_dir.join("prover/elfs");
121 if !elfs_dir.exists() {
122 fs::create_dir_all(&elfs_dir).expect("Failed to create elfs directory");
123 println!("cargo:warning=Created elfs directory at {:?}", elfs_dir);
124 }
125
126 // Build source path (ensure this path is correct based on risc0_build's actual output location)
127 // This path assumes a specific structure relative to the workspace root.
128 // A more robust way might be to get this path from OUT_DIR if risc0_build places it there predictably.
129 let src_path = base_dir.join("target/riscv-guest/header-chain-circuit/header-chain-guest/riscv32im-risc0-zkvm-elf/docker/header-chain-guest.bin");
130
131 if !src_path.exists() {
132 // If the source ELF from the Docker build isn't found, the copy will fail.
133 // This could indicate an issue with the guest build itself or the path construction.
134 // The Docker build log (#8 and #9) suggests the ELF is built.
135 // RISC0 build scripts often place final ELFs in OUT_DIR/{method_name}.
136 // Consider using: let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
137 // let src_path = out_dir.join("header-chain-guest"); // or "header-chain-guest.elf" / ".bin"
138 println!(
139 "cargo:warning=Source binary not found at {:?}, skipping copy. This might be the root cause if copy fails.",
140 src_path
141 );
142 // It's important to ensure src_path is correct. For now, we assume it is based on your log.
143 // If the copy fails below, investigate src_path more deeply.
144 // return; // Or panic, as subsequent steps depend on this.
145 }
146
147 // Build destination path with network prefix
148 let dest_filename = format!("{}-header-chain-guest.bin", network.to_lowercase());
149 let dest_path = elfs_dir.join(&dest_filename); // This is an absolute PathBuf
150
151 // Copy the file
152 match fs::copy(&src_path, &dest_path) {
153 Ok(_) => println!(
154 "cargo:warning=Successfully copied binary from {:?} to {:?}",
155 src_path, dest_path
156 ),
157 Err(e) => {
158 // If the copy fails, the subsequent read will definitely fail.
159 // It's crucial to handle this, e.g., by panicking to stop the build with a clear message.
160 panic!(
161 "Failed to copy binary from {:?} to {:?}: {}. Subsequent ELF read will fail.",
162 src_path, dest_path, e
163 );
164 }
165 }
166
167 // The `elf_path` string below is used as a logical identifier or for constructing paths within the prover,
168 // but it should not be used directly for fs::read from the build script's CWD.

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected