@@ -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 ))
@@ -1036,9 +1063,10 @@ func createEmbedObjectFile(data, hexSum, sourceFile, sourceDir, tmpdir string, c
10361063// needed to convert a program to its final form. Some transformations are not
10371064// optional and must be run as the compiler expects them to run.
10381065func 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+ }
10421070 }
10431071 if config .VerifyIR () {
10441072 // Only verify if we really need it.
@@ -1054,7 +1082,7 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config) error {
10541082 }
10551083
10561084 // Insert values from -ldflags="-X ..." into the IR.
1057- err = setGlobalValues (mod , config .Options .GlobalValues )
1085+ err : = setGlobalValues (mod , config .Options .GlobalValues )
10581086 if err != nil {
10591087 return err
10601088 }
0 commit comments