veridian_kernel/pkg/sdk/
mod.rs1#[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
21pub fn get_sysroot() -> &'static str {
23 "/usr/veridian"
24}
25
26pub 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#[derive(Debug, Clone, PartialEq, Eq)]
44pub enum BuildTarget {
45 Native,
47 #[cfg(feature = "alloc")]
49 Cross(String),
50}
51
52#[cfg(feature = "alloc")]
54#[derive(Debug, Clone)]
55pub struct ToolchainInfo {
56 pub compiler_path: String,
58 pub linker_path: String,
60 pub target_triple: String,
62 pub sysroot_path: String,
64 pub version: String,
66}
67
68#[cfg(feature = "alloc")]
69impl ToolchainInfo {
70 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#[cfg(feature = "alloc")]
87#[derive(Debug, Clone)]
88pub struct SdkConfig {
89 pub default_cflags: Vec<String>,
91 pub default_ldflags: Vec<String>,
93 pub sysroot: String,
95 pub include_paths: Vec<String>,
97 pub lib_paths: Vec<String>,
99}
100
101#[cfg(feature = "alloc")]
102impl SdkConfig {
103 pub fn new() -> Self {
105 Self::for_target(BuildTarget::Native)
106 }
107
108 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}