@@ -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 ))
@@ -1031,9 +1058,10 @@ func createEmbedObjectFile(data, hexSum, sourceFile, sourceDir, tmpdir string, c
1031
1058
// needed to convert a program to its final form. Some transformations are not
1032
1059
// optional and must be run as the compiler expects them to run.
1033
1060
func optimizeProgram (mod llvm.Module , config * compileopts.Config ) error {
1034
- err := interp .Run (mod , config .Options .InterpTimeout , config .DumpSSA ())
1035
- if err != nil {
1036
- return err
1061
+ if ! config .Options .WizerInit {
1062
+ if err := interp .Run (mod , config .Options .InterpTimeout , config .DumpSSA ()); err != nil {
1063
+ return err
1064
+ }
1037
1065
}
1038
1066
if config .VerifyIR () {
1039
1067
// Only verify if we really need it.
@@ -1049,7 +1077,7 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config) error {
1049
1077
}
1050
1078
1051
1079
// Insert values from -ldflags="-X ..." into the IR.
1052
- err = setGlobalValues (mod , config .Options .GlobalValues )
1080
+ err : = setGlobalValues (mod , config .Options .GlobalValues )
1053
1081
if err != nil {
1054
1082
return err
1055
1083
}
0 commit comments