44mod documentation_site;
55
66use std:: {
7+ collections:: { BTreeMap , BTreeSet } ,
78 env, fs,
89 path:: { Path , PathBuf } ,
910 process:: { Command , ExitCode } ,
1011} ;
1112
13+ #[ derive( Clone , Copy ) ]
1214struct RuntimeFixture {
1315 source : & ' static str ,
1416 output : & ' static str ,
@@ -17,13 +19,30 @@ struct RuntimeFixture {
1719 extra_arguments : & ' static [ & ' static str ] ,
1820}
1921
22+ #[ derive( Clone , Copy ) ]
2023struct CompileFixture {
2124 source : & ' static str ,
2225 output : & ' static str ,
2326 profile : & ' static str ,
2427}
2528
26- const COMPILE_FIXTURES : & [ CompileFixture ] = & [ ] ;
29+ const COMPILE_FIXTURES : & [ CompileFixture ] = & [
30+ CompileFixture {
31+ source : "examples/lunistice.split" ,
32+ output : "lunistice.release.wasm" ,
33+ profile : "release" ,
34+ } ,
35+ CompileFixture {
36+ source : "tests/debug_profile.split" ,
37+ output : "debug_profile.debug.wasm" ,
38+ profile : "debug" ,
39+ } ,
40+ CompileFixture {
41+ source : "tests/debug_profile.split" ,
42+ output : "debug_profile.release.wasm" ,
43+ profile : "release" ,
44+ } ,
45+ ] ;
2746
2847const RUNTIME_FIXTURES : & [ RuntimeFixture ] = & [
2948 RuntimeFixture {
@@ -847,16 +866,13 @@ fn check() -> Result<(), String> {
847866 } else {
848867 "target/debug/splitc"
849868 } ) ;
850- for fixture in RUNTIME_FIXTURES {
851- compile_once (
852- & root,
853- & compiler,
854- fixture. source ,
855- & outputs. join ( fixture. output ) ,
856- fixture. profile ,
857- ) ?;
858- }
859- for fixture in COMPILE_FIXTURES {
869+ let artifacts = verification_artifacts ( RUNTIME_FIXTURES , COMPILE_FIXTURES ) ?;
870+ println ! (
871+ "compiling {} unique verification artifacts for {} runtime scenarios" ,
872+ artifacts. len( ) ,
873+ RUNTIME_FIXTURES . len( )
874+ ) ;
875+ for fixture in & artifacts {
860876 compile_once (
861877 & root,
862878 & compiler,
@@ -865,48 +881,14 @@ fn check() -> Result<(), String> {
865881 fixture. profile ,
866882 ) ?;
867883 }
868- let lunistice_release = outputs. join ( "lunistice.release.wasm" ) ;
869- compile_once (
870- & root,
871- & compiler,
872- "examples/lunistice.split" ,
873- & lunistice_release,
874- "release" ,
875- ) ?;
876884 let debug = outputs. join ( "debug_profile.debug.wasm" ) ;
877885 let release = outputs. join ( "debug_profile.release.wasm" ) ;
878- compile_once (
879- & root,
880- & compiler,
881- "tests/debug_profile.split" ,
882- & debug,
883- "debug" ,
884- ) ?;
885- compile_once (
886- & root,
887- & compiler,
888- "tests/debug_profile.split" ,
889- & release,
890- "release" ,
891- ) ?;
892886
893- let mut validated = RUNTIME_FIXTURES
894- . iter ( )
895- . map ( |fixture| outputs. join ( fixture. output ) )
896- . collect :: < Vec < _ > > ( ) ;
897- validated. extend (
898- COMPILE_FIXTURES
899- . iter ( )
900- . map ( |fixture| outputs. join ( fixture. output ) ) ,
901- ) ;
902- validated. extend ( [ lunistice_release, debug. clone ( ) , release. clone ( ) ] ) ;
903- validated. sort ( ) ;
904- validated. dedup ( ) ;
905- for module in & validated {
887+ for module in artifacts. iter ( ) . map ( |fixture| outputs. join ( fixture. output ) ) {
906888 run (
907889 & root,
908890 "wasm-tools" ,
909- & [ "validate" , "--features" , "all" , path_text ( module) ?] ,
891+ & [ "validate" , "--features" , "all" , path_text ( & module) ?] ,
910892 ) ?;
911893 }
912894
@@ -929,6 +911,57 @@ fn check() -> Result<(), String> {
929911 Ok ( ( ) )
930912}
931913
914+ fn verification_artifacts (
915+ runtime_fixtures : & [ RuntimeFixture ] ,
916+ compile_fixtures : & [ CompileFixture ] ,
917+ ) -> Result < Vec < CompileFixture > , String > {
918+ let mut scenarios = BTreeSet :: new ( ) ;
919+ for fixture in runtime_fixtures {
920+ if !scenarios. insert ( (
921+ fixture. source ,
922+ fixture. output ,
923+ fixture. profile ,
924+ fixture. harness ,
925+ fixture. extra_arguments ,
926+ ) ) {
927+ return Err ( format ! (
928+ "duplicate runtime scenario for `{}` with harness `{}` and arguments {:?}" ,
929+ fixture. output, fixture. harness, fixture. extra_arguments
930+ ) ) ;
931+ }
932+ }
933+
934+ let mut artifacts = BTreeMap :: new ( ) ;
935+ for fixture in runtime_fixtures. iter ( ) . map ( |fixture| CompileFixture {
936+ source : fixture. source ,
937+ output : fixture. output ,
938+ profile : fixture. profile ,
939+ } ) {
940+ insert_artifact ( & mut artifacts, fixture) ?;
941+ }
942+ for & fixture in compile_fixtures {
943+ insert_artifact ( & mut artifacts, fixture) ?;
944+ }
945+ Ok ( artifacts. into_values ( ) . collect ( ) )
946+ }
947+
948+ fn insert_artifact (
949+ artifacts : & mut BTreeMap < & ' static str , CompileFixture > ,
950+ fixture : CompileFixture ,
951+ ) -> Result < ( ) , String > {
952+ if let Some ( previous) = artifacts. get ( fixture. output ) {
953+ if previous. source != fixture. source || previous. profile != fixture. profile {
954+ return Err ( format ! (
955+ "conflicting artifact `{}`: `{}` ({}) and `{}` ({})" ,
956+ fixture. output, previous. source, previous. profile, fixture. source, fixture. profile
957+ ) ) ;
958+ }
959+ } else {
960+ artifacts. insert ( fixture. output , fixture) ;
961+ }
962+ Ok ( ( ) )
963+ }
964+
932965fn compile_once (
933966 root : & Path ,
934967 compiler : & Path ,
0 commit comments