Skip to content

Commit 5267573

Browse files
committed
Merge #453: [node] Fix: Allow compilation for all target os/arch
2f36579 [node] Fix: Allow compilation for all target os/arch (志宇) Pull request description: Previously, if the target os/arch had no match, `download_filename` method would not exist, leading to compilation error. Now, if the target os/arch has no match, and a download is required, we panic instead. This change allows the user can set `BITCOIND_EXE` to skip the download step (without a compile error on OSes where the binary is not hosted on `bitcoincore.org`). ### Rationale Bitcoin Core can be compiled for other OSes such as BSD and Android. It's just that these binaries are not hosted on [bitcoincore.org](bitcoincore.org). A compile error based on whether the binaries are hosted on that domain does not make sense. ### Testing I haven't tested this on OSX, Linux or Windows. I was hoping the CLI can cover some of these before I get my laptop replaced. ACKs for top commit: jamillambert: ACK 2f36579 tcharding: ACK 2f36579 Tree-SHA512: 430a06156f0a9da2ed34b323f90dc2f6f88720065d4bedfba4bb123df5c066b1d017d2c507231b2c2b818ac0de8c203b47a170cf0bb35a62618c6279effccb61
2 parents 75c4c3e + 2f36579 commit 5267573

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

node/build.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,32 @@ mod download {
1919

2020
include!("src/versions.rs");
2121

22-
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
2322
fn download_filename() -> String {
24-
if cfg!(not(feature = "23_2")) {
25-
format!("bitcoin-{}-osx64.tar.gz", &VERSION)
26-
} else {
27-
format!("bitcoin-{}-x86_64-apple-darwin.tar.gz", &VERSION)
23+
if cfg!(all(target_os = "macos", target_arch = "x86_64")) {
24+
if cfg!(not(feature = "23_2")) {
25+
return format!("bitcoin-{}-osx64.tar.gz", &VERSION);
26+
}
27+
return format!("bitcoin-{}-x86_64-apple-darwin.tar.gz", &VERSION);
28+
}
29+
30+
if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
31+
return format!("bitcoin-{}-arm64-apple-darwin.tar.gz", &VERSION);
2832
}
29-
}
3033

31-
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
32-
fn download_filename() -> String { format!("bitcoin-{}-arm64-apple-darwin.tar.gz", &VERSION) }
34+
if cfg!(all(target_os = "linux", target_arch = "x86_64")) {
35+
return format!("bitcoin-{}-x86_64-linux-gnu.tar.gz", &VERSION);
36+
}
3337

34-
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
35-
fn download_filename() -> String { format!("bitcoin-{}-x86_64-linux-gnu.tar.gz", &VERSION) }
38+
if cfg!(all(target_os = "linux", target_arch = "aarch64")) {
39+
return format!("bitcoin-{}-aarch64-linux-gnu.tar.gz", &VERSION);
40+
}
3641

37-
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
38-
fn download_filename() -> String { format!("bitcoin-{}-aarch64-linux-gnu.tar.gz", &VERSION) }
42+
if cfg!(all(target_os = "windows", target_arch = "x86_64")) {
43+
return format!("bitcoin-{}-win64.zip", &VERSION);
44+
}
3945

40-
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
41-
fn download_filename() -> String { format!("bitcoin-{}-win64.zip", &VERSION) }
46+
panic!("No download file for this os/arch");
47+
}
4248

4349
#[allow(clippy::lines_filter_map_ok)] // clippy doesn't like the `lines` call below and the suggested fix is incorrect.
4450
fn get_expected_sha256(filename: &str) -> anyhow::Result<sha256::Hash> {
@@ -72,9 +78,6 @@ mod download {
7278
if std::env::var_os("BITCOIND_SKIP_DOWNLOAD").is_some() {
7379
return Ok(());
7480
}
75-
let download_filename = download_filename();
76-
println!("download_filename: {}", download_filename);
77-
let expected_hash = get_expected_sha256(&download_filename)?;
7881
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
7982

8083
let bitcoin_exe_home = download_dir(&out_dir);
@@ -90,6 +93,10 @@ mod download {
9093
}
9194

9295
if !existing_filename.exists() {
96+
let download_filename = download_filename();
97+
println!("download_filename: {}", download_filename);
98+
let expected_hash = get_expected_sha256(&download_filename)?;
99+
93100
println!("filename:{} version:{} hash:{}", download_filename, VERSION, expected_hash);
94101

95102
let (file_or_url, tarball_bytes) = match std::env::var("BITCOIND_TARBALL_FILE") {

0 commit comments

Comments
 (0)