mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 13:47:21 +00:00
Took the architecture from the build target instead of metadata.txt (#1070)
This commit is contained in:
1 parent
db2cbaa71e
commit
940d214429
11 files changed
+37
-155
No files matched your search
+12
-24
@@ -7,20 +7,19 @@ fn main() {
|
||||
println!("cargo:rustc-env=OUT_DIR={}", out_dir.to_str().unwrap());
|
||||
|
||||
//
|
||||
// When we are in debug mode, we want to set the current RID
|
||||
// to the current architecture. This is necessary, so that
|
||||
// the developers get the right behavior.
|
||||
//
|
||||
// We read the current OS and architecture and overwrite the
|
||||
// current RID in the metadata file (line #10).
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
let current_os = std::env::consts::OS;
|
||||
let current_arch = std::env::consts::ARCH;
|
||||
let rid = match (current_os, current_arch) {
|
||||
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()) {
|
||||
("windows", "x86_64") => "win-x64",
|
||||
("windows", "aarch64") => "win-arm64",
|
||||
|
||||
@@ -30,28 +29,17 @@ fn main() {
|
||||
("macos", "x86_64") => "osx-x64",
|
||||
("macos", "aarch64") => "osx-arm64",
|
||||
|
||||
_ => panic!("Unsupported OS or architecture: {current_os} {current_arch}"),
|
||||
_ => panic!("Unsupported OS or architecture: {target_os} {target_arch}"),
|
||||
};
|
||||
|
||||
let metadata = include_str!("../metadata.txt");
|
||||
let mut metadata_lines = metadata.lines().collect::<Vec<_>>();
|
||||
metadata_lines[9] = rid;
|
||||
|
||||
// Every line ends with a line break, the last one included. The build
|
||||
// script of the .NET side writes the file the same way:
|
||||
let mut new_metadata = metadata_lines.join("\n");
|
||||
new_metadata.push('\n');
|
||||
|
||||
// Write only on a change to avoid unnecessary rewrites:
|
||||
if new_metadata != metadata {
|
||||
std::fs::write("../metadata.txt", new_metadata).unwrap();
|
||||
}
|
||||
println!("cargo:rustc-env=AI_STUDIO_ARCHITECTURE={rid}");
|
||||
|
||||
//
|
||||
// Read the current version and update the
|
||||
// Rust and Tauri configuration files:
|
||||
//
|
||||
let version = metadata_lines[0];
|
||||
let metadata = include_str!("../metadata.txt");
|
||||
let version = metadata.lines().next().unwrap();
|
||||
update_cargo_toml("Cargo.toml", version);
|
||||
update_tauri_conf("tauri.conf.json", version);
|
||||
}
|
||||
|
||||
@@ -38,12 +38,12 @@ impl MetaData {
|
||||
let mud_blazor_version = metadata_lines.next().unwrap();
|
||||
let tauri_version = metadata_lines.next().unwrap();
|
||||
let app_commit_hash = metadata_lines.next().unwrap();
|
||||
let architecture = metadata_lines.next().unwrap();
|
||||
let pdfium_version = metadata_lines.next().unwrap();
|
||||
let vector_store_version = metadata_lines.next().unwrap();
|
||||
|
||||
let metadata = MetaData {
|
||||
architecture: architecture.to_string(),
|
||||
// The build script names the platform the runtime is built for:
|
||||
architecture: env!("AI_STUDIO_ARCHITECTURE").to_string(),
|
||||
app_commit_hash: app_commit_hash.to_string(),
|
||||
app_version: app_version.to_string(),
|
||||
build_number: build_number.to_string(),
|
||||
|
||||
+1
-43
@@ -6,10 +6,7 @@ use std::sync::OnceLock;
|
||||
use log::{info, warn};
|
||||
use tokio::process::Command;
|
||||
use crate::environment::{DATA_DIRECTORY, is_flatpak};
|
||||
use crate::metadata::META_DATA;
|
||||
|
||||
/// Tracks whether the RID mismatch warning has been logged.
|
||||
static HAS_LOGGED_RID_MISMATCH: OnceLock<()> = OnceLock::new();
|
||||
static HAS_LOGGED_PANDOC_PATH: OnceLock<()> = OnceLock::new();
|
||||
const FLATPAK_PANDOC_PLUGIN_BIN_DIRECTORY: &str = "/app/plugins/pandoc/bin";
|
||||
|
||||
@@ -243,47 +240,8 @@ impl PandocProcessBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Determines the executable name based on the current OS at runtime.
|
||||
///
|
||||
/// This uses runtime detection instead of metadata to ensure correct behavior
|
||||
/// on dev machines where the metadata may contain stale values.
|
||||
/// Determines the executable name based on the OS the runtime is built for.
|
||||
fn pandoc_executable_name() -> String {
|
||||
// Log a warning (once) if the runtime OS differs from the metadata architecture.
|
||||
// This can happen on dev machines where the metadata.txt contains stale values.
|
||||
HAS_LOGGED_RID_MISMATCH.get_or_init(|| {
|
||||
let runtime_os = std::env::consts::OS;
|
||||
let runtime_arch = std::env::consts::ARCH;
|
||||
|
||||
if let Ok(metadata) = META_DATA.lock() && let Some(metadata) = metadata.as_ref() {
|
||||
let metadata_arch = &metadata.architecture;
|
||||
|
||||
// Determine expected OS from metadata:
|
||||
let metadata_is_windows = metadata_arch.starts_with("win-");
|
||||
let metadata_is_macos = metadata_arch.starts_with("osx-");
|
||||
let metadata_is_linux = metadata_arch.starts_with("linux-");
|
||||
|
||||
// Compare with runtime OS:
|
||||
let runtime_is_windows = runtime_os == "windows";
|
||||
let runtime_is_macos = runtime_os == "macos";
|
||||
let runtime_is_linux = runtime_os == "linux";
|
||||
|
||||
let os_mismatch = (metadata_is_windows != runtime_is_windows)
|
||||
|| (metadata_is_macos != runtime_is_macos)
|
||||
|| (metadata_is_linux != runtime_is_linux);
|
||||
|
||||
if os_mismatch {
|
||||
warn!(
|
||||
Source = "Pandoc";
|
||||
"Runtime-detected OS '{}-{}' differs from metadata architecture '{}'. Using runtime-detected OS. This is expected on dev machines where metadata.txt may be outdated.",
|
||||
runtime_os,
|
||||
runtime_arch,
|
||||
metadata_arch
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Use std::env::consts::OS for runtime detection instead of metadata
|
||||
match std::env::consts::OS {
|
||||
"windows" => "pandoc.exe".to_string(),
|
||||
_ => "pandoc".to_string(),
|
||||
|
||||
Reference in new issue
Block a user