Skip to content

Commit e50cd3f

Browse files
committed
Merge branch 'develop'
2 parents d4ccb4e + 7ca7188 commit e50cd3f

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

AGENT_DOCS/PLANS/BUILD_JOB.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ The build system will target the following architectures:
4040

4141
## Implementation Plan
4242

43+
### Key Technical Challenges and Solutions
44+
45+
#### Cross-Platform Binary Embedding
46+
47+
**Challenge**: The `go:embed` directive requires files to exist at compile time with exact path matches. On Windows, the ast-grep binary is downloaded as `ast-grep.exe`, but the embed directive looks for `bin/ast-grep`.
48+
49+
**Solution**: Platform-specific handling in the GitHub Actions workflow:
50+
- **Linux/macOS**: Extract binary directly to `cmd/server/bin/ast-grep`
51+
- **Windows**: Extract to temporary directory, then copy `ast-grep.exe` to `cmd/server/bin/ast-grep` (removing .exe extension)
52+
53+
This ensures the embedded binary works across all platforms while maintaining a consistent internal file structure.
54+
55+
#### PowerShell Archive Extraction Issues
56+
57+
**Challenge**: Initial attempts using `7z` for Windows extraction failed due to PowerShell parameter parsing conflicts.
58+
59+
**Solution**: Switched to PowerShell's built-in `Expand-Archive` cmdlet, which is more reliable in the GitHub Actions PowerShell environment and handles parameter parsing correctly.
60+
4361
### Phase 1: Local Build Infrastructure
4462

4563
#### 1.1 Makefile Creation
@@ -248,10 +266,37 @@ jobs:
248266
with:
249267
go-version-file: go.mod
250268

251-
- name: Download ast-grep binary
269+
- name: Download ast-grep binary (Linux/macOS)
270+
if: matrix.os != 'windows-latest'
271+
run: |
272+
curl -L -o ast-grep.zip https://github.com/ast-grep/ast-grep/releases/download/0.39.5/${{ matrix.ast_grep_asset }}
273+
unzip -o ast-grep.zip -d cmd/server/bin/
274+
if [ -f "cmd/server/bin/ast-grep" ]; then
275+
echo "ast-grep binary ready"
276+
else
277+
echo "Error: No ast-grep binary found after extraction"
278+
exit 1
279+
fi
280+
rm ast-grep.zip
281+
282+
- name: Download ast-grep binary (Windows)
283+
if: matrix.os == 'windows-latest'
252284
run: |
253-
curl -L -o ast-grep.zip https://github.com/ast-grep/ast-grep/releases/latest/download/${{ matrix.ast_grep_asset }}
254-
# Extract and place in cmd/server/bin/
285+
$AST_GREP_URL = "https://github.com/ast-grep/ast-grep/releases/download/0.39.5/${{ matrix.ast_grep_asset }}"
286+
curl.exe -L -o ast-grep.zip $AST_GREP_URL
287+
# Extract to temp directory and copy .exe file to expected location
288+
Expand-Archive -Path ast-grep.zip -DestinationPath ./temp_extract -Force
289+
$exeFile = Get-ChildItem -Path ./temp_extract -Recurse -Filter *.exe | Select-Object -First 1
290+
if ($exeFile) {
291+
Copy-Item -Path $exeFile.FullName -Destination "cmd/server/bin/ast-grep" -Force
292+
Write-Host "Copied $($exeFile.Name) to cmd/server/bin/ast-grep"
293+
} else {
294+
Write-Host "Error: ast-grep.exe not found in the extracted archive."
295+
Get-ChildItem -Path ./temp_extract -Recurse | ForEach-Object { Write-Host " $($_.FullName)" }
296+
exit 1
297+
}
298+
Remove-Item -Recurse -Force ./temp_extract
299+
Remove-Item ast-grep.zip
255300
256301
- name: Build binary
257302
run: |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ If you prefer to build from source, you will need to have Go installed on your s
108108
1. **Download the `ast-grep` binary**:
109109
- Go to the [`ast-grep` releases page](https://github.com/ast-grep/ast-grep/releases/latest).
110110
- Download the binary appropriate for your target platform and architecture.
111-
- Place the binary in the `cmd/server/bin/` directory and rename it to `sg`.
111+
- Place the binary in the `cmd/server/bin/` directory with the name `ast-grep` (on Windows, rename `ast-grep.exe` to `ast-grep`).
112112

113113
2. **Build the server**:
114114
- Open your terminal in the project root directory.

0 commit comments

Comments
 (0)