ng_repo/
os_info.rs

1// Copyright (c) 2022-2025 Niko Bonnieure, Par le Peuple, NextGraph.org developers
2// All rights reserved.
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
5// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
6// at your option. All files in the project carrying such
7// notice may not be copied, modified, or distributed except
8// according to those terms.
9
10use os_info;
11use serde_json::{json, Value};
12
13pub fn get_os_info() -> Value {
14    let arch = std::env::consts::ARCH;
15    let machine = match arch {
16        "ia32" => "x86",
17        "x64" => "x86_64",
18        "i386" => "x86",
19        "i686" => "x86",
20        "amd64" => "x86_64",
21        "arm64" => "aarch64",
22        "powerpc" => "ppc",
23        "powerpc64" => "ppc64",
24        _ => arch,
25    };
26
27    let info = os_info::get();
28    let os_type = info.os_type();
29    let os_name = match os_type {
30        os_info::Type::Macos => "macOS".to_string(),
31        _ => format!("{:?}", os_type),
32    };
33
34    let val = json!({
35        "uname": {
36            "os_name": os_name,
37            "version": info.version().to_string(),
38            "arch": info.architecture().map(|s| s.into()).unwrap_or(Value::Null),
39            "bitness": format!("{:?}",info.bitness()),
40            "codename": info.codename().map(|s| s.into()).unwrap_or(Value::Null),
41            "edition": info.edition().map(|s| s.into()).unwrap_or(Value::Null),
42        },
43        "rust": {
44            "family": std::env::consts::FAMILY,
45            "os_name": match std::env::consts::OS {
46                "linux" => "Linux",
47                "macos" => "macOS",
48                "ios" => "iOS",
49                "freebsd" => "FreeBSD",
50                "dragonfly" => "DragonFly",
51                "netbsd" => "NetBSD",
52                "openbsd" => "OpenBSD",
53                "solaris" => "Solaris",
54                "android" => "Android",
55                "windows" => "Windows",
56                _ => std::env::consts::OS,
57            },
58            "arch": machine,
59            "debug": cfg!(debug_assertions),
60            "target": current_platform::CURRENT_PLATFORM,
61        }
62    });
63    //println!("{}", to_string_pretty(&val).unwrap());
64    val
65}