Skip to content

Commit d3146c3

Browse files
committed
fix: Windows installer now finds pre-built .exe binaries from release archive
1 parent 2430008 commit d3146c3

File tree

1 file changed

+53
-22
lines changed

1 file changed

+53
-22
lines changed

cmd/install/main.go

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,68 @@ func installRuntimeBinaries() {
7070
{"index-all", "./cmd/index-all"},
7171
}
7272

73-
missing := false
73+
// Check which binaries are missing from the install directory
74+
var missingBinaries []struct {
75+
name string
76+
pkg string
77+
}
7478
for _, bin := range binaries {
75-
if _, err := os.Stat(filepath.Join(binDir, bin.name)); os.IsNotExist(err) {
76-
missing = true
77-
break
79+
binName := bin.name
80+
if runtime.GOOS == "windows" {
81+
binName += ".exe"
82+
}
83+
if _, err := os.Stat(filepath.Join(binDir, binName)); os.IsNotExist(err) {
84+
missingBinaries = append(missingBinaries, bin)
7885
}
7986
}
8087

81-
if !missing {
88+
if len(missingBinaries) == 0 {
8289
success(fmt.Sprintf("Runtime binaries already installed in %s", binDir))
8390
return
8491
}
8592

86-
if _, err := exec.LookPath("go"); err != nil {
87-
fail("Go toolchain is required to build RagCode binaries. Install Go from https://go.dev/doc/install or rerun without --skip-build once binaries exist.")
88-
}
93+
log(fmt.Sprintf("Installing runtime binaries into %s...", binDir))
94+
for _, bin := range missingBinaries {
95+
binName := bin.name
96+
if runtime.GOOS == "windows" {
97+
binName += ".exe"
98+
}
99+
output := filepath.Join(binDir, binName)
89100

90-
log(fmt.Sprintf("Building RagCode binaries into %s...", binDir))
91-
for _, bin := range binaries {
92-
log(fmt.Sprintf(" - Building %s", bin.name))
93-
output := filepath.Join(binDir, bin.name)
94-
cmd := exec.Command("go", "build", "-o", output, bin.pkg)
95-
cmd.Stdout = os.Stdout
96-
cmd.Stderr = os.Stderr
97-
if err := cmd.Run(); err != nil {
98-
fail(fmt.Sprintf("Failed to build %s: %v", bin.name, err))
99-
}
100-
if err := os.Chmod(output, 0755); err != nil {
101-
fail(fmt.Sprintf("Failed to set executable bit on %s: %v", output, err))
102-
}
103-
success(fmt.Sprintf("Installed %s", output))
101+
// Option 1: Check if pre-built binary exists in current directory (from release archive)
102+
if _, err := os.Stat(binName); err == nil {
103+
log(fmt.Sprintf(" - Found %s in current directory, copying...", binName))
104+
if err := copyFile(binName, output); err != nil {
105+
fail(fmt.Sprintf("Failed to copy %s: %v", binName, err))
106+
}
107+
if err := os.Chmod(output, 0755); err != nil {
108+
warn(fmt.Sprintf("Could not set executable flag on %s: %v", binName, err))
109+
}
110+
success(fmt.Sprintf("Installed %s", output))
111+
continue
112+
}
113+
114+
// Option 2: Fallback to building from source if Go is available and source exists
115+
if _, err := os.Stat(bin.pkg); err == nil {
116+
if _, err := exec.LookPath("go"); err != nil {
117+
fail(fmt.Sprintf("Binary %s not found and Go toolchain is not available. Please download the complete release archive from:\nhttps://github.com/doITmagic/rag-code-mcp/releases/latest", binName))
118+
}
119+
log(fmt.Sprintf(" - Building %s from source...", bin.name))
120+
cmd := exec.Command("go", "build", "-o", output, bin.pkg)
121+
cmd.Stdout = os.Stdout
122+
cmd.Stderr = os.Stderr
123+
if err := cmd.Run(); err != nil {
124+
fail(fmt.Sprintf("Failed to build %s: %v", bin.name, err))
125+
}
126+
if err := os.Chmod(output, 0755); err != nil {
127+
fail(fmt.Sprintf("Failed to set executable bit on %s: %v", output, err))
128+
}
129+
success(fmt.Sprintf("Built and installed %s", output))
130+
continue
131+
}
132+
133+
// Neither pre-built binary nor source found
134+
fail(fmt.Sprintf("Binary %s not found in current directory and source not available. Please download the complete release archive from:\nhttps://github.com/doITmagic/rag-code-mcp/releases/latest", binName))
104135
}
105136
}
106137

0 commit comments

Comments
 (0)