Skip to content

Commit 1fd697f

Browse files
committed
Merge #572: bitcoind: extract libexec/bitcoin-node and bin/bitcoin-cli alongside bitcoind
62f9f2b bitcoind: extract `libexec/bitcoin-node` and `bin/bitcoin-cli` alongside `bitcoind` (Толли) Pull request description: The build script previously extracted only `bin/bitcoind` from the downloaded tarball and discarded the rest. Downstream crates that need `bin/bitcoin-cli` or since v30 -the multiprocess `libexec/bitcoin-node` had to maintain their own download + unpack logic, defeating the point of corepc's auto-download. sv2-apps is one such crate: it carries a manual download + extract + macOS codesigning block specifically to get at `libexec/bitcoin-node` for `-ipcbind=unix`. This PR extends the extraction filter to pull `bin/bitcoind`, `bin/bitcoin-cli`, and (when feature `30_0`+ is enabled) `libexec/bitcoin-node` from the `.tar.gz`. The cache-completeness check and the macOS arm64 ad-hoc signing pass are updated to match. Closes #566 ## Tested - `cargo build --features "30_2 download"` from a clean cache: all three binaries on disk, all `codesign -v` pass, `bitcoin-node -regtest -ipcbind=unix` creates `regtest/node.sock`. - `cargo build --features "23_2 download"`: extracts `bitcoind` + `bitcoin-cli` only (no `libexec/bitcoin-node` in pre-v30 tarballs); rebuild cache-hits, no re-download loop. - Tarball layout verified identical across `bitcoin-30.2-x86_64-linux-gnu.tar.gz` and `bitcoin-30.2-arm64-apple-darwin.tar.gz`. ACKs for top commit: tcharding: ACK 62f9f2b Tree-SHA512: 51d7c9c83f90545da83b046f3c2b13e3c500ce113053e5450e2de7056578549e6551bf2f64bb40ba1613e2156ff02e168f364dd1c5500650defaec58a76ac891
2 parents 5aca05e + 62f9f2b commit 1fd697f

1 file changed

Lines changed: 42 additions & 22 deletions

File tree

bitcoind/build.rs

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,23 @@ mod download {
8484
std::fs::create_dir_all(&bitcoin_exe_home)
8585
.with_context(|| format!("cannot create dir {:?}", bitcoin_exe_home))?;
8686

87-
let mut existing_filename =
88-
bitcoin_exe_home.join(format!("bitcoin-{}", VERSION)).join("bin");
87+
let version_dir = bitcoin_exe_home.join(format!("bitcoin-{}", VERSION));
88+
let mut existing_filename = version_dir.join("bin");
8989
if cfg!(target_os = "windows") {
9090
existing_filename.push("bitcoind.exe");
9191
} else {
9292
existing_filename.push("bitcoind");
9393
}
9494

95-
if !existing_filename.exists() {
95+
#[cfg(not(target_os = "windows"))]
96+
let cache_complete = existing_filename.exists()
97+
&& version_dir.join("bin").join("bitcoin-cli").exists()
98+
&& (!cfg!(feature = "30_0")
99+
|| version_dir.join("libexec").join("bitcoin-node").exists());
100+
#[cfg(target_os = "windows")]
101+
let cache_complete = existing_filename.exists();
102+
103+
if !cache_complete {
96104
let download_filename = download_filename();
97105
println!("download_filename: {}", download_filename);
98106
let expected_hash = get_expected_sha256(&download_filename)?;
@@ -139,10 +147,15 @@ mod download {
139147
if download_filename.ends_with(".tar.gz") {
140148
let d = GzDecoder::new(&tarball_bytes[..]);
141149

150+
let targets: &[&Path] = &[
151+
Path::new("bin/bitcoind"),
152+
Path::new("bin/bitcoin-cli"),
153+
Path::new("libexec/bitcoin-node"),
154+
];
142155
let mut archive = Archive::new(d);
143156
for mut entry in archive.entries().unwrap().flatten() {
144157
if let Ok(file) = entry.path() {
145-
if file.ends_with("bitcoind") {
158+
if targets.iter().any(|t| file.ends_with(t)) {
146159
entry.unpack_in(&bitcoin_exe_home).unwrap();
147160
}
148161
}
@@ -175,24 +188,31 @@ mod download {
175188
{
176189
use std::process::Command;
177190

178-
let signing_status = Command::new("codesign")
179-
.arg("-v")
180-
.arg(&existing_filename)
181-
.status()
182-
.with_context(|| "failed to verify bitcoind code signature")?;
183-
184-
if !signing_status.success() {
185-
let status = Command::new("codesign")
186-
.arg("-s")
187-
.arg("-")
188-
.arg(&existing_filename)
189-
.status()
190-
.with_context(|| "failed to sign bitcoind")?;
191-
if !status.success() {
192-
return Err(anyhow::anyhow!(
193-
"codesign failed with exit code {}",
194-
status.code().unwrap_or(-1)
195-
));
191+
let to_sign = [
192+
version_dir.join("bin").join("bitcoind"),
193+
version_dir.join("bin").join("bitcoin-cli"),
194+
version_dir.join("libexec").join("bitcoin-node"),
195+
];
196+
for binary in to_sign.iter().filter(|p| p.exists()) {
197+
let signing_status =
198+
Command::new("codesign").arg("-v").arg(binary).status().with_context(
199+
|| format!("failed to verify code signature on {:?}", binary),
200+
)?;
201+
202+
if !signing_status.success() {
203+
let status = Command::new("codesign")
204+
.arg("-s")
205+
.arg("-")
206+
.arg(binary)
207+
.status()
208+
.with_context(|| format!("failed to sign {:?}", binary))?;
209+
if !status.success() {
210+
return Err(anyhow::anyhow!(
211+
"codesign failed for {:?} with exit code {}",
212+
binary,
213+
status.code().unwrap_or(-1)
214+
));
215+
}
196216
}
197217
}
198218
}

0 commit comments

Comments
 (0)