Skip to content

Commit 0a552a8

Browse files
authored
fix(macros): cache rustc -V output (#13690)
1 parent 560067c commit 0a552a8

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

.changes/cache-rustc-version.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri-macros: "patch:perf"
3+
---
4+
5+
Cache `rustc -V` output in `#[tauri::command]` macros

crates/tauri-macros/src/command/wrapper.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use std::env::var;
5+
use std::{env::var, sync::OnceLock};
66

77
use heck::{ToLowerCamelCase, ToSnakeCase};
88
use proc_macro::TokenStream;
@@ -485,26 +485,29 @@ fn is_rustc_at_least(major: u32, minor: u32) -> bool {
485485
version.0 >= major && version.1 >= minor
486486
}
487487

488-
fn rustc_version() -> (u32, u32) {
489-
cross_command("rustc")
490-
.arg("-V")
491-
.output()
492-
.ok()
493-
.and_then(|o| {
494-
let version = String::from_utf8_lossy(&o.stdout)
495-
.trim()
496-
.split(' ')
497-
.nth(1)
498-
.unwrap_or_default()
499-
.split('.')
500-
.take(2)
501-
.flat_map(|p| p.parse::<u32>().ok())
502-
.collect::<Vec<_>>();
503-
version
504-
.first()
505-
.and_then(|major| version.get(1).map(|minor| (*major, *minor)))
506-
})
507-
.unwrap_or((1, 0))
488+
fn rustc_version() -> &'static (u32, u32) {
489+
static RUSTC_VERSION: OnceLock<(u32, u32)> = OnceLock::new();
490+
RUSTC_VERSION.get_or_init(|| {
491+
cross_command("rustc")
492+
.arg("-V")
493+
.output()
494+
.ok()
495+
.and_then(|o| {
496+
let version = String::from_utf8_lossy(&o.stdout)
497+
.trim()
498+
.split(' ')
499+
.nth(1)
500+
.unwrap_or_default()
501+
.split('.')
502+
.take(2)
503+
.flat_map(|p| p.parse::<u32>().ok())
504+
.collect::<Vec<_>>();
505+
version
506+
.first()
507+
.and_then(|major| version.get(1).map(|minor| (*major, *minor)))
508+
})
509+
.unwrap_or((1, 0))
510+
})
508511
}
509512

510513
fn cross_command(bin: &str) -> std::process::Command {

0 commit comments

Comments
 (0)