From 138a55fc7eb10caacbaad07fe92c1ab2209bf5a0 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 2 Apr 2024 11:07:51 +0200 Subject: [PATCH 1/3] 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. --- build.rs | 3 +++ src/lib.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index bc3992a..10a192f 100644 --- a/build.rs +++ b/build.rs @@ -71,6 +71,9 @@ mod download { } pub(crate) fn start() -> anyhow::Result<()> { + if std::env::var_os("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(); diff --git a/src/lib.rs b/src/lib.rs index f30f929..006f690 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 `SKIP_DOWNLOAD` env var is set + SkipDownload, } impl fmt::Debug for Error { @@ -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 `SKIP_DOWNLOAD` env var is set"), } } } @@ -496,6 +499,10 @@ pub fn downloaded_exe_path() -> anyhow::Result { /// Provide the bitcoind executable path if a version feature has been specified #[cfg(feature = "download")] pub fn downloaded_exe_path() -> anyhow::Result { + if std::env::var_os("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)); From a4c044ed20d4d186370a49476d2afb59939dd96f Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 2 Apr 2024 16:04:47 +0200 Subject: [PATCH 2/3] document SKIP_DOWNLOAD --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index df40e62..f0a52f9 100644 --- a/README.md +++ b/README.md @@ -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 `SKIP_DOWNLOAD` env var and provide the +executable via the `PATH`. + Alternatively, use the dep without auto-download feature. ## Used by From 0a35cb282fd54eeb4bb3be40656c24b5b717bb53 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Thu, 4 Apr 2024 09:02:08 +0200 Subject: [PATCH 3/3] rename SKIP_DOWNLOAD -> BITCOIND_SKIP_DOWNLOAD --- README.md | 2 +- build.rs | 2 +- src/lib.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f0a52f9..1fbc393 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ 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 `SKIP_DOWNLOAD` env var and provide the +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. diff --git a/build.rs b/build.rs index 10a192f..7db3cb5 100644 --- a/build.rs +++ b/build.rs @@ -71,7 +71,7 @@ mod download { } pub(crate) fn start() -> anyhow::Result<()> { - if std::env::var_os("SKIP_DOWNLOAD").is_some() { + if std::env::var_os("BITCOIND_SKIP_DOWNLOAD").is_some() { return Ok(()); } let download_filename = download_filename(); diff --git a/src/lib.rs b/src/lib.rs index 006f690..fe075cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,7 +123,7 @@ 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 `SKIP_DOWNLOAD` env var is set + /// Returned when expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set SkipDownload, } @@ -138,7 +138,7 @@ impl fmt::Debug for Error { 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::SkipDownload => write!(f, "expecting an auto-downloaded executable but `SKIP_DOWNLOAD` env var is set"), + Error::SkipDownload => write!(f, "expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set"), } } } @@ -499,7 +499,7 @@ pub fn downloaded_exe_path() -> anyhow::Result { /// Provide the bitcoind executable path if a version feature has been specified #[cfg(feature = "download")] pub fn downloaded_exe_path() -> anyhow::Result { - if std::env::var_os("SKIP_DOWNLOAD").is_some() { + if std::env::var_os("BITCOIND_SKIP_DOWNLOAD").is_some() { return Err(Error::SkipDownload.into()); }