Skip to content

Commit 138a55f

Browse files
committed
skip auto download when SKIP_DOWNLOAD is set
this can be handy in nix environment where build script cannot hit the internet but dev-dependencies specify the auto download feature.
1 parent da48b10 commit 138a55f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ mod download {
7171
}
7272

7373
pub(crate) fn start() -> anyhow::Result<()> {
74+
if std::env::var_os("SKIP_DOWNLOAD").is_some() {
75+
return Ok(());
76+
}
7477
let download_filename = download_filename();
7578
let expected_hash = get_expected_sha256(&download_filename)?;
7679
let out_dir = std::env::var_os("OUT_DIR").unwrap();

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ pub enum Error {
123123
/// Returned when -rpcuser and/or -rpcpassword is used in `Conf` args
124124
/// It will soon be deprecated, please use -rpcauth instead
125125
RpcUserAndPasswordUsed,
126+
/// Returned when expecting an auto-downloaded executable but `SKIP_DOWNLOAD` env var is set
127+
SkipDownload,
126128
}
127129

128130
impl fmt::Debug for Error {
@@ -135,7 +137,8 @@ impl fmt::Debug for Error {
135137
Error::NoBitcoindExecutableFound => write!(f, "`bitcoind` executable is required, provide it with one of the following: set env var `BITCOIND_EXE` or use a feature like \"22_1\" or have `bitcoind` executable in the `PATH`"),
136138
Error::EarlyExit(e) => write!(f, "The bitcoind process terminated early with exit code {}", e),
137139
Error::BothDirsSpecified => write!(f, "tempdir and staticdir cannot be enabled at same time in configuration options"),
138-
Error::RpcUserAndPasswordUsed => write!(f, "`-rpcuser` and `-rpcpassword` cannot be used, it will be deprecated soon and it's recommended to use `-rpcauth` instead which works alongside with the default cookie authentication")
140+
Error::RpcUserAndPasswordUsed => write!(f, "`-rpcuser` and `-rpcpassword` cannot be used, it will be deprecated soon and it's recommended to use `-rpcauth` instead which works alongside with the default cookie authentication"),
141+
Error::SkipDownload => write!(f, "expecting an auto-downloaded executable but `SKIP_DOWNLOAD` env var is set"),
139142
}
140143
}
141144
}
@@ -496,6 +499,10 @@ pub fn downloaded_exe_path() -> anyhow::Result<String> {
496499
/// Provide the bitcoind executable path if a version feature has been specified
497500
#[cfg(feature = "download")]
498501
pub fn downloaded_exe_path() -> anyhow::Result<String> {
502+
if std::env::var_os("SKIP_DOWNLOAD").is_some() {
503+
return Err(Error::SkipDownload.into());
504+
}
505+
499506
let mut path: PathBuf = env!("OUT_DIR").into();
500507
path.push("bitcoin");
501508
path.push(format!("bitcoin-{}", versions::VERSION));

0 commit comments

Comments
 (0)