@@ -105,13 +105,17 @@ func (s *PluginServe) writeTablesJSON(ctx context.Context, dir string) error {
105105func (s * PluginServe ) build (pluginDirectory , goos , goarch , distPath , pluginVersion string ) (* TargetBuild , error ) {
106106 pluginName := fmt .Sprintf ("plugin-%s-%s-%s-%s" , s .plugin .Name (), pluginVersion , goos , goarch )
107107 pluginPath := path .Join (distPath , pluginName )
108- args := []string {"build" , "-o" , pluginPath }
109108 importPath , err := s .getModuleName (pluginDirectory )
110109 if err != nil {
111110 return nil , err
112111 }
112+ ldFlags := fmt .Sprintf ("-s -w -X %s/plugin.Version=%s" , importPath , pluginVersion )
113+ if s .plugin .IsStaticLinkingEnabled () {
114+ ldFlags += " -linkmode external -extldflags=-static"
115+ }
116+ args := []string {"build" , "-o" , pluginPath }
113117 args = append (args , "-buildmode=exe" )
114- args = append (args , "-ldflags" , fmt . Sprintf ( "-s -w -X %s/plugin.Version=%s" , importPath , pluginVersion ) )
118+ args = append (args , "-ldflags" , ldFlags )
115119 cmd := exec .Command ("go" , args ... )
116120 cmd .Dir = pluginDirectory
117121 cmd .Stdout = os .Stdout
0 commit comments