Skip to content

Commit

Permalink
add custom build arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
muazhari committed Jul 25, 2024
1 parent 2ff796e commit c8cae49
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion base/genimport/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Importer struct {
mode types.ImportMode
PluginOpen r.Value // = reflect.ValueOf(plugin.Open)
output *Output
BuildArgs []string
}

func DefaultImporter(o *Output) *Importer {
Expand Down Expand Up @@ -151,7 +152,7 @@ func (imp *Importer) doImportPackagesOrError(pathMap map[string]PackageName, ena
}
return refs, nil
}
soname := compilePlugin(o, dir, enableModule, o.Stdout, o.Stderr)
soname := compilePlugin(imp.BuildArgs, o, dir, enableModule, o.Stdout, o.Stderr)
ipkgs := imp.loadPluginSymbol(soname, "Packages")
pkgs := *ipkgs.(*map[string]imports.PackageUnderlying)

Expand Down
7 changes: 5 additions & 2 deletions base/genimport/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func chooseGoCmd() string {
return gocmd
}

func compilePlugin(o *Output, dir string, enableModule bool, stdout io.Writer, stderr io.Writer) string {
func compilePlugin(buildArgs []string, o *Output, dir string, enableModule bool, stdout io.Writer, stderr io.Writer) string {
gosrcdir := paths.GoSrcDir
gosrclen := len(gosrcdir)
dirlen := len(dir)
Expand All @@ -49,7 +49,10 @@ func compilePlugin(o *Output, dir string, enableModule bool, stdout io.Writer, s
}
gocmd := chooseGoCmd()

cmd := exec.Command(gocmd, "build", "-buildmode=plugin")
args := make([]string, 0)
args = append(args, "build", "-buildmode=plugin")
args = append(args, buildArgs...)
cmd := exec.Command(gocmd, args...)
cmd.Dir = dir
cmd.Env = environForCompiler(enableModule)
cmd.Stdin = nil
Expand Down
4 changes: 4 additions & 0 deletions fast/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func (ir *Interp) SetDebugger(debugger Debugger) {
ir.env.Run.Debugger = debugger
}

func (ir *Interp) SetBuildArgs(args []string) {
ir.Comp.Importer.BuildArgs = args
}

func (ir *Interp) Interrupt(os.Signal) {
ir.env.Run.interrupt()
}
Expand Down

0 comments on commit c8cae49

Please sign in to comment.