@@ -5,6 +5,83 @@ use walrus::{
5
5
FunctionBuilder , FunctionId , ImportKind , MemoryId , Module , ValType ,
6
6
} ;
7
7
8
+ static IMPORTS : & [ ( & str , & str ) ] = & [
9
+ (
10
+ "shopify_function_context_new" ,
11
+ "_shopify_function_context_new" ,
12
+ ) ,
13
+ ( "shopify_function_input_get" , "_shopify_function_input_get" ) ,
14
+ (
15
+ "shopify_function_input_get_val_len" ,
16
+ "_shopify_function_input_get_val_len" ,
17
+ ) ,
18
+ ( "shopify_function_input_read_utf8_str" , "" ) ,
19
+ (
20
+ "shopify_function_input_get_obj_prop" ,
21
+ "_shopify_function_input_get_obj_prop" ,
22
+ ) ,
23
+ (
24
+ "shopify_function_input_get_interned_obj_prop" ,
25
+ "_shopify_function_input_get_interned_obj_prop" ,
26
+ ) ,
27
+ (
28
+ "shopify_function_input_get_at_index" ,
29
+ "_shopify_function_input_get_at_index" ,
30
+ ) ,
31
+ (
32
+ "shopify_function_input_get_obj_key_at_index" ,
33
+ "_shopify_function_input_get_obj_key_at_index" ,
34
+ ) ,
35
+ (
36
+ "shopify_function_output_new_bool" ,
37
+ "_shopify_function_output_new_bool" ,
38
+ ) ,
39
+ (
40
+ "shopify_function_output_new_null" ,
41
+ "_shopify_function_output_new_null" ,
42
+ ) ,
43
+ (
44
+ "shopify_function_output_finalize" ,
45
+ "_shopify_function_output_finalize" ,
46
+ ) ,
47
+ (
48
+ "shopify_function_output_new_i32" ,
49
+ "_shopify_function_output_new_i32" ,
50
+ ) ,
51
+ (
52
+ "shopify_function_output_new_f64" ,
53
+ "_shopify_function_output_new_f64" ,
54
+ ) ,
55
+ (
56
+ "shopify_function_output_new_utf8_str" ,
57
+ "_shopify_function_output_new_utf8_str" ,
58
+ ) ,
59
+ (
60
+ "shopify_function_intern_utf8_str" ,
61
+ "_shopify_function_intern_utf8_str" ,
62
+ ) ,
63
+ (
64
+ "shopify_function_output_new_interned_utf8_str" ,
65
+ "_shopify_function_output_new_interned_utf8_str" ,
66
+ ) ,
67
+ (
68
+ "shopify_function_output_new_object" ,
69
+ "_shopify_function_output_new_object" ,
70
+ ) ,
71
+ (
72
+ "shopify_function_output_finish_object" ,
73
+ "_shopify_function_output_finish_object" ,
74
+ ) ,
75
+ (
76
+ "shopify_function_output_new_array" ,
77
+ "_shopify_function_output_new_array" ,
78
+ ) ,
79
+ (
80
+ "shopify_function_output_finish_array" ,
81
+ "_shopify_function_output_finish_array" ,
82
+ ) ,
83
+ ] ;
84
+
8
85
pub const PROVIDER_MODULE_NAME : & str =
9
86
concat ! ( "shopify_function_v" , env!( "CARGO_PKG_VERSION_MAJOR" ) ) ;
10
87
@@ -366,79 +443,31 @@ impl TrampolineCodegen {
366
443
}
367
444
368
445
pub fn apply ( mut self ) -> walrus:: Result < Module > {
369
- self . rename_imported_func (
370
- "shopify_function_context_new" ,
371
- "_shopify_function_context_new" ,
372
- ) ?;
373
- self . rename_imported_func ( "shopify_function_input_get" , "_shopify_function_input_get" ) ?;
374
- self . rename_imported_func (
375
- "shopify_function_input_get_val_len" ,
376
- "_shopify_function_input_get_val_len" ,
377
- ) ?;
378
- self . emit_shopify_function_input_read_utf8_str ( ) ?;
379
- self . emit_shopify_function_input_get_obj_prop ( ) ?;
380
- self . rename_imported_func (
381
- "shopify_function_input_get_interned_obj_prop" ,
382
- "_shopify_function_input_get_interned_obj_prop" ,
383
- ) ?;
384
- self . rename_imported_func (
385
- "shopify_function_input_get_at_index" ,
386
- "_shopify_function_input_get_at_index" ,
387
- ) ?;
388
- self . rename_imported_func (
389
- "shopify_function_input_get_obj_key_at_index" ,
390
- "_shopify_function_input_get_obj_key_at_index" ,
391
- ) ?;
392
- self . rename_imported_func (
393
- "shopify_function_output_new_bool" ,
394
- "_shopify_function_output_new_bool" ,
395
- ) ?;
396
- self . rename_imported_func (
397
- "shopify_function_output_new_null" ,
398
- "_shopify_function_output_new_null" ,
399
- ) ?;
400
- self . rename_imported_func (
401
- "shopify_function_output_finalize" ,
402
- "_shopify_function_output_finalize" ,
403
- ) ?;
404
- self . rename_imported_func (
405
- "shopify_function_output_new_i32" ,
406
- "_shopify_function_output_new_i32" ,
407
- ) ?;
408
- self . rename_imported_func (
409
- "shopify_function_output_new_f64" ,
410
- "_shopify_function_output_new_f64" ,
411
- ) ?;
412
- self . emit_shopify_function_output_new_utf8_str ( ) ?;
413
- self . emit_shopify_function_intern_utf8_str ( ) ?;
414
- self . rename_imported_func (
415
- "shopify_function_output_new_interned_utf8_str" ,
416
- "_shopify_function_output_new_interned_utf8_str" ,
417
- ) ?;
418
- self . rename_imported_func (
419
- "shopify_function_output_new_object" ,
420
- "_shopify_function_output_new_object" ,
421
- ) ?;
422
- self . rename_imported_func (
423
- "shopify_function_output_finish_object" ,
424
- "_shopify_function_output_finish_object" ,
425
- ) ?;
426
- self . rename_imported_func (
427
- "shopify_function_output_new_array" ,
428
- "_shopify_function_output_new_array" ,
429
- ) ?;
430
- self . rename_imported_func (
431
- "shopify_function_output_finish_array" ,
432
- "_shopify_function_output_finish_array" ,
433
- ) ?;
446
+ for ( original, new) in IMPORTS {
447
+ match * original {
448
+ "shopify_function_input_read_utf8_str" => {
449
+ self . emit_shopify_function_input_read_utf8_str ( ) ?
450
+ }
451
+ "shopify_function_input_get_obj_prop" => {
452
+ self . emit_shopify_function_input_get_obj_prop ( ) ?
453
+ }
454
+ "shopify_function_output_new_utf8_str" => {
455
+ self . emit_shopify_function_output_new_utf8_str ( ) ?
456
+ }
457
+ "shopify_function_intern_utf8_str" => {
458
+ self . emit_shopify_function_intern_utf8_str ( ) ?
459
+ }
460
+ original => self . rename_imported_func ( original, new) ?,
461
+ } ;
462
+ }
434
463
435
464
Ok ( self . module )
436
465
}
437
466
}
438
467
439
468
#[ cfg( test) ]
440
469
mod test {
441
- use super :: TrampolineCodegen ;
470
+ use super :: { TrampolineCodegen , IMPORTS , PROVIDER_MODULE_NAME } ;
442
471
use walrus:: Module ;
443
472
444
473
#[ test]
@@ -456,4 +485,14 @@ mod test {
456
485
insta:: assert_snapshot!( actual) ;
457
486
} ) ;
458
487
}
488
+
489
+ #[ test]
490
+ fn test_consumer_imports_the_entire_api_surface ( ) {
491
+ let input = include_bytes ! ( "test_data/consumer.wat" ) ;
492
+ let buf = wat:: parse_bytes ( input) . unwrap ( ) ;
493
+ let module = Module :: from_buffer ( & buf) . unwrap ( ) ;
494
+ for ( import, _) in IMPORTS {
495
+ assert ! ( module. imports. find( PROVIDER_MODULE_NAME , import) . is_some( ) ) ;
496
+ }
497
+ }
459
498
}
0 commit comments