21
21
from .logger import logger , log_config
22
22
from . import config
23
23
from .package import Package , create_package , Backend
24
+ from .package .kernel import Kernel
25
+ from .package .runtime import Runtime
24
26
from .package .meson import Meson
25
27
from .package .cargo import Cargo
28
+ from .package import cargo
26
29
27
30
from .buildsys import ninja_backend
28
- from .utils import pathhelper
31
+ from .utils import pathhelper , working_directory
29
32
30
33
31
34
class Project :
32
35
def __init__ (self , project_dir : pathlib .Path ) -> None :
33
36
self .path = pathhelper .ProjectPath (
34
37
project_dir = project_dir ,
35
- output_dir = project_dir ,
38
+ output_dir = project_dir / "output" ,
36
39
)
37
40
38
41
# XXX:
@@ -58,18 +61,12 @@ def __init__(self, project_dir: pathlib.Path) -> None:
58
61
# This will be, likely, false for next devel step.
59
62
60
63
# Instantiate Sentry kernel
61
- self ._packages . append (
62
- Meson ( "kernel" , self , self . _toml [ "kernel" ], Package . Type . Kernel ) # type: ignore
63
- )
64
+ self ._kernel = Kernel ( self , self . _toml )
65
+ self . _packages . append ( self . _kernel . _package )
66
+
64
67
# Instantiate libshield
65
- self ._packages .append (
66
- Meson (
67
- "runtime" ,
68
- self ,
69
- self ._toml ["runtime" ],
70
- Package .Type .Runtime , # type: ignore[arg-type]
71
- )
72
- )
68
+ self ._runtime = Runtime (self , self ._toml )
69
+ self ._packages .append (self ._runtime ._package )
73
70
74
71
if "application" in self ._toml :
75
72
self ._noapp = False
@@ -95,6 +92,15 @@ def update(self) -> None:
95
92
p .update ()
96
93
97
94
def setup (self ) -> None :
95
+
96
+ logger .info ("Create Cargo local repository" )
97
+ registry = cargo .LocalRegistry (
98
+ self .path .sysroot_data_dir / "cargo" / "registry" / "outpost_sdk"
99
+ )
100
+ cargo_config = cargo .Config (self .path .output_dir , registry )
101
+ registry .init ()
102
+ self ._kernel .install_crates (registry , cargo_config )
103
+ self ._runtime .install_crates (registry , cargo_config )
98
104
logger .info (f"Generating { self .name } Ninja build File" )
99
105
ninja = ninja_backend .NinjaGenFile (os .path .join (self .path .build_dir , "build.ninja" ))
100
106
@@ -112,7 +118,7 @@ def setup(self) -> None:
112
118
)
113
119
114
120
ninja .add_meson_rules ()
115
- ninja .add_cargo_rules ()
121
+ ninja .add_cargo_rules (self . _kernel . rustargs , self . _kernel . rust_target )
116
122
117
123
# Add setup/compile/install targets for meson packages
118
124
for p in self ._packages :
@@ -143,20 +149,22 @@ def setup(self) -> None:
143
149
144
150
# Dummy link, for non pic application
145
151
for package in self ._packages :
146
- if package .is_application and package .backend == Backend .Meson :
147
- ninja .add_relink_meson_target (
152
+ # if package.is_application and package.backend == Backend.Meson:
153
+ if package .is_application :
154
+ ninja .add_relink_target (
148
155
package .name ,
149
156
package .installed_targets [0 ],
150
157
package .dummy_linked_targets [0 ],
151
158
dummy_linker_script ,
159
+ package_name = package .name if package .backend == Backend .Meson else "kernel" ,
152
160
)
153
161
154
162
layout_sys_exelist = []
155
163
layout_app_exelist = []
156
164
for package in self ._packages :
157
165
if package .is_sys_package :
158
166
layout_sys_exelist .extend (package .installed_targets )
159
- elif package . backend == Backend . Meson :
167
+ else :
160
168
layout_app_exelist .extend (package .dummy_linked_targets )
161
169
162
170
firmware_layout = ninja .add_internal_gen_memory_layout_target (
@@ -174,7 +182,7 @@ def setup(self) -> None:
174
182
175
183
# gen_ld/relink/gen_meta/objcopy app(s)
176
184
for package in self ._packages :
177
- if package .is_application and package . backend == Backend . Meson :
185
+ if package .is_application :
178
186
# XXX: Handle multiple exe package
179
187
elf_in = package .installed_targets [0 ]
180
188
elf_out = package .relocated_targets [0 ]
@@ -189,15 +197,21 @@ def setup(self) -> None:
189
197
pathlib .Path (firmware_layout [0 ]),
190
198
package .name ,
191
199
)
192
- ninja .add_relink_meson_target (
200
+ ninja .add_relink_target (
193
201
package .name ,
194
202
elf_in ,
195
203
elf_out ,
196
204
linker_script ,
197
- package .name ,
205
+ package_name = package .name if package . backend == Backend . Meson else "kernel" ,
198
206
)
199
207
200
- ninja .add_objcopy_rule (elf_out , hex_out , "ihex" , [], package .name )
208
+ ninja .add_objcopy_rule (
209
+ elf_out ,
210
+ hex_out ,
211
+ "ihex" ,
212
+ [],
213
+ package_name = package .name if package .backend == Backend .Meson else "kernel" ,
214
+ )
201
215
app_hex_files .append (hex_out )
202
216
203
217
ninja .add_gen_metadata_rule (
@@ -238,7 +252,8 @@ def update(project: Project) -> None:
238
252
239
253
240
254
def setup (project : Project ) -> None :
241
- project .setup ()
255
+ with working_directory (project .path .output_dir ):
256
+ project .setup ()
242
257
243
258
244
259
def common_argument_parser () -> ArgumentParser :
0 commit comments