@@ -854,6 +854,33 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
854854 }
855855 }
856856
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+
857884 // Print code size if requested.
858885 if config .Options .PrintSizes == "short" || config .Options .PrintSizes == "full" {
859886 packagePathMap := make (map [string ]string , len (lprogram .Packages ))
@@ -1051,9 +1078,10 @@ func createEmbedObjectFile(data, hexSum, sourceFile, sourceDir, tmpdir string, c
10511078// needed to convert a program to its final form. Some transformations are not
10521079// optional and must be run as the compiler expects them to run.
10531080func 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+ }
10571085 }
10581086 if config .VerifyIR () {
10591087 // Only verify if we really need it.
@@ -1069,7 +1097,7 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config, globalValues m
10691097 }
10701098
10711099 // Insert values from -ldflags="-X ..." into the IR.
1072- err = setGlobalValues (mod , globalValues )
1100+ err : = setGlobalValues (mod , globalValues )
10731101 if err != nil {
10741102 return err
10751103 }
0 commit comments