From f8be7427c4c0c8bc059f2d611f4469b8eb6040e2 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Thu, 4 Apr 2024 09:55:29 +0200 Subject: [PATCH] skip download if ELECTRSD_SKIP_DOWNLOAD is set --- README.md | 4 ++++ build.rs | 4 ++++ src/lib.rs | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5efb9da..4c49da9 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,10 @@ if let Ok(exe_path) = electrsd::exe_path() { Startup options could be configured via the `Conf` struct using `electrsD::with_conf` or `electrsD::from_downloaded_with_conf`. +## Nix + +For determinisim, in nix you cannot hit the internet within the `build.rs`. Moreover, some downstream crates cannot remove the auto-download feature from their dev-deps. In this case you can set the `ELECTRSD_SKIP_DOWNLOAD` env var and provide the electrs executable in the `PATH` (or skip the test execution). + ## Issues with traditional approach I used integration testing based on external bash script launching needed external processes, there are many issues with this approach like: diff --git a/build.rs b/build.rs index b8a3a81..727a139 100644 --- a/build.rs +++ b/build.rs @@ -32,6 +32,10 @@ mod download { } pub fn download() { + if std::env::var_os("ELECTRSD_SKIP_DOWNLOAD").is_some() { + return; + } + if !HAS_FEATURE { return; } diff --git a/src/lib.rs b/src/lib.rs index 5892230..3a737b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -346,9 +346,9 @@ impl Drop for ElectrsD { } } -/// Provide the electrs executable path if a version feature has been specified +/// Provide the electrs executable path if a version feature has been specified and `ELECTRSD_SKIP_DOWNLOAD` is not set. pub fn downloaded_exe_path() -> Option { - if versions::HAS_FEATURE { + if versions::HAS_FEATURE && std::env::var_os("ELECTRSD_SKIP_DOWNLOAD").is_none() { Some(format!( "{}/electrs/{}/electrs", env!("OUT_DIR"),