fix: totally fix rustc version check

C-style shit syntax
This commit is contained in:
mokurin000
2025-07-31 20:02:46 +08:00
parent 6cb1dcefe8
commit 789d46991d
4 changed files with 22 additions and 14 deletions

View File

@@ -29,4 +29,6 @@ nyquest-preset = { version = "0.2.0", features = ["async"] }
palc = { version = "0.0.1", features = ["derive"] }
futures-util = { version = "0.3.31", optional = true }
ctrlc = { version = "3.4.7", features = ["termination"] }
rustversion = "1.0.21"
[build-dependencies]
version_check = "0.9.5"

7
sdgb-cli/build.rs Normal file
View File

@@ -0,0 +1,7 @@
fn main() {
println!("cargo::rustc-check-cfg=cfg(file_lock_ready)");
if version_check::is_min_version("1.89") == Some(true) {
println!("cargo:rustc-cfg=file_lock_ready");
}
}

View File

@@ -201,6 +201,17 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
use crate::cache::{open_table_read, read_txn};
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("players.json")?;
#[cfg(file_lock_ready)]
file.try_lock()?;
let writer = BufWriter::new(file);
let txn = read_txn()?;
let table = open_table_read(&txn)?;
@@ -215,18 +226,6 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
.map(|(value, _)| value)
.collect::<Vec<GetUserPreviewApiResp>>();
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("players.json")?;
#[rustversion::since(1.89)]
{
file.lock()?;
}
let writer = BufWriter::new(file);
serde_json::to_writer(writer, &user_ids)?;
info!("dumped {} user id", user_ids.len());
}