@@ -854,6 +854,33 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
854
854
}
855
855
}
856
856
857
+ if config .Options .WizerInit {
858
+ var args []string
859
+
860
+ resultWizer := result .Executable + "-wizer"
861
+
862
+ args = append (args ,
863
+ "--allow-wasi" ,
864
+ "--wasm-bulk-memory=true" ,
865
+ "-f" , "runtime.wizerInit" ,
866
+ result .Executable ,
867
+ "-o" , resultWizer ,
868
+ )
869
+
870
+ cmd := exec .Command (goenv .Get ("WIZER" ), args ... )
871
+ cmd .Stdout = os .Stdout
872
+ cmd .Stderr = os .Stderr
873
+
874
+ err := cmd .Run ()
875
+ if err != nil {
876
+ return fmt .Errorf ("wizer failed: %w" , err )
877
+ }
878
+
879
+ if err := os .Rename (resultWizer , result .Executable ); err != nil {
880
+ return fmt .Errorf ("rename failed: %w" , err )
881
+ }
882
+ }
883
+
857
884
// Print code size if requested.
858
885
if config .Options .PrintSizes == "short" || config .Options .PrintSizes == "full" {
859
886
packagePathMap := make (map [string ]string , len (lprogram .Packages ))
@@ -1051,9 +1078,10 @@ func createEmbedObjectFile(data, hexSum, sourceFile, sourceDir, tmpdir string, c
1051
1078
// needed to convert a program to its final form. Some transformations are not
1052
1079
// optional and must be run as the compiler expects them to run.
1053
1080
func optimizeProgram (mod llvm.Module , config * compileopts.Config , globalValues map [string ]map [string ]string ) error {
1054
- err := interp .Run (mod , config .Options .InterpTimeout , config .DumpSSA ())
1055
- if err != nil {
1056
- return err
1081
+ if ! config .Options .WizerInit {
1082
+ if err := interp .Run (mod , config .Options .InterpTimeout , config .DumpSSA ()); err != nil {
1083
+ return err
1084
+ }
1057
1085
}
1058
1086
if config .VerifyIR () {
1059
1087
// Only verify if we really need it.
@@ -1069,7 +1097,7 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config, globalValues m
1069
1097
}
1070
1098
1071
1099
// Insert values from -ldflags="-X ..." into the IR.
1072
- err = setGlobalValues (mod , globalValues )
1100
+ err : = setGlobalValues (mod , globalValues )
1073
1101
if err != nil {
1074
1102
return err
1075
1103
}
0 commit comments