@@ -834,6 +834,33 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
834
834
}
835
835
}
836
836
837
+ if config .Options .WizerInit {
838
+ var args []string
839
+
840
+ resultWizer := result .Executable + "-wizer"
841
+
842
+ args = append (args ,
843
+ "--allow-wasi" ,
844
+ "--wasm-bulk-memory=true" ,
845
+ "-f" , "runtime.wizerInit" ,
846
+ result .Executable ,
847
+ "-o" , resultWizer ,
848
+ )
849
+
850
+ cmd := exec .Command (goenv .Get ("WIZER" ), args ... )
851
+ cmd .Stdout = os .Stdout
852
+ cmd .Stderr = os .Stderr
853
+
854
+ err := cmd .Run ()
855
+ if err != nil {
856
+ return fmt .Errorf ("wizer failed: %w" , err )
857
+ }
858
+
859
+ if err := os .Rename (resultWizer , result .Executable ); err != nil {
860
+ return fmt .Errorf ("rename failed: %w" , err )
861
+ }
862
+ }
863
+
837
864
// Print code size if requested.
838
865
if config .Options .PrintSizes == "short" || config .Options .PrintSizes == "full" {
839
866
packagePathMap := make (map [string ]string , len (lprogram .Packages ))
@@ -1036,9 +1063,10 @@ func createEmbedObjectFile(data, hexSum, sourceFile, sourceDir, tmpdir string, c
1036
1063
// needed to convert a program to its final form. Some transformations are not
1037
1064
// optional and must be run as the compiler expects them to run.
1038
1065
func optimizeProgram (mod llvm.Module , config * compileopts.Config ) error {
1039
- err := interp .Run (mod , config .Options .InterpTimeout , config .DumpSSA ())
1040
- if err != nil {
1041
- return err
1066
+ if ! config .Options .WizerInit {
1067
+ if err := interp .Run (mod , config .Options .InterpTimeout , config .DumpSSA ()); err != nil {
1068
+ return err
1069
+ }
1042
1070
}
1043
1071
if config .VerifyIR () {
1044
1072
// Only verify if we really need it.
@@ -1054,7 +1082,7 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config) error {
1054
1082
}
1055
1083
1056
1084
// Insert values from -ldflags="-X ..." into the IR.
1057
- err = setGlobalValues (mod , config .Options .GlobalValues )
1085
+ err : = setGlobalValues (mod , config .Options .GlobalValues )
1058
1086
if err != nil {
1059
1087
return err
1060
1088
}
0 commit comments