-
Notifications
You must be signed in to change notification settings - Fork 46
Add CLAUDE.md: AI Assistant Guide #1336
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cadafde
Merge pull request #1333 from goplus/dependabot/go_modules/github.com…
xgopilot f65072d
docs: address review feedback on CLAUDE.md
xgopilot c7e3408
docs: simplify CLAUDE.md per review feedback
xgopilot 1edd4b8
docs: merge Testing and Validation into single section
xgopilot a99f3d9
docs: refactor Important Notes with clear workflow and requirements
xgopilot 72602d6
docs: address review feedback on CLAUDE.md
xgopilot 00d5aad
docs: remove duplicate validation section from CLAUDE.md
xgopilot 62198a5
docs: add descriptive instructions to Code Quality section
xgopilot d6f45c6
docs: merge Testing and Validation into single section
xgopilot 391e09a
docs: migrate all build commands to Common Development Tasks
xgopilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| # LLGo Project AI Assistant Guide | ||
|
|
||
| This document provides essential information for AI assistants to help fix bugs and implement features in the LLGo project. | ||
|
|
||
| ## About LLGo | ||
|
|
||
| LLGo is a Go compiler based on LLVM designed to better integrate Go with the C ecosystem, including Python and JavaScript. It's a subproject of the XGo project that aims to expand the boundaries of Go/XGo for game development, AI and data science, WebAssembly, and embedded development. | ||
|
|
||
| ## Project Structure | ||
|
|
||
| - `cmd/llgo` - Main llgo compiler command (usage similar to `go` command) | ||
| - `cl/` - Core compiler logic that converts Go packages to LLVM IR | ||
| - `ssa/` - LLVM IR file generation using Go SSA semantics | ||
| - `internal/build/` - Build process orchestration | ||
| - `runtime/` - LLGo runtime library | ||
| - `chore/` - Development tools (llgen, llpyg, ssadump, etc.) | ||
| - `_demo/` - Example programs demonstrating C/C++ interop (`c/hello`, `c/qsort`) and Python integration (`py/callpy`, `py/numpy`) | ||
| - `_cmptest/` - Comparison tests to verify the same program gets the same output with Go and LLGo | ||
|
|
||
| ## Development Environment | ||
|
|
||
| For detailed dependency requirements and installation instructions, see the [Dependencies](README.md#dependencies) and [How to install](README.md#how-to-install) sections in the README. | ||
|
|
||
| ## Testing & Validation | ||
|
|
||
| The following commands and workflows are essential when fixing bugs or implementing features in the LLGo project: | ||
|
|
||
| ### Run all tests | ||
| ```bash | ||
| go test ./... | ||
| ``` | ||
|
|
||
| **Note:** Some tests may fail if optional dependencies (like Python) are not properly configured. The test suite includes comprehensive tests for: | ||
| - Compiler functionality | ||
| - SSA generation | ||
| - C interop | ||
| - Python integration (requires Python development headers) | ||
|
|
||
| ### Write and run tests for your changes | ||
|
|
||
| When adding new functionality or fixing bugs, create appropriate test cases: | ||
|
|
||
| ```bash | ||
| # Add your test to the relevant package's *_test.go file | ||
| # Then run tests for that package | ||
| go test ./path/to/package | ||
|
|
||
| # Or run all tests | ||
| go test ./... | ||
| ``` | ||
|
|
||
| **Important:** The `LLGO_ROOT` environment variable must be set to the repository root when running llgo commands during development. | ||
|
|
||
| ## Code Quality | ||
|
|
||
| Before submitting any code updates, you must run the following formatting and validation commands: | ||
|
|
||
| ### Format code | ||
| ```bash | ||
| go fmt ./... | ||
| ``` | ||
|
|
||
| **Important:** Always run `go fmt ./...` before committing code changes. This ensures consistent code formatting across the project. | ||
|
|
||
| ### Run static analysis | ||
| ```bash | ||
| go vet ./... | ||
| ``` | ||
|
|
||
| **Note:** Currently reports some issues related to lock passing by value in `ssa/type_cvt.go` and a possible unsafe.Pointer misuse in `cl/builtin_test.go`. These are known issues. | ||
|
|
||
|
|
||
| ## Common Development Tasks | ||
|
|
||
| ### Build the entire project | ||
| ```bash | ||
| go build -v ./... | ||
| ``` | ||
|
|
||
| ### Build llgo command specifically | ||
| ```bash | ||
| go build -o llgo ./cmd/llgo | ||
| ``` | ||
|
|
||
| ### Check llgo version | ||
| ```bash | ||
| llgo version | ||
| ``` | ||
|
|
||
| ### Install llgo for system-wide use | ||
| ```bash | ||
| ./install.sh | ||
| ``` | ||
|
|
||
| ### Build development tools | ||
| ```bash | ||
| go install -v ./cmd/... | ||
| go install -v ./chore/... | ||
| ``` | ||
|
|
||
| ## Key Modules for Understanding | ||
|
|
||
| - `ssa` - Generates LLVM IR using Go SSA semantics | ||
| - `cl` - Core compiler converting Go to LLVM IR | ||
| - `internal/build` - Orchestrates the compilation process | ||
|
|
||
| ## Debugging | ||
|
|
||
| ### Disable Garbage Collection | ||
| For testing purposes, you can disable GC: | ||
| ```bash | ||
| LLGO_ROOT=/path/to/llgo llgo run -tags nogc . | ||
| ``` | ||
|
Comment on lines
+107
to
+113
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe current doc status we not need complete this step's description |
||
|
|
||
| ## LLGO_ROOT Environment Variable | ||
|
|
||
| **CRITICAL:** Always set `LLGO_ROOT` to the repository root when running llgo during development: | ||
|
|
||
| ```bash | ||
| export LLGO_ROOT=/path/to/llgo | ||
| # or | ||
| LLGO_ROOT=/path/to/llgo llgo run . | ||
| ``` | ||
|
|
||
| ## Important Notes | ||
|
|
||
| 1. **Testing Requirement:** All bug fixes and features MUST include tests | ||
| 2. **Demo Directory:** Examples in `_demo` are prefixed with `_` to prevent standard `go` command from trying to compile them | ||
| 3. **Defer in Loops:** LLGo intentionally does not support `defer` in loops (considered bad practice) | ||
| 4. **C Ecosystem Integration:** LLGo uses `go:linkname` directive to link external symbols through ABI | ||
| 5. **Python Integration:** Third-party Python libraries require separate installation of library files | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xgopilot
Refactor to remove redundancy. Key improvements:
LLGO_ROOTand 5 important notes sectionsUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important Notes Section Refactored ✅
I've successfully refactored the section as requested with key improvements for clarity and structure.
Changes Made
1. Added "Validation Workflow" section (CLAUDE.md:156-167)
2. Created prominent "LLGO_ROOT Environment Variable" section (CLAUDE.md:168-176)
3. Updated "Important Notes" section (CLAUDE.md:178-185)
Key Improvements:
This refactoring removes redundancy while making critical requirements more prominent and actionable.
Branch: xgopilot/claude/issue-1335-1760330027
Commit: a99f3d94