2026-02-03 14:32:17 +01:00
|
|
|
use std::path::{PathBuf};
|
2024-03-28 22:26:48 +01:00
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
tauri_build::build();
|
2025-04-15 08:08:39 +02:00
|
|
|
|
2024-03-28 22:26:48 +01:00
|
|
|
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
|
|
|
|
println!("cargo:rustc-env=OUT_DIR={}", out_dir.to_str().unwrap());
|
2024-05-21 18:55:08 +02:00
|
|
|
|
2025-04-15 08:08:39 +02:00
|
|
|
//
|
2026-10-16 08:13:18 +02:00
|
|
|
// The runtime reports the platform it is built for. Cargo runs this
|
|
|
|
|
// build script on the machine which builds, so std::env::consts would
|
|
|
|
|
// name that machine. Both differ when we cross-compile, e.g., for
|
|
|
|
|
// Intel-based Macs on an ARM-based one. Hence, we read the target
|
|
|
|
|
// from Cargo and pass its RID on to the compiler.
|
2025-04-15 08:08:39 +02:00
|
|
|
//
|
|
|
|
|
// We have to take care of different naming conventions. The
|
|
|
|
|
// following RIDs are supported: win-x64, win-arm64, linux-x64,
|
|
|
|
|
// linux-arm64, osx-x64, osx-arm64.
|
|
|
|
|
//
|
2026-10-16 08:13:18 +02:00
|
|
|
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
|
|
|
|
|
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
|
|
|
|
|
let rid = match (target_os.as_str(), target_arch.as_str()) {
|
2025-04-15 08:08:39 +02:00
|
|
|
("windows", "x86_64") => "win-x64",
|
|
|
|
|
("windows", "aarch64") => "win-arm64",
|
|
|
|
|
|
|
|
|
|
("linux", "x86_64") => "linux-x64",
|
|
|
|
|
("linux", "aarch64") => "linux-arm64",
|
|
|
|
|
|
|
|
|
|
("macos", "x86_64") => "osx-x64",
|
|
|
|
|
("macos", "aarch64") => "osx-arm64",
|
|
|
|
|
|
2026-10-16 08:13:18 +02:00
|
|
|
_ => panic!("Unsupported OS or architecture: {target_os} {target_arch}"),
|
2025-04-15 08:08:39 +02:00
|
|
|
};
|
|
|
|
|
|
2026-10-16 08:13:18 +02:00
|
|
|
println!("cargo:rustc-env=AI_STUDIO_ARCHITECTURE={rid}");
|
2025-04-15 08:08:39 +02:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Read the current version and update the
|
|
|
|
|
// Rust and Tauri configuration files:
|
|
|
|
|
//
|
2026-10-16 08:13:18 +02:00
|
|
|
let metadata = include_str!("../metadata.txt");
|
|
|
|
|
let version = metadata.lines().next().unwrap();
|
2024-05-21 18:55:08 +02:00
|
|
|
update_cargo_toml("Cargo.toml", version);
|
|
|
|
|
update_tauri_conf("tauri.conf.json", version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update_cargo_toml(cargo_path: &str, version: &str) {
|
|
|
|
|
let cargo_toml = std::fs::read_to_string(cargo_path).unwrap();
|
|
|
|
|
let cargo_toml_lines = cargo_toml.lines();
|
|
|
|
|
let mut new_cargo_toml = String::new();
|
|
|
|
|
|
2026-05-06 18:45:50 +02:00
|
|
|
// Return early when the version already matches to avoid unnecessary rewrites.
|
|
|
|
|
let current_version = cargo_toml.lines().find_map(|line| {
|
|
|
|
|
let trimmed = line.trim_start();
|
|
|
|
|
let rest = trimmed.strip_prefix("\"version\": ")?;
|
|
|
|
|
let quoted = rest.strip_prefix('"')?;
|
|
|
|
|
let end_idx = quoted.find('"')?;
|
|
|
|
|
Some("ed[..end_idx])
|
|
|
|
|
});
|
|
|
|
|
if current_version == Some(version) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-21 18:55:08 +02:00
|
|
|
for line in cargo_toml_lines {
|
|
|
|
|
if line.starts_with("version = ") {
|
|
|
|
|
new_cargo_toml.push_str(&format!("version = \"{version}\""));
|
|
|
|
|
} else {
|
|
|
|
|
new_cargo_toml.push_str(line);
|
|
|
|
|
}
|
|
|
|
|
new_cargo_toml.push('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::fs::write(cargo_path, new_cargo_toml).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update_tauri_conf(tauri_conf_path: &str, version: &str) {
|
|
|
|
|
let tauri_conf = std::fs::read_to_string(tauri_conf_path).unwrap();
|
2026-05-06 18:45:50 +02:00
|
|
|
|
|
|
|
|
// Return early when the version already matches to avoid unnecessary rewrites.
|
|
|
|
|
let current_version = tauri_conf.lines().find_map(|line| {
|
|
|
|
|
let trimmed = line.trim_start();
|
|
|
|
|
let rest = trimmed.strip_prefix("\"version\": ")?;
|
|
|
|
|
let quoted = rest.strip_prefix('"')?;
|
|
|
|
|
let end_idx = quoted.find('"')?;
|
|
|
|
|
Some("ed[..end_idx])
|
|
|
|
|
});
|
|
|
|
|
if current_version == Some(version) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-21 18:55:08 +02:00
|
|
|
let tauri_conf_lines = tauri_conf.lines();
|
|
|
|
|
let mut new_tauri_conf = String::new();
|
|
|
|
|
|
|
|
|
|
for line in tauri_conf_lines {
|
|
|
|
|
// The version in Tauri's config is formatted like this:
|
|
|
|
|
// "version": "0.1.0-alpha.0"
|
|
|
|
|
// Please notice, that the version number line might have a leading tab, etc.
|
|
|
|
|
if line.contains("\"version\": ") {
|
2026-05-06 18:45:50 +02:00
|
|
|
new_tauri_conf.push_str(&format!(" \"version\": \"{version}\","));
|
2024-05-21 18:55:08 +02:00
|
|
|
} else {
|
|
|
|
|
new_tauri_conf.push_str(line);
|
|
|
|
|
}
|
|
|
|
|
new_tauri_conf.push('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::fs::write(tauri_conf_path, new_tauri_conf).unwrap();
|
2026-02-03 14:32:17 +01:00
|
|
|
}
|