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
25 changes: 25 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Workspace-level Cargo configuration.
#
# This file is read by `cargo` invocations from the repository root (where CI
# runs `cargo build --release --target x86_64-pc-windows-gnu --bin codescope`).
# The per-crate `server/.cargo/config.toml` (profile/lto tuning) is NOT
# consulted for root-level builds, so cross-cutting target flags belong here.

[build]
# Use all available CPU cores for parallel compilation
jobs = -1

# Windows GNU target: statically link the MinGW runtime so `codescope.exe` is
# self-contained. This eliminates dynamic dependencies on libgcc_s_seh-1.dll,
# libstdc++-6.dll, and libwinpthread-1.dll — the root cause of:
# * ABI incompatibility between MinGW 14.0.0 (official release) and 16.1.0
# (local dev) runtime DLLs.
# * Access-violation crashes after SQLite init (heap/exception-model
# mismatch between the statically-linked engine and a mismatched runtime
# DLL on PATH).
# * System-wide DLL pollution (PowerShell memory access violations).
# `-static` makes the gcc linker prefer static archives for every `-l` flag;
# Windows system DLLs (KERNEL32 / msvcrt / ucrtbase / ADVAPI32) only ship as
# import libraries and are linked dynamically regardless, so they are unaffected.
[target.x86_64-pc-windows-gnu]
rustflags = ["-C", "link-arg=-static"]
38 changes: 29 additions & 9 deletions .github/workflows/_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,30 @@ jobs:

- name: Install deps (Windows)
if: matrix.os == 'windows-2022'
shell: bash
run: |
# Install MinGW-w64 toolchain (version pinned to match local dev: GCC 16.1.0)
choco install mingw --version=14.0.0 -y --no-progress
echo "C:\tools\mingw64\bin" >> $GITHUB_PATH
# WinLibs portable MinGW-w64: GCC 16.1.0 + MinGW-w64 14.0.0 + UCRT +
# SEH + POSIX threads (x86_64), pinned to match local dev toolchain.
#
# Why not chocolatey: the `mingw` chocolatey package version number
# does NOT correspond to the GCC version (package 14.0.0 ships a
# different GCC), so it cannot reliably pin GCC 16.1.0. WinLibs
# portable builds give a deterministic, exact toolchain. Combined
# with the static-link rustflags in .cargo/config.toml
# ([target.x86_64-pc-windows-gnu] -static), codescope.exe becomes
# self-contained and no longer depends on MinGW runtime DLLs, so
# the official release and local builds can no longer clash on
# libgcc_s_seh-1.dll / libstdc++-6.dll / libwinpthread-1.dll.
WINLIBS_URL="https://github.com/brechtsanders/winlibs_mingw/releases/download/16.1.0posix-14.0.0-ucrt-r3/winlibs-x86_64-posix-seh-gcc-16.1.0-mingw-w64ucrt-14.0.0-r3.7z"
curl -fsSL -o winlibs.7z "$WINLIBS_URL"
7z x winlibs.7z -o"C:/winlibs" -y -bd
echo "C:\winlibs\mingw64\bin" >> $GITHUB_PATH
# Add Rust Windows GNU target (Rust version pinned to 1.95.0 by dtolnay/rust-toolchain@1.95.0)
rustup target add x86_64-pc-windows-gnu
echo "CC=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV
echo "CXX=x86_64-w64-mingw32-g++" >> $GITHUB_ENV
echo "CC=gcc" >> $GITHUB_ENV
echo "CXX=g++" >> $GITHUB_ENV
# CMake 4.4.0 and Ninja 1.13.2 are pre-installed on GitHub Actions Windows runners
/C/winlibs/mingw64/bin/gcc --version

- name: Cache Cargo registry
uses: actions/cache@v6 # v4.2.3
Expand Down Expand Up @@ -279,12 +294,17 @@ jobs:
LBUG_FILE="liblbug.0.dylib"
;;
*-windows)
# Windows: bundle lbug_shared.dll next to the .exe
LBUG_LIB="engine/third_party/ladybug/lib/windows/lbug_shared.dll"
LBUG_FILE="lbug_shared.dll"
# Windows: LadybugDB is intentionally disabled (see
# engine/CMakeLists.txt — HAS_LADYBUG undefined). No shared
# library to bundle; graph storage uses SQLite only.
LBUG_LIB=""
;;
esac
cp -L "$LBUG_LIB" "package/$LBUG_FILE"
# Bundle LadybugDB shared lib (Linux/macOS only). Windows builds
# without LadybugDB, so LBUG_LIB is empty there — skip the copy.
if [ -n "$LBUG_LIB" ]; then
cp -L "$LBUG_LIB" "package/$LBUG_FILE"
fi
# Set rpath to $ORIGIN (Linux) / @executable_path (macOS) so the
# dynamic linker finds the bundled library in the same directory.
if [[ "${{ matrix.os }}" == ubuntu-* ]]; then
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Dev branch validation: cross-compile Windows binary from macOS runner
# to catch regressions in build.rs cross-compilation logic early.
name: Dev CI (Windows Cross-Compile)

on:
workflow_dispatch:
push:
branches: [hhh]

permissions:
contents: read

concurrency:
group: dev-ci-${{ github.sha }}
cancel-in-progress: true

jobs:
cross-compile-windows:
name: Cross-compile codescope.exe (macOS → Windows)
# Use macOS runner to test the macOS→Windows cross-compilation path
# (build.rs host-OS detection + MinGW cross-compiler selection).
# Native Windows builds are covered by the main CI on PR/main.
runs-on: macos-15
timeout-minutes: 30
steps:
- uses: actions/checkout@v7 # v4.2.2

- name: Setup Rust
uses: dtolnay/rust-toolchain@1.95.0 # pinned to match local dev

- name: Install MinGW cross-compiler
run: |
brew install mingw-w64
# Verify the cross-compiler is on PATH
x86_64-w64-mingw32-gcc --version

- name: Add Windows GNU target
run: rustup target add x86_64-pc-windows-gnu

- name: Cross-compile codescope.exe
run: cargo build --release --target x86_64-pc-windows-gnu --bin codescope

- name: Verify binary
run: |
ls -lh target/x86_64-pc-windows-gnu/release/codescope.exe
file target/x86_64-pc-windows-gnu/release/codescope.exe

- name: Check binary is PE (Windows executable)
run: |
file target/x86_64-pc-windows-gnu/release/codescope.exe | grep -i "PE32"
echo "✅ Windows cross-compile succeeded"
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# Changelog

## Unreleased
## v0.2.4 (2026-07-24)

Windows compilation stability — fully static-linked `codescope.exe` (zero MinGW runtime DLLs), LadybugDB disabled on Windows (SQLite-only), and critical cross-compilation bug fixes.

### 🚀 New Features

- **Fully static Windows binary**: `codescope.exe` statically links `libstdc++`, `libgcc`, and `libwinpthread` via `.cargo/config.toml` `-static` rustflag. Zero MinGW runtime DLL dependencies at runtime — no more `libstdc++-6.dll` / `libgcc_s_seh-1.dll` / `libwinpthread-1.dll` version conflicts. (`engine/CMakeLists.txt`, `server/build.rs`)
- **Dev branch CI for Windows**: New `.github/workflows/dev.yml` validates Windows cross-compilation on push to `dev` branch (manual `workflow_dispatch` also supported). (`dev.yml`)

### 🐛 Bug Fixes

- **Cross-compile host OS detection**: `build.rs` previously used `CARGO_CFG_TARGET_OS` to detect the build host, but during cross-compilation this returns the *target* OS ("windows"), causing `-DCMAKE_SYSTEM_NAME=Windows` to never be passed to CMake. Fixed to use `std::env::consts::OS` for the actual build host. (`server/build.rs`)
- **Cross-compile compiler selection**: `platform_default_compiler("windows")` returned `gcc`/`g++` on macOS, which resolves to native clang, not the MinGW cross-compiler. Fixed to detect cross-compilation and use `x86_64-w64-mingw32-gcc`/`x86_64-w64-mingw32-g++`. (`server/build.rs`)
- **Stale LadybugDB CMake cache on cross-compile**: The shared `build-release/` directory retained LadybugDB cache entries from a previous native macOS build. When cross-compiling to Windows, the stale macOS `.dylib` path was passed to the MinGW linker. Fixed by `unset(LADYBUG_LIBRARY CACHE)` in the Windows CMake branch and a Rust-side guard that skips all LadybugDB cache reading on Windows. (`engine/CMakeLists.txt`, `server/build.rs`)
- **LadybugDB now skipped on Windows**: The vendored `lbug_shared.lib` is a static archive of unverified MinGW ABI with no corresponding `.dll`. Windows builds now compile with `HAS_LADYBUG` undefined and use SQLite as the sole graph store. (`engine/CMakeLists.txt`)

### 🧹 Chores

- **Version bump**: 0.2.3 → 0.2.4
- **Windows support now explicitly documented as "beta"** in both README.md and README.zh.md.

---

## v0.2.3 (2026-07-21)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = 4

[[package]]
name = "codescope"
version = "0.2.3"
version = "0.2.4"
dependencies = [
"libc",
"once_cell",
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

It transforms source code into verifiable facts, understandable models, and inspectable evidence — enabling AI to validate claims against reality instead of hallucinating.

**Version**: v0.2.3 | **License**: Apache 2.0
**Version**: v0.2.4 | **License**: Apache 2.0

---

Expand Down Expand Up @@ -231,6 +231,7 @@ codescope cli force_index_files '{"paths":["/path/to/test/file.rs"]}'
|----------|-------------|
| **macOS** | Xcode CLT, cmake, Rust (1.85+) |
| **Linux** | build-essential, cmake, Rust (1.85+) |
| **Windows** ⚠️ **Beta** | MinGW-w64 14.0.0+, Rust `x86_64-pc-windows-gnu` target, cmake. LadybugDB/Cypher not available (SQLite-only). |

### Install Pre-built Binary

Expand Down Expand Up @@ -277,7 +278,7 @@ codescope index-parallel /path/to/large/project

---

## 4. MCP Tools (42 Tools)
## 5. MCP Tools (42 Tools)

### Indexing

Expand Down Expand Up @@ -401,7 +402,7 @@ Change impact → detect_changes

---

## 5. Knowledge Graph
## 6. Knowledge Graph

CodeScope builds a **module-level knowledge graph** as a side product of the verification pipeline. It learns structured metadata about how the project is organized, what's important, what's redundant, and what it promises:

Expand All @@ -426,7 +427,7 @@ Supported tables: `entity`, `relation`, `architecture_edge`, `module_edge`, `cap

---

## 6. Benchmark
## 7. Benchmark

All benchmarks measured on **Apple M3 Max (36 GB RAM)**. Other hardware will produce different results — expect slower performance on less capable machines.

Expand Down Expand Up @@ -501,7 +502,7 @@ Using code graphs instead of raw source files saves **~98.9% tokens** on average

---

## 7. Skills (Shell Wrappers)
## 8. Skills (Shell Wrappers)

The `skills/` directory provides shell scripts that wrap common CodeScope queries so you don't need to remember the JSON schema:

Expand Down Expand Up @@ -534,7 +535,7 @@ Each script calls `codescope cli <tool_name> '<json_args>'` internally. See `ski

---

## 8. Environment Variables
## 9. Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
Expand All @@ -552,8 +553,8 @@ Each script calls `codescope cli <tool_name> '<json_args>'` internally. See `ski

---

## 9. License
## 10. License

Apache 2.0 — see [LICENSE](LICENSE).

**CodeScope v0.2.3** — Built with Rust 2024 + C++23 + tree-sitter + SQLite.
**CodeScope v0.2.4** — Built with Rust 2024 + C++23 + tree-sitter + SQLite.
17 changes: 9 additions & 8 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

它将源代码转化为可验证的事实、可理解的模型和可检查的证据 — 让 AI 能够根据现实验证断言,而非凭空编造。

**版本**: v0.2.3 | **许可证**: Apache 2.0
**版本**: v0.2.4 | **许可证**: Apache 2.0

---

Expand Down Expand Up @@ -231,6 +231,7 @@ codescope cli force_index_files '{"paths":["/path/to/test/file.rs"]}'
|------|------|
| **macOS** | Xcode CLT, cmake, Rust (1.85+) |
| **Linux** | build-essential, cmake, Rust (1.85+) |
| **Windows** ⚠️ **Beta** | MinGW-w64 14.0.0+,Rust `x86_64-pc-windows-gnu` 目标,cmake。不支持 LadybugDB/Cypher(仅 SQLite)。|

### 安装预编译二进制

Expand Down Expand Up @@ -277,7 +278,7 @@ codescope index-parallel /path/to/large/project

---

## 4. MCP 工具(37 个工具)
## 5. MCP 工具(37 个工具)

### 索引

Expand Down Expand Up @@ -385,7 +386,7 @@ HTTP 路由 → get_routes

---

## 5. 知识图谱
## 6. 知识图谱

CodeScope 在验证管线的副产品中构建了一个**模块级知识图谱**。它学习的是结构化的元数据 — 项目如何组织、什么重要、什么冗余、承诺了什么:

Expand All @@ -410,7 +411,7 @@ get_knowledge_graph {"table":"capability","limit":10}

---

## 6. 性能基准
## 7. 性能基准

所有基准测试在 **Apple M3 Max(36 GB RAM)** 上测得。其他硬件会产生不同的结果 — 性能较低的机器上预期会慢一些。

Expand Down Expand Up @@ -484,7 +485,7 @@ get_knowledge_graph {"table":"capability","limit":10}

---

## 7. Skills(Shell 封装脚本)
## 8. Skills(Shell 封装脚本)

`skills/` 目录提供了一系列 Shell 脚本,封装了常用的 CodeScope 查询,无需记忆 JSON 参数格式:

Expand Down Expand Up @@ -517,7 +518,7 @@ cd CodeScope

---

## 8. 环境变量
## 9. 环境变量

| 变量 | 默认值 | 说明 |
|------|--------|------|
Expand All @@ -535,8 +536,8 @@ cd CodeScope

---

## 9. 许可证
## 10. 许可证

Apache 2.0 — 详见 [LICENSE](LICENSE)。

**CodeScope v0.2.3** — 使用 Rust 2024 + C++23 + tree-sitter + SQLite 构建。
**CodeScope v0.2.4** — 使用 Rust 2024 + C++23 + tree-sitter + SQLite 构建。
54 changes: 19 additions & 35 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,36 @@
## v0.2.3 (2026-07-21)
## v0.2.4 (2026-07-24)

Windows beta supportcross-compilation from macOS to `x86_64-pc-windows-gnu` (MinGW), vendored LadybugDB Windows DLL, and CI pipeline. Plus critical bug fixes for the v0.2.2 LadybugDB migration that broke all query tools.
Windows compilation stabilityfully static-linked `codescope.exe` (zero MinGW runtime DLLs), LadybugDB disabled on Windows (SQLite-only), and critical cross-compilation bug fixes.

### What changed

| Area | Before | After |
|------|--------|-------|
| **Windows support** | Not supported | Beta: cross-compiled `codescope.exe` (16MB PE32+), `lbug_shared.dll` bundled, CI `windows-2022` |
| **`search` tool** | Async FTS on `graph_nodes` (empty), returned no results | Synchronous `MATCH (n) WHERE n.name CONTAINS 'query'` via LadybugDB, ~1ms |
| **`isGraphReady()`** | Process-in-memory flag only (broken across worker/CLI processes) | Probes LadybugDB directly via `MATCH (n) RETURN count(*)` |
| **All query tools** | `findSymbolJson` prepare failed, `find_callers`/`find_callees` etc. "graph not ready" | All queries go through `entity`/`relation` tables or LadybugDB |
| **`graph_nodes`/`graph_edges`** | Still referenced by >20 SQL queries (returning empty) | Fully removed from all query paths. Tables still exist but unused |
| **`verify_integrity`** | Hangs indefinitely (no timeout) | 10s `QueryDeadlineGuard` |
| **`make fmt`** | Only checked recently modified files | Full project lint check (`lint-cpp-full`) |
| **Cross-compilation** | N/A | `build.rs` detects cross-compile vs native Windows, sets `CMAKE_SYSTEM_NAME` only when needed |
| **Windows runtime deps** | Depended on `libstdc++-6.dll`, `libgcc_s_seh-1.dll`, `libwinpthread-1.dll` — crash if MinGW version mismatched | Fully static via `-static` rustflag — single `codescope.exe` with zero MinGW DLL deps |
| **Windows LadybugDB** | Vendored `lbug_shared.lib` + `lbug_shared.dll` of unverified MinGW ABI | Disabled entirely — SQLite-only on Windows (`HAS_LADYBUG` undefined) |
| **Cross-compile host detection** | `build.rs` compared `CARGO_CFG_TARGET_OS` (returns *target* = "windows" during cross-compile) → `-DCMAKE_SYSTEM_NAME=Windows` never set | Uses `std::env::consts::OS` for actual build host |
| **Cross-compile compiler** | `platform_default_compiler("windows")` returned `gcc`/`g++` (macOS native clang) | Returns `x86_64-w64-mingw32-gcc`/`x86_64-w64-mingw32-g++` when cross-compiling |
| **Stale CMake cache** | macOS LadybugDB path persisted in shared `build-release/`, passed to MinGW linker | `unset(LADYBUG_LIBRARY CACHE)` on Windows branch + build.rs skips cache reading on Windows |
| **Dev branch CI** | No automated Windows validation on `dev` | New `.github/workflows/dev.yml`: triggers on push to `dev` (or manual dispatch) |
| **Windows support** | Unmarked | Documented as **beta** in README |

### Upgrade notes

- **Windows**: Use `--target x86_64-pc-windows-gnu` for Rust builds. Requires MinGW-w64 14.0.0+. `lbug_shared.dll` must be in the same directory as `codescope.exe` (bundled in the package).
- **Windows**: The single `codescope.exe` is now fully self-contained — no DLLs to bundle. LadybugDB/Cypher queries are unavailable on Windows; graph storage uses SQLite only.
- **No breaking API changes**: All MCP tools maintain the same JSON response schema.
- **`graph_nodes`/`graph_edges` tables are no longer written**: If you have custom scripts that query these tables, migrate to `entity`/`relation`.
- **LadybugDB is now required for graph queries**: Without LadybugDB, all query tools return "graph not ready" or "LadybugDB not compiled".

### Bug fixes (v0.2.2 migration fallout)
### Bug fixes

| # | Bug | Root cause | Fix |
|---|-----|------------|-----|
| 1 | `findSymbolJson` prepare failed | SQL query referenced `graph_nodes` (empty) | Query `entity` instead |
| 2 | All tools "graph not ready" | `isGraphReady()` in-memory flag not shared across processes | `probeGraphReady()` queries LadybugDB directly |
| 3 | `project_overview` total_symbols:0 | Counted `graph_nodes` rows | Count `entity` rows |
| 4 | `search` returns empty | FTS built on `graph_nodes` (empty), no fallback | `searchLadybugJson()` via LadybugDB Cypher |
| 5 | `buildFTSFromGraph` empty | FTS tables built from `graph_nodes` | Build from `entity` |
| 6 | `engine_get_project_node_count` returns 0 | Queried `graph_nodes` | Query `entity` |
| 7 | `getLatestProjectId` wrong project | Queried `graph_nodes` for node count | Query `entity` |
| 8 | `verify_integrity` hangs | No query timeout | 10s `QueryDeadlineGuard` |
| 9 | `buildCSR` reverse query fails | `ORDER BY target_node_id` (wrong column name) | `ORDER BY target_id` |
| 10 | Version string still 0.2.1 | Hardcoded in `engine_ffi.cpp` | Updated to 0.2.3 |

### Performance

| Metric | Value |
|--------|-------|
| CodeScope self-index (212 files) | 899ms |
| Windows binary size | 16MB (PE32+ executable) |
| LadybugDB search latency | ~1ms (Cypher CONTAINS) |
| Query latency (all graph tools) | ~1ms |
| `make check` | 85 Rust tests + all C++ tests pass |
| 1 | Cross-compile build.rs ignored cmake system name | `CARGO_CFG_TARGET_OS` returns target during cross-compile | `std::env::consts::OS` for build host |
| 2 | Wrong compiler used for cross-compile | `platform_default_compiler` returned native `gcc` on macOS | Detect cross-compile → use MinGW cross-compiler |
| 3 | Stale LadybugDB cache breaks Windows link | macOS `.dylib` path persisted in shared build dir | `unset()` + Rust-side Windows guard |
| 4 | Windows crash at startup (runtime DLL mismatch) | MinGW libstdc++/libgcc/libwinpthread version conflict | `-static` rustflag bakes all runtime into .exe |
| 5 | LadybugDB ABI risk on Windows | Vendored `.lib` of unverified MinGW version | Disable LadybugDB on Windows entirely |

### Full changelog

See [CHANGELOG.md](./CHANGELOG.md) for the complete list of changes, bug fixes, and cross-platform fixes.
See [CHANGELOG.md](./CHANGELOG.md) for the complete list of changes.

---
Loading
Loading