Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip auto download when BITCOIND_SKIP_DOWNLOAD is set #154

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ For reproducibility reasons, Nix build scripts cannot hit the internet, but the
auto-download feature does exactly that. To successfully build under Nix the
user must provide the tarball locally and specify its location via the
`BITCOIND_TARBALL_FILE` env var.

Another option is to specify the `BITCOIND_SKIP_DOWNLOAD` env var and provide the
executable via the `PATH`.

Alternatively, use the dep without auto-download feature.

## Used by
Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ mod download {
}

pub(crate) fn start() -> anyhow::Result<()> {
if std::env::var_os("BITCOIND_SKIP_DOWNLOAD").is_some() {
return Ok(());
}
let download_filename = download_filename();
let expected_hash = get_expected_sha256(&download_filename)?;
let out_dir = std::env::var_os("OUT_DIR").unwrap();
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ pub enum Error {
/// Returned when -rpcuser and/or -rpcpassword is used in `Conf` args
/// It will soon be deprecated, please use -rpcauth instead
RpcUserAndPasswordUsed,
/// Returned when expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set
SkipDownload,
}

impl fmt::Debug for Error {
Expand All @@ -135,7 +137,8 @@ impl fmt::Debug for Error {
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`"),
Error::EarlyExit(e) => write!(f, "The bitcoind process terminated early with exit code {}", e),
Error::BothDirsSpecified => write!(f, "tempdir and staticdir cannot be enabled at same time in configuration options"),
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")
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"),
Error::SkipDownload => write!(f, "expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set"),
}
}
}
Expand Down Expand Up @@ -496,6 +499,10 @@ pub fn downloaded_exe_path() -> anyhow::Result<String> {
/// Provide the bitcoind executable path if a version feature has been specified
#[cfg(feature = "download")]
pub fn downloaded_exe_path() -> anyhow::Result<String> {
if std::env::var_os("BITCOIND_SKIP_DOWNLOAD").is_some() {
return Err(Error::SkipDownload.into());
}

let mut path: PathBuf = env!("OUT_DIR").into();
path.push("bitcoin");
path.push(format!("bitcoin-{}", versions::VERSION));
Expand Down
Loading