⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

veridian_kernel/pkg/sdk/
mod.rs

1//! SDK Core Types for VeridianOS Package Development
2//!
3//! Provides toolchain information, build target configuration, and sysroot
4//! management for building VeridianOS packages. These types define the SDK
5//! contract for user-space library and application development.
6//!
7//! NOTE: Many types in this module are forward declarations for user-space
8//! APIs. They will be exercised when user-space process execution is
9//! functional. See TODO(user-space) markers for specific activation points.
10
11// User-space SDK forward declarations -- see module doc TODO(user-space)
12
13#[cfg(feature = "alloc")]
14use alloc::{string::String, vec, vec::Vec};
15
16pub mod generator;
17pub mod pkg_config;
18pub mod syscall_api;
19pub mod toolchain;
20
21/// Return the sysroot path for the VeridianOS SDK.
22pub fn get_sysroot() -> &'static str {
23    "/usr/veridian"
24}
25
26/// Return the target triple for the current architecture.
27pub fn get_target_triple() -> &'static str {
28    #[cfg(target_arch = "x86_64")]
29    {
30        "x86_64-veridian"
31    }
32    #[cfg(target_arch = "aarch64")]
33    {
34        "aarch64-veridian"
35    }
36    #[cfg(target_arch = "riscv64")]
37    {
38        "riscv64gc-veridian"
39    }
40}
41
42/// Build target specification.
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub enum BuildTarget {
45    /// Build for the host architecture.
46    Native,
47    /// Cross-compile for the specified target triple.
48    #[cfg(feature = "alloc")]
49    Cross(String),
50}
51
52/// Information about the active toolchain.
53#[cfg(feature = "alloc")]
54#[derive(Debug, Clone)]
55pub struct ToolchainInfo {
56    /// Path to the compiler binary.
57    pub compiler_path: String,
58    /// Path to the linker binary.
59    pub linker_path: String,
60    /// Target triple (e.g. "x86_64-veridian").
61    pub target_triple: String,
62    /// Sysroot directory containing headers and libraries.
63    pub sysroot_path: String,
64    /// Toolchain version string.
65    pub version: String,
66}
67
68#[cfg(feature = "alloc")]
69impl ToolchainInfo {
70    /// Return toolchain information for the current architecture.
71    pub fn current() -> Self {
72        let triple = String::from(get_target_triple());
73        let sysroot = String::from(get_sysroot());
74
75        Self {
76            compiler_path: alloc::format!("{}/bin/{}-gcc", sysroot, triple),
77            linker_path: alloc::format!("{}/bin/{}-ld", sysroot, triple),
78            target_triple: triple,
79            sysroot_path: sysroot,
80            version: String::from("0.4.0"),
81        }
82    }
83}
84
85/// SDK configuration controlling compiler and linker flags.
86#[cfg(feature = "alloc")]
87#[derive(Debug, Clone)]
88pub struct SdkConfig {
89    /// Default C compiler flags.
90    pub default_cflags: Vec<String>,
91    /// Default linker flags.
92    pub default_ldflags: Vec<String>,
93    /// Sysroot directory.
94    pub sysroot: String,
95    /// Include search paths.
96    pub include_paths: Vec<String>,
97    /// Library search paths.
98    pub lib_paths: Vec<String>,
99}
100
101#[cfg(feature = "alloc")]
102impl SdkConfig {
103    /// Create a new SDK configuration with sensible defaults.
104    pub fn new() -> Self {
105        Self::for_target(BuildTarget::Native)
106    }
107
108    /// Create an SDK configuration for a specific build target.
109    pub fn for_target(target: BuildTarget) -> Self {
110        let sysroot = String::from(get_sysroot());
111
112        let triple = match &target {
113            BuildTarget::Native => String::from(get_target_triple()),
114            BuildTarget::Cross(t) => t.clone(),
115        };
116
117        let include_base = alloc::format!("{}/include", sysroot);
118        let lib_base = alloc::format!("{}/lib/{}", sysroot, triple);
119
120        Self {
121            default_cflags: vec![
122                String::from("-ffreestanding"),
123                String::from("-nostdlib"),
124                alloc::format!("--sysroot={}", sysroot),
125                alloc::format!("--target={}", triple),
126            ],
127            default_ldflags: vec![
128                String::from("-nostdlib"),
129                alloc::format!("-L{}", lib_base),
130                String::from("-lveridian"),
131            ],
132            sysroot,
133            include_paths: vec![
134                include_base.clone(),
135                alloc::format!("{}/veridian", include_base),
136            ],
137            lib_paths: vec![lib_base],
138        }
139    }
140}
141
142#[cfg(feature = "alloc")]
143impl Default for SdkConfig {
144    fn default() -> Self {
145        Self::new()
146    }
147}