mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
fix(macros): cache rustc -V output (#13690)
This commit is contained in:
5
.changes/cache-rustc-version.md
Normal file
5
.changes/cache-rustc-version.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
tauri-macros: "patch:perf"
|
||||
---
|
||||
|
||||
Cache `rustc -V` output in `#[tauri::command]` macros
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::env::var;
|
||||
use std::{env::var, sync::OnceLock};
|
||||
|
||||
use heck::{ToLowerCamelCase, ToSnakeCase};
|
||||
use proc_macro::TokenStream;
|
||||
@@ -485,26 +485,29 @@ fn is_rustc_at_least(major: u32, minor: u32) -> bool {
|
||||
version.0 >= major && version.1 >= minor
|
||||
}
|
||||
|
||||
fn rustc_version() -> (u32, u32) {
|
||||
cross_command("rustc")
|
||||
.arg("-V")
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|o| {
|
||||
let version = String::from_utf8_lossy(&o.stdout)
|
||||
.trim()
|
||||
.split(' ')
|
||||
.nth(1)
|
||||
.unwrap_or_default()
|
||||
.split('.')
|
||||
.take(2)
|
||||
.flat_map(|p| p.parse::<u32>().ok())
|
||||
.collect::<Vec<_>>();
|
||||
version
|
||||
.first()
|
||||
.and_then(|major| version.get(1).map(|minor| (*major, *minor)))
|
||||
})
|
||||
.unwrap_or((1, 0))
|
||||
fn rustc_version() -> &'static (u32, u32) {
|
||||
static RUSTC_VERSION: OnceLock<(u32, u32)> = OnceLock::new();
|
||||
RUSTC_VERSION.get_or_init(|| {
|
||||
cross_command("rustc")
|
||||
.arg("-V")
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|o| {
|
||||
let version = String::from_utf8_lossy(&o.stdout)
|
||||
.trim()
|
||||
.split(' ')
|
||||
.nth(1)
|
||||
.unwrap_or_default()
|
||||
.split('.')
|
||||
.take(2)
|
||||
.flat_map(|p| p.parse::<u32>().ok())
|
||||
.collect::<Vec<_>>();
|
||||
version
|
||||
.first()
|
||||
.and_then(|major| version.get(1).map(|minor| (*major, *minor)))
|
||||
})
|
||||
.unwrap_or((1, 0))
|
||||
})
|
||||
}
|
||||
|
||||
fn cross_command(bin: &str) -> std::process::Command {
|
||||
|
||||
Reference in New Issue
Block a user