@@ -45,21 +45,21 @@ fn packages() -> Vec<nbuild::Package> {
4545 nbuild:: Package {
4646 name: "nbuild" ,
4747 path: std:: path:: Path :: new( "./nbuild/Cargo.toml" ) ,
48- output : std :: path :: Path :: new ( "./nbuild/target/debug/nbuild{exe}" ) ,
48+ output_template : None ,
4949 kind: nbuild:: PackageKind :: NBuild ,
5050 testable: true ,
5151 } ,
5252 nbuild:: Package {
53- name: "flames utility " ,
53+ name: "flames" ,
5454 path: std:: path:: Path :: new( "./utilities/flames/Cargo.toml" ) ,
55- output : std :: path :: Path :: new ( "./target/{target}/{profile}/flames" ) ,
55+ output_template : Some ( "./target/{target}/{profile}/flames" ) ,
5656 kind: nbuild:: PackageKind :: Utility ,
5757 testable: false ,
5858 } ,
5959 nbuild:: Package {
6060 name: "Neotron OS" ,
6161 path: std:: path:: Path :: new( "./neotron-os/Cargo.toml" ) ,
62- output : std :: path :: Path :: new ( "./target/{target}/{profile}/neotron-os" ) ,
62+ output_template : Some ( "./target/{target}/{profile}/neotron-os" ) ,
6363 kind: nbuild:: PackageKind :: Os ,
6464 testable: false ,
6565 } ,
@@ -91,11 +91,16 @@ fn main() {
9191
9292/// Builds the utility and OS packages as binaries
9393fn binary ( packages : & [ nbuild:: Package ] , start_address : & str , target : & str ) {
94+ use chrono:: { Datelike , Timelike } ;
95+
9496 let mut is_error = false ;
9597 let Ok ( start_address) = nbuild:: parse_int ( start_address) else {
9698 eprintln ! ( "{:?} was not a valid integer" , start_address) ;
9799 std:: process:: exit ( 1 ) ;
98100 } ;
101+
102+ let mut romfs_entries = Vec :: new ( ) ;
103+ // Build utilities
99104 for package in packages
100105 . iter ( )
101106 . filter ( |p| p. kind == nbuild:: PackageKind :: Utility )
@@ -108,7 +113,57 @@ fn binary(packages: &[nbuild::Package], start_address: &str, target: &str) {
108113 eprintln ! ( "Build of {} failed: {}" , package. name, e) ;
109114 is_error = true ;
110115 }
116+ let package_output = package
117+ . output ( target, "release" )
118+ . expect ( "utilties should have an output" ) ;
119+ let contents = match std:: fs:: read ( & package_output) {
120+ Ok ( contents) => contents,
121+ Err ( e) => {
122+ eprintln ! ( "Reading of {} failed: {}" , package_output, e) ;
123+ continue ;
124+ }
125+ } ;
126+ let ctime = std:: time:: SystemTime :: now ( ) ;
127+ let ctime = chrono:: DateTime :: < chrono:: Utc > :: from ( ctime) ;
128+ romfs_entries. push ( neotron_romfs:: Entry {
129+ metadata : neotron_romfs:: EntryMetadata {
130+ file_name : package. name ,
131+ ctime : neotron_api:: file:: Time {
132+ year_since_1970 : ( ctime. year ( ) - 1970 ) as u8 ,
133+ zero_indexed_month : ctime. month0 ( ) as u8 ,
134+ zero_indexed_day : ctime. day0 ( ) as u8 ,
135+ hours : ctime. hour ( ) as u8 ,
136+ minutes : ctime. minute ( ) as u8 ,
137+ seconds : ctime. second ( ) as u8 ,
138+ } ,
139+ file_size : contents. len ( ) as u32 ,
140+ } ,
141+ contents,
142+ } ) ;
111143 }
144+
145+ // Build ROMFS
146+ let mut buffer = Vec :: new ( ) ;
147+ let _size = match neotron_romfs:: RomFs :: construct_into ( & mut buffer, & romfs_entries) {
148+ Ok ( size) => size,
149+ Err ( e) => {
150+ eprintln ! ( "Making ROMFS failed: {:?}" , e) ;
151+ std:: process:: exit ( 1 ) ;
152+ }
153+ } ;
154+ let mut romfs_path = std:: path:: PathBuf :: new ( ) ;
155+ romfs_path. push ( std:: env:: current_dir ( ) . expect ( "We have no CWD?" ) ) ;
156+ romfs_path. push ( "target" ) ;
157+ romfs_path. push ( target) ;
158+ romfs_path. push ( "release" ) ;
159+ romfs_path. push ( "romfs.bin" ) ;
160+ if let Err ( e) = std:: fs:: write ( & romfs_path, & buffer) {
161+ eprintln ! ( "Writing ROMFS to {} failed: {:?}" , romfs_path. display( ) , e) ;
162+ std:: process:: exit ( 1 ) ;
163+ }
164+ println ! ( "Built ROMFS at {}" , romfs_path. display( ) ) ;
165+
166+ // Build OS
112167 for package in packages
113168 . iter ( )
114169 . filter ( |p| p. kind == nbuild:: PackageKind :: Os )
@@ -117,10 +172,13 @@ fn binary(packages: &[nbuild::Package], start_address: &str, target: &str) {
117172 "Cross-compiling {}, using start address 0x{:08x} and target {:?}" ,
118173 package. name, start_address, target
119174 ) ;
120- let environment = [ (
121- "NEOTRON_OS_START_ADDRESS" ,
122- format ! ( "0x{:08x}" , start_address) ,
123- ) ] ;
175+ let environment = [
176+ (
177+ "NEOTRON_OS_START_ADDRESS" ,
178+ format ! ( "0x{:08x}" , start_address) ,
179+ ) ,
180+ ( "ROMFS_PATH" , romfs_path. to_string_lossy ( ) . to_string ( ) ) ,
181+ ] ;
124182 if let Err ( e) = nbuild:: cargo_with_env (
125183 & [ "build" , "--release" ] ,
126184 Some ( target) ,
@@ -130,6 +188,13 @@ fn binary(packages: &[nbuild::Package], start_address: &str, target: &str) {
130188 eprintln ! ( "Build of {} failed: {}" , package. name, e) ;
131189 is_error = true ;
132190 }
191+ let package_output = package
192+ . output ( target, "release" )
193+ . expect ( "PackageKind::Os should always have output" ) ;
194+ if let Err ( e) = nbuild:: make_bin ( & package_output) {
195+ eprintln ! ( "objcopy of {} failed: {}" , package_output, e) ;
196+ is_error = true ;
197+ }
133198 }
134199 if is_error {
135200 std:: process:: exit ( 1 ) ;
0 commit comments