Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugin/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func WithJSONSchema(schema string) Option {
}
}

func WithStaticLinking() Option {
return func(p *Plugin) {
p.staticLinking = true
}
}

type TableOptions struct {
Tables []string
SkipTables []string
Expand Down
7 changes: 7 additions & 0 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type Plugin struct {
targets []BuildTarget
// Called upon init call to validate and init configuration
newClient NewClientFunc
// staticLinking true if C libraries should be added to compiled executable
staticLinking bool
// Logger to call, this logger is passed to the serve.Serve Client, if not defined Serve will create one instead.
logger zerolog.Logger
// mu is a mutex that limits the number of concurrent init/syncs (can only be one at a time)
Expand Down Expand Up @@ -108,6 +110,11 @@ func (p *Plugin) Version() string {
return p.version
}

// IsStaticLinkingEnabled whether static linking is to be enabled
func (p *Plugin) IsStaticLinkingEnabled() bool {
return p.staticLinking
}

func (p *Plugin) Targets() []BuildTarget {
return p.targets
}
Expand Down
8 changes: 6 additions & 2 deletions serve/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ func (s *PluginServe) writeTablesJSON(ctx context.Context, dir string) error {
func (s *PluginServe) build(pluginDirectory, goos, goarch, distPath, pluginVersion string) (*TargetBuild, error) {
pluginName := fmt.Sprintf("plugin-%s-%s-%s-%s", s.plugin.Name(), pluginVersion, goos, goarch)
pluginPath := path.Join(distPath, pluginName)
args := []string{"build", "-o", pluginPath}
importPath, err := s.getModuleName(pluginDirectory)
if err != nil {
return nil, err
}
ldFlags := fmt.Sprintf("-s -w -X %s/plugin.Version=%s", importPath, pluginVersion)
if s.plugin.IsStaticLinkingEnabled() {
ldFlags += " -linkmode external -extldflags=-static"
}
args := []string{"build", "-o", pluginPath}
args = append(args, "-buildmode=exe")
args = append(args, "-ldflags", fmt.Sprintf("-s -w -X %s/plugin.Version=%s", importPath, pluginVersion))
args = append(args, "-ldflags", ldFlags)
cmd := exec.Command("go", args...)
cmd.Dir = pluginDirectory
cmd.Stdout = os.Stdout
Expand Down