Skip to content

Conversation

luoliwoshang
Copy link
Member

@luoliwoshang luoliwoshang commented Sep 12, 2025

we are release the esp-clang,so we need func test with esp-clang

Copy link

niupilot bot commented Sep 12, 2025

Code Review for PR #1295

Todo List:

  • Read and analyze the changed files
  • Review .github/workflows/download_esp_clang.sh changes
  • Review install.sh changes
  • Check for code quality and best practices
  • Identify potential bugs or issues
  • Check documentation consistency
  • Provide comprehensive review feedback

Overview

This PR adds ESP Clang toolchain support to the llgo installation process. The changes include:

  1. Enhanced ESP Clang download script - supports single-platform or all-platform installation
  2. New installation option - --with-esp flag for bundled LLVM builds

Strengths

Good Architecture & Design:

  • Clean separation between single-platform and multi-platform installation modes
  • Backward compatibility maintained - existing functionality unchanged
  • Well-structured functions with clear responsibilities
  • Proper error handling and validation

Security & Robustness:

  • Input validation for platform arguments (install.sh:71-81, download_esp_clang.sh:71-81)
  • Proper executable checks before running scripts (install.sh:58)
  • Safe parameter expansion patterns used throughout
  • Exit codes properly propagated on errors

⚠️ Issues and Suggestions

1. Shell Syntax Error ⚠️

# Line 86 in download_esp_clang.sh - 'local' inside for loop
for platform in "darwin-amd64" "darwin-arm64" "linux-amd64" "linux-arm64"; do
    local os="${platform%-*}"  # ❌ This will cause syntax error
    local arch="${platform##*-}"

Fix: Remove local keywords inside the for loop:

for platform in "darwin-amd64" "darwin-arm64" "linux-amd64" "linux-arm64"; do
    os="${platform%-*}"
    arch="${platform##*-}"

2. Code Duplication ⚠️
The platform parsing logic appears in multiple places:

  • download_esp_clang.sh:86-87
  • install.sh:69-73

Suggestion: Consider extracting this to a shared function in the download script.

3. Hardcoded Version Management ⚠️
ESP_CLANG_VERSION is hardcoded (download_esp_clang.sh:4). Consider:

  • Adding version as optional parameter
  • Documenting version update process
  • Consider environment variable override capability

4. Error Message Clarity 💡
download_esp_clang.sh:91-93 usage message could be more descriptive:

# Current
echo "Usage: $0 [platform]" >&2

# Suggested  
echo "Usage: $0 [platform]" >&2
echo "Downloads ESP Clang toolchain for llgo embedded development" >&2
echo "  platform: target platform (darwin-amd64, darwin-arm64, linux-amd64, linux-arm64)" >&2
echo "  If no platform specified, downloads all platforms to .sysroot/" >&2

5. Inconsistent Path Handling ⚠️

  • Single platform: crosscompile/clang (relative)
  • All platforms: .sysroot/${os}/${arch}/crosscompile/clang (relative)

Both should use consistent path resolution to avoid issues if PWD changes.

🔍 Technical Verification

Build Environment Settings:

  • CGO flags properly configured for both Darwin and Linux
  • RPATH settings appropriate for bundled libraries
  • Build tags correctly structured

Cross-Platform Support:

  • Handles Darwin and Linux architectures correctly
  • Proper architecture mapping (x86_64→amd64, aarch64→arm64)

📚 Documentation Consistency

Missing Documentation Updates: ⚠️
The README.md mentions ESP32 support in embedded examples (lines 405-416) but doesn't document the new --with-esp installation option. Consider adding:

### Install with ESP Clang (for embedded development)
```sh
./install.sh --with-esp

This installs llgo with a bundled ESP Clang toolchain for embedded development targeting ESP32 and other embedded platforms.


#### 🏆 **Overall Assessment**

This is a **solid enhancement** that adds valuable embedded development capabilities to llgo. The code follows good practices and maintains backward compatibility. The main issues are minor (syntax error, documentation) and easily addressable.

**Recommended Actions:**
1. **Fix the shell syntax error** in download_esp_clang.sh:86-87
2. **Update README.md** to document the `--with-esp` installation option  
3. **Consider adding version parameter** to the download script for future maintainability

---
👉 **Want me to re-run this review?** Just type `/review` in the comments! For more usage examples, visit [CodeAgent GitHub Repository](https://github.com/qiniu/codeagent).

@luoliwoshang luoliwoshang marked this pull request as draft September 12, 2025 02:38
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @luoliwoshang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the llgo installation process by adding support for building with the ESP Clang toolchain. This allows for a more specialized build environment, particularly beneficial for cross-compilation scenarios targeting ESP platforms, by bundling the necessary LLVM components directly.

Highlights

  • New ESP Clang Integration: Introduced a new installation method (install_local_with_esp) in install.sh to build llgo using the ESP Clang toolchain.
  • Cross-Compilation Support: The new method handles downloading the ESP Clang toolchain and configures CGO_CPPFLAGS, CGO_LDFLAGS, and rpath for macOS and Linux to enable building llgo with a bundled LLVM.
  • Installation Script Enhancement: The install.sh script now accepts a --with-esp argument, allowing users to choose between the basic local installation and the new ESP Clang integrated build.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new installation method in install.sh to build llgo with the ESP-Clang toolchain, activated by a --with-esp flag. The new install_local_with_esp function manages downloading the toolchain and configuring the CGO environment. My review highlights a significant issue with the linker's runtime path (rpath) configuration, which would prevent the compiled binary from running correctly. I have provided a comprehensive code suggestion to fix this issue and refactor the script for better maintainability and robustness.

Comment on lines +79 to +90
if [ "$OS" = "darwin" ]; then
export CGO_CPPFLAGS="-I$(pwd)/crosscompile/clang/include -mmacosx-version-min=10.13 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
export CGO_LDFLAGS="-L$(pwd)/crosscompile/clang/lib -mmacosx-version-min=10.13 -lLLVM-19 -lz -lm -Wl,-rpath,@executable_path/../crosscompile/clang/lib"
go install -tags="${OS},${ARCH},byollvm" ./cmd/llgo
elif [ "$OS" = "linux" ]; then
export CGO_CPPFLAGS="-I$(pwd)/crosscompile/clang/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
export CGO_LDFLAGS="-L$(pwd)/crosscompile/clang/lib -lLLVM-19"
go install -tags="${OS},${ARCH},byollvm" -ldflags='-extldflags=-Wl,-rpath,$ORIGIN/../crosscompile/clang/lib' ./cmd/llgo
else
echo "Error: Unsupported OS: ${OS}"
exit 1
fi

Choose a reason for hiding this comment

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

high

This block for OS-specific build flags has a high-impact issue with rpath and could also be improved for maintainability.

  1. Incorrect rpath: The rpath set for the llgo binary is incorrect for both darwin and linux. go install places the binary in $GOPATH/bin, but the relative path provided (../crosscompile/clang/lib) assumes a different file structure. This will cause dynamic linking errors at runtime as the LLVM shared libraries won't be found. A fix is to use an absolute path to the libraries for local development builds.

  2. Code Duplication: There's significant repetition in setting CGO_CPPFLAGS, CGO_LDFLAGS, and the go install command. Extracting common parts into variables will make the script cleaner and easier to maintain.

  3. Brittle $(pwd): The script relies on $(pwd), which assumes it's executed from the project root. It's more robust to calculate paths relative to the script's own location.

Here is a suggested refactoring that addresses all these points:

Suggested change
if [ "$OS" = "darwin" ]; then
export CGO_CPPFLAGS="-I$(pwd)/crosscompile/clang/include -mmacosx-version-min=10.13 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
export CGO_LDFLAGS="-L$(pwd)/crosscompile/clang/lib -mmacosx-version-min=10.13 -lLLVM-19 -lz -lm -Wl,-rpath,@executable_path/../crosscompile/clang/lib"
go install -tags="${OS},${ARCH},byollvm" ./cmd/llgo
elif [ "$OS" = "linux" ]; then
export CGO_CPPFLAGS="-I$(pwd)/crosscompile/clang/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
export CGO_LDFLAGS="-L$(pwd)/crosscompile/clang/lib -lLLVM-19"
go install -tags="${OS},${ARCH},byollvm" -ldflags='-extldflags=-Wl,-rpath,$ORIGIN/../crosscompile/clang/lib' ./cmd/llgo
else
echo "Error: Unsupported OS: ${OS}"
exit 1
fi
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
CLANG_DIR="${SCRIPT_DIR}/crosscompile/clang"
# Common CGO flags
COMMON_CPPFLAGS="-I${CLANG_DIR}/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
COMMON_LDFLAGS="-L${CLANG_DIR}/lib -lLLVM-19"
INSTALL_TAGS="${OS},${ARCH},byollvm"
if [ "$OS" = "darwin" ]; then
export CGO_CPPFLAGS="${COMMON_CPPFLAGS} -mmacosx-version-min=10.13"
export CGO_LDFLAGS="${COMMON_LDFLAGS} -mmacosx-version-min=10.13 -lz -lm -Wl,-rpath,${CLANG_DIR}/lib"
go install -tags="${INSTALL_TAGS}" ./cmd/llgo
elif [ "$OS" = "linux" ]; then
export CGO_CPPFLAGS="${COMMON_CPPFLAGS} -D_GNU_SOURCE"
export CGO_LDFLAGS="${COMMON_LDFLAGS}"
go install -tags="${INSTALL_TAGS}" -ldflags="-extldflags=-Wl,-rpath,${CLANG_DIR}/lib" ./cmd/llgo
else
echo "Error: Unsupported OS: ${OS}"
exit 1
fi

Copy link

codecov bot commented Sep 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.22%. Comparing base (d5ad4d9) to head (00f78da).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1295   +/-   ##
=======================================
  Coverage   90.22%   90.22%           
=======================================
  Files          42       42           
  Lines       11931    11931           
=======================================
  Hits        10765    10765           
  Misses       1032     1032           
  Partials      134      134           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant