From b10315bf39b9af9d18d20e6e53c912ae64361d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 27 Aug 2025 13:22:13 +0100 Subject: [PATCH 1/4] purge any temp databases on build --- Cargo.lock | 6 +++++ .../client-core/gateways-storage/Cargo.toml | 1 + common/client-core/gateways-storage/build.rs | 18 ++++++++++--- common/client-core/surb-storage/Cargo.toml | 1 + common/client-core/surb-storage/build.rs | 12 ++++++--- common/credential-storage/Cargo.toml | 1 + common/credential-storage/build.rs | 17 ++++++++++--- common/gateway-stats-storage/Cargo.toml | 1 + common/gateway-stats-storage/build.rs | 17 ++++++++++--- common/gateway-storage/Cargo.toml | 1 + common/gateway-storage/build.rs | 17 ++++++++++--- common/nyxd-scraper/Cargo.toml | 1 + common/nyxd-scraper/build.rs | 18 ++++++++++--- nym-api/build.rs | 25 +++++++++++-------- .../nym-credential-proxy/Cargo.toml | 1 + .../nym-credential-proxy/build.rs | 17 ++++++++++--- .../nym-node-status-api/build.rs | 8 +++++- nym-validator-rewarder/Cargo.toml | 1 + nym-validator-rewarder/build.rs | 15 +++++------ tools/internal/testnet-manager/Cargo.toml | 1 + tools/internal/testnet-manager/build.rs | 17 ++++++++++--- 21 files changed, 146 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7c2db6de8a2..47d8662fc1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5211,6 +5211,7 @@ dependencies = [ name = "nym-client-core-gateways-storage" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "cosmrs", "nym-crypto", @@ -5229,6 +5230,7 @@ dependencies = [ name = "nym-client-core-surb-storage" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "dashmap", "nym-crypto", @@ -5439,6 +5441,7 @@ dependencies = [ name = "nym-credential-storage" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "bincode", "log", @@ -5807,6 +5810,7 @@ dependencies = [ name = "nym-gateway-stats-storage" version = "0.1.0" dependencies = [ + "anyhow", "nym-node-metrics", "nym-sphinx", "nym-statistics-common", @@ -5822,6 +5826,7 @@ dependencies = [ name = "nym-gateway-storage" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "bincode", "defguard_wireguard_rs", @@ -7390,6 +7395,7 @@ dependencies = [ name = "nyxd-scraper" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "const_format", "cosmrs", diff --git a/common/client-core/gateways-storage/Cargo.toml b/common/client-core/gateways-storage/Cargo.toml index ef2a1b5fdf7..d1dfe2b7f84 100644 --- a/common/client-core/gateways-storage/Cargo.toml +++ b/common/client-core/gateways-storage/Cargo.toml @@ -26,6 +26,7 @@ features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate", "time"] optional = true [build-dependencies] +anyhow = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } sqlx = { workspace = true, features = [ "runtime-tokio-rustls", diff --git a/common/client-core/gateways-storage/build.rs b/common/client-core/gateways-storage/build.rs index f8b85cbb4ae..bacc4853217 100644 --- a/common/client-core/gateways-storage/build.rs +++ b/common/client-core/gateways-storage/build.rs @@ -1,24 +1,32 @@ // Copyright 2022 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use anyhow::Context; + #[tokio::main] -async fn main() { +async fn main() -> anyhow::Result<()> { #[cfg(feature = "fs-gateways-storage")] { use sqlx::{Connection, SqliteConnection}; use std::env; - let out_dir = env::var("OUT_DIR").unwrap(); + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/gateways-storage-example.sqlite"); + // remove the db file if it already existed from previous build + // in case it was from a different branch + if std::fs::exists(&database_path)? { + std::fs::remove_file(&database_path)?; + } + let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./fs_gateways_migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; #[cfg(target_family = "unix")] println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); @@ -28,4 +36,6 @@ async fn main() { // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); } + + Ok(()) } diff --git a/common/client-core/surb-storage/Cargo.toml b/common/client-core/surb-storage/Cargo.toml index 551bfb74ecd..be03487d955 100644 --- a/common/client-core/surb-storage/Cargo.toml +++ b/common/client-core/surb-storage/Cargo.toml @@ -30,6 +30,7 @@ optional = true path = "../../../sqlx-pool-guard" [build-dependencies] +anyhow = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } sqlx = { workspace = true, features = [ "runtime-tokio-rustls", diff --git a/common/client-core/surb-storage/build.rs b/common/client-core/surb-storage/build.rs index 62c02c39685..5cdde74c4ce 100644 --- a/common/client-core/surb-storage/build.rs +++ b/common/client-core/surb-storage/build.rs @@ -1,24 +1,26 @@ // Copyright 2022 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use anyhow::Context; + #[tokio::main] -async fn main() { +async fn main() -> anyhow::Result<()> { #[cfg(feature = "fs-surb-storage")] { use sqlx::{Connection, SqliteConnection}; use std::env; - let out_dir = env::var("OUT_DIR").unwrap(); + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/fs-surbs-example.sqlite"); let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./fs_surbs_migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; #[cfg(target_family = "unix")] println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); @@ -28,4 +30,6 @@ async fn main() { // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); } + + Ok(()) } diff --git a/common/credential-storage/Cargo.toml b/common/credential-storage/Cargo.toml index aa9b6158054..54c8a2fcd0c 100644 --- a/common/credential-storage/Cargo.toml +++ b/common/credential-storage/Cargo.toml @@ -33,6 +33,7 @@ features = ["rt-multi-thread", "net", "signal", "fs"] [build-dependencies] +anyhow = { workspace = true } sqlx = { workspace = true, features = [ "runtime-tokio-rustls", "sqlite", diff --git a/common/credential-storage/build.rs b/common/credential-storage/build.rs index 4716c65d0d4..cc713b8c6fc 100644 --- a/common/credential-storage/build.rs +++ b/common/credential-storage/build.rs @@ -3,22 +3,29 @@ * SPDX-License-Identifier: Apache-2.0 */ +use anyhow::Context; use sqlx::{Connection, SqliteConnection}; use std::env; #[tokio::main] -async fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); +async fn main() -> anyhow::Result<()> { + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/coconut-credential-example.sqlite"); + // remove the db file if it already existed from previous build + // in case it was from a different branch + if std::fs::exists(&database_path)? { + std::fs::remove_file(&database_path)?; + } + let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; #[cfg(target_family = "unix")] println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); @@ -27,4 +34,6 @@ async fn main() { // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); + + Ok(()) } diff --git a/common/gateway-stats-storage/Cargo.toml b/common/gateway-stats-storage/Cargo.toml index dc479e4cd2c..d9674fdfe3f 100644 --- a/common/gateway-stats-storage/Cargo.toml +++ b/common/gateway-stats-storage/Cargo.toml @@ -27,6 +27,7 @@ nym-statistics-common = { path = "../statistics" } [build-dependencies] +anyhow = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } sqlx = { workspace = true, features = [ "runtime-tokio-rustls", diff --git a/common/gateway-stats-storage/build.rs b/common/gateway-stats-storage/build.rs index cef40420c9c..6c665678e67 100644 --- a/common/gateway-stats-storage/build.rs +++ b/common/gateway-stats-storage/build.rs @@ -1,22 +1,29 @@ // Copyright 2024 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only +use anyhow::Context; use sqlx::{Connection, SqliteConnection}; use std::env; #[tokio::main] -async fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); +async fn main() -> anyhow::Result<()> { + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/gateway-stats-example.sqlite"); + // remove the db file if it already existed from previous build + // in case it was from a different branch + if std::fs::exists(&database_path)? { + std::fs::remove_file(&database_path)?; + } + let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; #[cfg(target_family = "unix")] println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); @@ -25,4 +32,6 @@ async fn main() { // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); + + Ok(()) } diff --git a/common/gateway-storage/Cargo.toml b/common/gateway-storage/Cargo.toml index 4ead02b9393..ab3dc0b86d5 100644 --- a/common/gateway-storage/Cargo.toml +++ b/common/gateway-storage/Cargo.toml @@ -31,6 +31,7 @@ nym-gateway-requests = { path = "../gateway-requests" } nym-sphinx = { path = "../nymsphinx" } [build-dependencies] +anyhow = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } sqlx = { workspace = true, features = [ "runtime-tokio-rustls", diff --git a/common/gateway-storage/build.rs b/common/gateway-storage/build.rs index 9b46e078408..bfdaf4fca99 100644 --- a/common/gateway-storage/build.rs +++ b/common/gateway-storage/build.rs @@ -1,22 +1,29 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only +use anyhow::Context; use sqlx::{Connection, SqliteConnection}; use std::env; #[tokio::main] -async fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); +async fn main() -> anyhow::Result<()> { + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/gateway-example.sqlite"); + // remove the db file if it already existed from previous build + // in case it was from a different branch + if std::fs::exists(&database_path)? { + std::fs::remove_file(&database_path)?; + } + let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; #[cfg(target_family = "unix")] println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); @@ -25,4 +32,6 @@ async fn main() { // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); + + Ok(()) } diff --git a/common/nyxd-scraper/Cargo.toml b/common/nyxd-scraper/Cargo.toml index 9eee598af78..4019c1dbd13 100644 --- a/common/nyxd-scraper/Cargo.toml +++ b/common/nyxd-scraper/Cargo.toml @@ -36,5 +36,6 @@ url.workspace = true [build-dependencies] +anyhow = { workspace = true } sqlx = { workspace = true, features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } diff --git a/common/nyxd-scraper/build.rs b/common/nyxd-scraper/build.rs index cfe3b9c079b..89a7681b987 100644 --- a/common/nyxd-scraper/build.rs +++ b/common/nyxd-scraper/build.rs @@ -1,22 +1,30 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use anyhow::Context; + #[tokio::main] -async fn main() { +async fn main() -> anyhow::Result<()> { use sqlx::{Connection, SqliteConnection}; use std::env; - let out_dir = env::var("OUT_DIR").unwrap(); + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/scraper-example.sqlite"); + // remove the db file if it already existed from previous build + // in case it was from a different branch + if std::fs::exists(&database_path)? { + std::fs::remove_file(&database_path)?; + } + let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./sql_migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; #[cfg(target_family = "unix")] println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); @@ -25,4 +33,6 @@ async fn main() { // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); + + Ok(()) } diff --git a/nym-api/build.rs b/nym-api/build.rs index 6bc476b72f6..09184d677d1 100644 --- a/nym-api/build.rs +++ b/nym-api/build.rs @@ -1,16 +1,20 @@ +use anyhow::Context; use sqlx::{Connection, FromRow, SqliteConnection}; use std::env; const SQLITE_DB_FILENAME: &str = "nym-api-example.sqlite"; -// it's fine if compilation fails -#[allow(clippy::unwrap_used)] -#[allow(clippy::expect_used)] #[tokio::main] -async fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); +async fn main() -> anyhow::Result<()> { + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/{SQLITE_DB_FILENAME}"); + // remove the db file if it already existed from previous build + // in case it was from a different branch + if std::fs::exists(&database_path)? { + std::fs::remove_file(&database_path)?; + } + #[cfg(target_family = "unix")] write_db_path_to_file(&out_dir, SQLITE_DB_FILENAME) .await @@ -18,12 +22,12 @@ async fn main() { let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; #[derive(FromRow)] struct Exists { @@ -33,8 +37,7 @@ async fn main() { // check if it was already run let res: Exists = sqlx::query_as("SELECT EXISTS (SELECT 1 FROM v3_migration_info) AS 'exists'") .fetch_one(&mut conn) - .await - .unwrap(); + .await?; let already_run = res.exists; @@ -58,7 +61,7 @@ async fn main() { ) .execute(&mut conn) .await - .expect("failed to update post v3 migration tables"); + .context("failed to update post v3 migration tables")?; } #[cfg(target_family = "unix")] @@ -68,6 +71,8 @@ async fn main() { // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); + + Ok(()) } /// use `./enter_db.sh` to inspect DB diff --git a/nym-credential-proxy/nym-credential-proxy/Cargo.toml b/nym-credential-proxy/nym-credential-proxy/Cargo.toml index 79077003844..10f847cdbb9 100644 --- a/nym-credential-proxy/nym-credential-proxy/Cargo.toml +++ b/nym-credential-proxy/nym-credential-proxy/Cargo.toml @@ -55,6 +55,7 @@ nym-credential-proxy-requests = { path = "../nym-credential-proxy-requests", fea tempfile = { workspace = true } [build-dependencies] +anyhow = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } sqlx = { workspace = true, features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate"] } diff --git a/nym-credential-proxy/nym-credential-proxy/build.rs b/nym-credential-proxy/nym-credential-proxy/build.rs index bdbdcf0d221..bedf911da77 100644 --- a/nym-credential-proxy/nym-credential-proxy/build.rs +++ b/nym-credential-proxy/nym-credential-proxy/build.rs @@ -1,22 +1,31 @@ // Copyright 2024 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only +use anyhow::Context; + #[tokio::main] -async fn main() { +async fn main() -> anyhow::Result<()> { use sqlx::{Connection, SqliteConnection}; use std::env; - let out_dir = env::var("OUT_DIR").unwrap(); + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/nym-credential-proxy-example.sqlite"); + // remove the db file if it already existed from previous build + // in case it was from a different branch + if std::fs::exists(&database_path)? { + std::fs::remove_file(&database_path)?; + } + let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); + Ok(()) } diff --git a/nym-node-status-api/nym-node-status-api/build.rs b/nym-node-status-api/nym-node-status-api/build.rs index a3b6635aef7..dc7b9b708e4 100644 --- a/nym-node-status-api/nym-node-status-api/build.rs +++ b/nym-node-status-api/nym-node-status-api/build.rs @@ -18,6 +18,12 @@ async fn init_db() -> Result<()> { let out_dir = read_env_var("OUT_DIR")?; let database_path = format!("{out_dir}/{SQLITE_DB_FILENAME}?mode=rwc"); + // remove the db file if it already existed from previous build + // in case it was from a different branch + if std::fs::exists(&database_path)? { + std::fs::remove_file(&database_path)?; + } + write_db_path_to_file(&out_dir, SQLITE_DB_FILENAME).await?; let mut conn = SqliteConnection::connect(&database_path).await?; sqlx::migrate!("./migrations").run(&mut conn).await?; @@ -44,7 +50,7 @@ async fn main() -> Result<()> { #[cfg(feature = "sqlite")] fn read_env_var(var: &str) -> Result { - std::env::var(var).map_err(|_| anyhow::anyhow!("You need to set {} env var", var)) + std::env::var(var).map_err(|_| anyhow::anyhow!("You need to set {var} env var")) } /// use `./enter_db.sh` to inspect DB diff --git a/nym-validator-rewarder/Cargo.toml b/nym-validator-rewarder/Cargo.toml index 3281e9f7823..65e2781fd1c 100644 --- a/nym-validator-rewarder/Cargo.toml +++ b/nym-validator-rewarder/Cargo.toml @@ -49,6 +49,7 @@ nym-serde-helpers = { path = "../common/serde-helpers", features = ["base64"] } nym-pemstore = { path = "../common/pemstore" } [build-dependencies] +anyhow = { workspace = true } sqlx = { workspace = true, features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } diff --git a/nym-validator-rewarder/build.rs b/nym-validator-rewarder/build.rs index 545f9c66b66..fbb510e0956 100644 --- a/nym-validator-rewarder/build.rs +++ b/nym-validator-rewarder/build.rs @@ -1,25 +1,24 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only -// it's fine if compilation fails -#[allow(clippy::unwrap_used)] -#[allow(clippy::expect_used)] +use anyhow::Context; + #[tokio::main] -async fn main() { +async fn main() -> anyhow::Result<()> { use sqlx::{Connection, SqliteConnection}; use std::env; - let out_dir = env::var("OUT_DIR").unwrap(); + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/scraper-example.sqlite"); let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; #[cfg(target_family = "unix")] println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); @@ -28,4 +27,6 @@ async fn main() { // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); + + Ok(()) } diff --git a/tools/internal/testnet-manager/Cargo.toml b/tools/internal/testnet-manager/Cargo.toml index e1a32ec685f..c1d3f37a660 100644 --- a/tools/internal/testnet-manager/Cargo.toml +++ b/tools/internal/testnet-manager/Cargo.toml @@ -51,5 +51,6 @@ nym-pemstore = { path = "../../../common/pemstore" } [build-dependencies] +anyhow = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } sqlx = { workspace = true, features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate"] } diff --git a/tools/internal/testnet-manager/build.rs b/tools/internal/testnet-manager/build.rs index 7e969e1e088..be394b3c41e 100644 --- a/tools/internal/testnet-manager/build.rs +++ b/tools/internal/testnet-manager/build.rs @@ -1,19 +1,26 @@ +use anyhow::Context; use sqlx::{Connection, SqliteConnection}; use std::env; #[tokio::main] -async fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); +async fn main() -> anyhow::Result<()> { + let out_dir = env::var("OUT_DIR")?; let database_path = format!("{out_dir}/nym-api-example.sqlite"); + // remove the db file if it already existed from previous build + // in case it was from a different branch + if std::fs::exists(&database_path)? { + std::fs::remove_file(&database_path)?; + } + let mut conn = SqliteConnection::connect(&format!("sqlite://{database_path}?mode=rwc")) .await - .expect("Failed to create SQLx database connection"); + .context("Failed to create SQLx database connection")?; sqlx::migrate!("./migrations") .run(&mut conn) .await - .expect("Failed to perform SQLx migrations"); + .context("Failed to perform SQLx migrations")?; #[cfg(target_family = "unix")] println!("cargo:rustc-env=DATABASE_URL=sqlite://{}", &database_path); @@ -22,4 +29,6 @@ async fn main() { // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); + + Ok(()) } From e27a3e6e7fd53b608309b5ee6650c39be12a93c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 27 Aug 2025 13:25:48 +0100 Subject: [PATCH 2/4] updated min rust version --- Cargo.toml | 2 +- common/client-core/gateways-storage/Cargo.toml | 1 + common/credential-storage/Cargo.toml | 1 + common/gateway-stats-storage/Cargo.toml | 1 + common/gateway-storage/Cargo.toml | 1 + common/nyxd-scraper/Cargo.toml | 1 + nym-credential-proxy/nym-credential-proxy/Cargo.toml | 1 + tools/internal/testnet-manager/Cargo.toml | 1 + 8 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6cf7625af6e..bc43d39aac9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -178,7 +178,7 @@ homepage = "https://nymtech.net" documentation = "https://nymtech.net" edition = "2021" license = "Apache-2.0" -rust-version = "1.80" +rust-version = "1.81" readme = "README.md" [workspace.dependencies] diff --git a/common/client-core/gateways-storage/Cargo.toml b/common/client-core/gateways-storage/Cargo.toml index d1dfe2b7f84..938a6db5dc3 100644 --- a/common/client-core/gateways-storage/Cargo.toml +++ b/common/client-core/gateways-storage/Cargo.toml @@ -3,6 +3,7 @@ name = "nym-client-core-gateways-storage" version = "0.1.0" edition = "2021" license.workspace = true +rust-version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/common/credential-storage/Cargo.toml b/common/credential-storage/Cargo.toml index 54c8a2fcd0c..9220c21b1cd 100644 --- a/common/credential-storage/Cargo.toml +++ b/common/credential-storage/Cargo.toml @@ -3,6 +3,7 @@ name = "nym-credential-storage" version = "0.1.0" edition = "2021" license.workspace = true +rust-version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/common/gateway-stats-storage/Cargo.toml b/common/gateway-stats-storage/Cargo.toml index d9674fdfe3f..e958e255260 100644 --- a/common/gateway-stats-storage/Cargo.toml +++ b/common/gateway-stats-storage/Cargo.toml @@ -7,6 +7,7 @@ homepage.workspace = true documentation.workspace = true edition.workspace = true license.workspace = true +rust-version.workspace = true [dependencies] sqlx = { workspace = true, features = [ diff --git a/common/gateway-storage/Cargo.toml b/common/gateway-storage/Cargo.toml index ab3dc0b86d5..c7878511be6 100644 --- a/common/gateway-storage/Cargo.toml +++ b/common/gateway-storage/Cargo.toml @@ -7,6 +7,7 @@ homepage.workspace = true documentation.workspace = true edition.workspace = true license.workspace = true +rust-version.workspace = true [dependencies] async-trait = { workspace = true } diff --git a/common/nyxd-scraper/Cargo.toml b/common/nyxd-scraper/Cargo.toml index 4019c1dbd13..025e906d56e 100644 --- a/common/nyxd-scraper/Cargo.toml +++ b/common/nyxd-scraper/Cargo.toml @@ -7,6 +7,7 @@ homepage.workspace = true documentation.workspace = true edition.workspace = true license.workspace = true +rust-version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/nym-credential-proxy/nym-credential-proxy/Cargo.toml b/nym-credential-proxy/nym-credential-proxy/Cargo.toml index 10f847cdbb9..ab63943d701 100644 --- a/nym-credential-proxy/nym-credential-proxy/Cargo.toml +++ b/nym-credential-proxy/nym-credential-proxy/Cargo.toml @@ -7,6 +7,7 @@ homepage.workspace = true documentation.workspace = true edition.workspace = true license.workspace = true +rust-version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/internal/testnet-manager/Cargo.toml b/tools/internal/testnet-manager/Cargo.toml index c1d3f37a660..bea71e6d01e 100644 --- a/tools/internal/testnet-manager/Cargo.toml +++ b/tools/internal/testnet-manager/Cargo.toml @@ -7,6 +7,7 @@ homepage.workspace = true documentation.workspace = true edition.workspace = true license.workspace = true +rust-version.workspace = true [dependencies] anyhow.workspace = true From 5bc4c6c95a8f527847a97ee1443ee3d58c404caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 27 Aug 2025 13:34:32 +0100 Subject: [PATCH 3/4] fixed clippy::manual_abs_diff' in verloc due to updated msrv --- common/verloc/src/models.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/common/verloc/src/models.rs b/common/verloc/src/models.rs index 0bedab812c3..970fc507b5c 100644 --- a/common/verloc/src/models.rs +++ b/common/verloc/src/models.rs @@ -130,12 +130,7 @@ impl VerlocMeasurement { let variance_micros = data .iter() .map(|&value| { - // make sure we don't underflow - let diff = if mean > value { - mean - value - } else { - value - mean - }; + let diff = mean.abs_diff(value); // we don't need nanos precision let diff_micros = diff.as_micros(); diff_micros * diff_micros From d7f489109ecb670394f99d56be27722923e16f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 27 Aug 2025 14:55:52 +0100 Subject: [PATCH 4/4] wasm --- common/client-core/gateways-storage/build.rs | 3 +-- common/client-core/surb-storage/build.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/common/client-core/gateways-storage/build.rs b/common/client-core/gateways-storage/build.rs index bacc4853217..e8fc127e07f 100644 --- a/common/client-core/gateways-storage/build.rs +++ b/common/client-core/gateways-storage/build.rs @@ -1,12 +1,11 @@ // Copyright 2022 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use anyhow::Context; - #[tokio::main] async fn main() -> anyhow::Result<()> { #[cfg(feature = "fs-gateways-storage")] { + use anyhow::Context; use sqlx::{Connection, SqliteConnection}; use std::env; diff --git a/common/client-core/surb-storage/build.rs b/common/client-core/surb-storage/build.rs index 5cdde74c4ce..7f77560668b 100644 --- a/common/client-core/surb-storage/build.rs +++ b/common/client-core/surb-storage/build.rs @@ -1,12 +1,11 @@ // Copyright 2022 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use anyhow::Context; - #[tokio::main] async fn main() -> anyhow::Result<()> { #[cfg(feature = "fs-surb-storage")] { + use anyhow::Context; use sqlx::{Connection, SqliteConnection}; use std::env;