Skip to content

Fix: fix golang packaging in windows #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
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
12 changes: 12 additions & 0 deletions pkg/engine/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strings"
Expand Down Expand Up @@ -202,6 +203,17 @@ func (e *Engine) newCommand(ctx context.Context, extraEnv []string, tool types.T
cmdArgs = append(cmdArgs, f.Name())
}

// This is a workaround for Windows, where the command interpreter is constructed with unix style paths
// It converts unix style paths to windows style paths
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only converts the first arg (which is ${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool)`. There could be some edge cases where the rest of the args contain unix path, which is not addressed here.

if runtime.GOOS == "windows" {
parts := strings.Split(args[0], "/")
if parts[len(parts)-1] == "gptscript-go-tool" {
parts[len(parts)-1] = "gptscript-go-tool.exe"
}

args[0] = filepath.Join(parts...)
}

cmd := exec.CommandContext(ctx, env.Lookup(envvars, args[0]), cmdArgs...)
cmd.Env = envvars
return cmd, stop, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (e *Engine) startDaemon(_ context.Context, tool types.Tool) (string, error)
e.Ports.daemonWG.Done()
})

for i := 0; i < 20; i++ {
for i := 0; i < 120; i++ {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to wait for more time to setup remote toolchain(like downloading runtime/pip install) before it can timeout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibuildthecloud The problem is that today when we use clicky-chat to download knowledge-api, the clicky-chat daemon will timeout first before it can download the other runtime(python). Ideally this timeout could probably be higher to give more time to download.

resp, err := http.Get(url)
if err == nil && resp.StatusCode == http.StatusOK {
go func() {
Expand Down
9 changes: 8 additions & 1 deletion pkg/repos/runtimes/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ func stripGo(env []string) (result []string) {

func (r *Runtime) runBuild(ctx context.Context, toolSource, binDir string, env []string) error {
log.Infof("Running go build in %s", toolSource)
cmd := debugcmd.New(ctx, filepath.Join(binDir, "go"), "build", "-buildvcs=false", "-o", "bin/gptscript-go-tool")
cmd := debugcmd.New(ctx, filepath.Join(binDir, "go"), "build", "-buildvcs=false", "-o", artifactName())
cmd.Env = stripGo(env)
cmd.Dir = toolSource
return cmd.Run()
}

func artifactName() string {
if runtime.GOOS == "windows" {
return filepath.Join("bin", "gptscript-go-tool.exe")
}
return filepath.Join("bin", "gptscript-go-tool")
}

func (r *Runtime) binDir(rel string) string {
return filepath.Join(rel, "go", "bin")
}
Expand Down