@@ -182,7 +182,7 @@ pub struct CompilerTestBuilder {
182
182
/// The extra MASM modules to link to the compiled MASM program
183
183
link_masm_modules : LinkMasmModules ,
184
184
/// Extra flags to pass to the midenc driver
185
- midenc_flags : Vec < Cow < ' static , str > > ,
185
+ midenc_flags : Vec < String > ,
186
186
/// Extra RUSTFLAGS to set when compiling Rust code
187
187
rustflags : Vec < Cow < ' static , str > > ,
188
188
/// The cargo workspace directory of the compiler
@@ -225,8 +225,7 @@ impl CompilerTestBuilder {
225
225
] ) ;
226
226
let mut midenc_flags = vec ! [ "--debug" . into( ) , "--verbose" . into( ) ] ;
227
227
if let Some ( entrypoint) = entrypoint {
228
- midenc_flags
229
- . extend ( [ "--entrypoint" . into ( ) , format ! ( "{}" , entrypoint. display( ) ) . into ( ) ] ) ;
228
+ midenc_flags. extend ( [ "--entrypoint" . into ( ) , format ! ( "{}" , entrypoint. display( ) ) ] ) ;
230
229
}
231
230
Self {
232
231
config : Default :: default ( ) ,
@@ -269,7 +268,7 @@ impl CompilerTestBuilder {
269
268
None => ( ) ,
270
269
}
271
270
self . midenc_flags
272
- . extend ( [ "--entrypoint" . into ( ) , format ! ( "{}" , entrypoint. display( ) ) . into ( ) ] ) ;
271
+ . extend ( [ "--entrypoint" . into ( ) , format ! ( "{}" , entrypoint. display( ) ) ] ) ;
273
272
self
274
273
}
275
274
@@ -278,7 +277,7 @@ impl CompilerTestBuilder {
278
277
& mut self ,
279
278
flags : impl IntoIterator < Item = Cow < ' static , str > > ,
280
279
) -> & mut Self {
281
- self . midenc_flags . extend ( flags) ;
280
+ self . midenc_flags . extend ( flags. into_iter ( ) . map ( |s| s . to_string ( ) ) ) ;
282
281
self
283
282
}
284
283
@@ -306,7 +305,7 @@ impl CompilerTestBuilder {
306
305
307
306
/// Consume the builder, invoke any tools required to obtain the inputs for the test, and if
308
307
/// successful, return a [CompilerTest], ready for evaluation.
309
- pub fn build ( self ) -> CompilerTest {
308
+ pub fn build ( mut self ) -> CompilerTest {
310
309
// Set up the command used to compile the test inputs (typically Rust -> Wasm)
311
310
let mut command = match self . source {
312
311
CompilerTestInputType :: CargoMiden ( _) => {
@@ -398,31 +397,26 @@ impl CompilerTestBuilder {
398
397
399
398
// Build test
400
399
match self . source {
401
- CompilerTestInputType :: CargoMiden ( config) => {
402
- let expected_wasm_artifact_path = config. wasm_artifact_path ( ) ;
403
- let skip_rust_compilation =
404
- std:: env:: var ( "SKIP_RUST" ) . is_ok ( ) && expected_wasm_artifact_path. exists ( ) ;
405
- let wasm_artifact_path = if !skip_rust_compilation {
406
- let mut args = vec ! [ command. get_program( ) . to_str( ) . unwrap( ) . to_string( ) ] ;
407
- let cmd_args: Vec < String > = command
408
- . get_args ( )
409
- . collect :: < Vec < & OsStr > > ( )
410
- . iter ( )
411
- . map ( |s| s. to_str ( ) . unwrap ( ) . to_string ( ) )
412
- . collect ( ) ;
413
- args. extend ( cmd_args) ;
414
- let wasm_artifacts =
415
- cargo_miden:: run ( args. into_iter ( ) , cargo_miden:: OutputType :: Wasm ) . unwrap ( ) ;
416
- assert_eq ! (
417
- wasm_artifacts. len( ) ,
418
- 1 ,
419
- "expected one Wasm artifact, got {:?}" ,
420
- wasm_artifacts
421
- ) ;
422
- wasm_artifacts. first ( ) . unwrap ( ) . clone ( )
423
- } else {
424
- drop ( command) ;
425
- expected_wasm_artifact_path
400
+ CompilerTestInputType :: CargoMiden ( ..) => {
401
+ let mut args = vec ! [ command. get_program( ) . to_str( ) . unwrap( ) . to_string( ) ] ;
402
+ let cmd_args: Vec < String > = command
403
+ . get_args ( )
404
+ . collect :: < Vec < & OsStr > > ( )
405
+ . iter ( )
406
+ . map ( |s| s. to_str ( ) . unwrap ( ) . to_string ( ) )
407
+ . collect ( ) ;
408
+ args. extend ( cmd_args) ;
409
+ let build_output =
410
+ cargo_miden:: run ( args. into_iter ( ) , cargo_miden:: OutputType :: Wasm )
411
+ . unwrap ( )
412
+ . expect ( "'cargo miden build' should return Some(CommandOutput)" )
413
+ . unwrap_build_output ( ) ; // Use the new method
414
+ let ( wasm_artifact_path, dependencies) = match build_output {
415
+ cargo_miden:: BuildOutput :: Wasm {
416
+ artifact_path,
417
+ dependencies,
418
+ } => ( artifact_path, dependencies) ,
419
+ other => panic ! ( "Expected Wasm output, got {:?}" , other) ,
426
420
} ;
427
421
let artifact_name =
428
422
wasm_artifact_path. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
@@ -440,6 +434,10 @@ impl CompilerTestBuilder {
440
434
} ) ) ;
441
435
// dbg!(&inputs);
442
436
437
+ for dep in & dependencies {
438
+ self . midenc_flags . push ( "--link-library" . to_string ( ) ) ;
439
+ self . midenc_flags . push ( dep. to_str ( ) . unwrap ( ) . to_string ( ) ) ;
440
+ }
443
441
let context = setup:: default_context ( inputs, & self . midenc_flags ) ;
444
442
let session = context. session_rc ( ) ;
445
443
CompilerTest {
@@ -448,6 +446,7 @@ impl CompilerTestBuilder {
448
446
context,
449
447
artifact_name : artifact_name. into ( ) ,
450
448
entrypoint : self . entrypoint ,
449
+ dependencies,
451
450
..Default :: default ( )
452
451
}
453
452
}
@@ -874,6 +873,8 @@ pub struct CompilerTest {
874
873
ir_masm_program : Option < Result < Arc < midenc_codegen_masm:: MasmComponent > , String > > ,
875
874
/// The compiled package containing a program executable by the VM
876
875
package : Option < Result < Arc < miden_mast_package:: Package > , String > > ,
876
+ /// Miden packages for dependencies
877
+ pub dependencies : Vec < PathBuf > ,
877
878
}
878
879
879
880
impl fmt:: Debug for CompilerTest {
@@ -907,6 +908,7 @@ impl Default for CompilerTest {
907
908
masm_src : None ,
908
909
ir_masm_program : None ,
909
910
package : None ,
911
+ dependencies : Vec :: new ( ) ,
910
912
}
911
913
}
912
914
}
0 commit comments