@@ -834,6 +834,33 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
834834 }
835835 }
836836
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+
837864 // Print code size if requested.
838865 if config .Options .PrintSizes == "short" || config .Options .PrintSizes == "full" {
839866 packagePathMap := make (map [string ]string , len (lprogram .Packages ))
@@ -1031,9 +1058,10 @@ func createEmbedObjectFile(data, hexSum, sourceFile, sourceDir, tmpdir string, c
10311058// needed to convert a program to its final form. Some transformations are not
10321059// optional and must be run as the compiler expects them to run.
10331060func 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+ }
10371065 }
10381066 if config .VerifyIR () {
10391067 // Only verify if we really need it.
@@ -1049,7 +1077,7 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config) error {
10491077 }
10501078
10511079 // Insert values from -ldflags="-X ..." into the IR.
1052- err = setGlobalValues (mod , config .Options .GlobalValues )
1080+ err : = setGlobalValues (mod , config .Options .GlobalValues )
10531081 if err != nil {
10541082 return err
10551083 }
0 commit comments