* -------------------------------------------------------------------------
* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* -------------------------------------------------------------------------
*/
#![windows_subsystem = "windows"]
#![allow(non_snake_case)]
#[cfg(all(not(debug_assertions), feature = "default"))]
mod default;
#[cfg(all(not(debug_assertions), feature = "default"))]
mod webview;
#[cfg(all(debug_assertions, feature = "default"))]
mod dev;
#[cfg(not(feature = "default"))]
mod http;
fn main() {
#[cfg(target_os = "linux")]
{
if getuid() == 0 && !allow_root() {
eprintln!(
"WARNING: Running as root is discouraged.\
Use '--allow-root' to override this restriction."
);
return;
}
}
#[cfg(feature = "default")]
{
#[cfg(debug_assertions)]
dev::main();
#[cfg(not(debug_assertions))]
default::main();
}
#[cfg(not(feature = "default"))]
http::main();
}
#[cfg(target_os = "linux")]
fn allow_root() -> bool {
let args: Vec<String> = std::env::args().collect();
args.contains(&String::from("--allow-root"))
}
#[cfg(target_os = "linux")]
fn getuid() -> u32 {
use std::arch::asm;
let uid: u32;
#[cfg(target_arch = "x86_64")]
unsafe {
asm!(
"syscall",
in("rax") 102,
lateout("rax") uid,
options(nostack, nomem, preserves_flags)
)
}
#[cfg(target_arch = "aarch64")]
unsafe {
asm!(
"svc 0",
in("x8") 174,
lateout("x0") uid,
options(nostack, nomem, preserves_flags)
)
}
uid
}