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
105 changes: 66 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,23 @@ jobs:
path: |
llvm-build
llvm-project
key: clangd-linux-x86_64-v1
key: clangd-linux-x86_64-v2
restore-keys: |
clangd-linux-x86_64-

# restore-keys can hand back a tree from an older cache key without an
# exact cache-hit; reuse it and let the build step update it incrementally.
- name: Checkout upstream llvm-project
if: steps.cache-clangd.outputs.cache-hit != 'true'
shell: bash
run: |
git clone --filter=blob:none --no-checkout --depth 1 https://github.com/llvm/llvm-project.git llvm-project
git -C llvm-project sparse-checkout set llvm clang clang-tools-extra cmake third-party libc
git -C llvm-project checkout
if [ -d llvm-project/.git ]; then
echo "Reusing llvm-project restored from a previous cache"
else
git clone --filter=blob:none --no-checkout --depth 1 https://github.com/llvm/llvm-project.git llvm-project
git -C llvm-project sparse-checkout set llvm clang clang-tools-extra cmake third-party libc
git -C llvm-project checkout
fi

- name: Build Clangd from main
if: steps.cache-clangd.outputs.cache-hit != 'true'
Expand All @@ -66,7 +73,7 @@ jobs:
-DCLANG_ENABLE_ARCMT=OFF \
-DCLANG_TOOL_CLANG_CHECK_BUILD=OFF \
-DCLANG_TOOL_CLANG_FORMAT_BUILD=OFF
ninja -C llvm-build clangd
ninja -C llvm-build clangd FileCheck not count LLVMFuzzerCLI

- name: Save Clangd cache
if: steps.cache-clangd.outputs.cache-hit != 'true'
Expand All @@ -75,7 +82,12 @@ jobs:
path: |
llvm-build
llvm-project
key: clangd-linux-x86_64-v1
key: clangd-linux-x86_64-v2

# No-op when the cached tree already has them; covers caches saved
# before these targets were part of the clangd build step.
- name: Build LLVM test utilities (FileCheck, not, count, FuzzerCLI)
run: ninja -C llvm-build FileCheck not count LLVMFuzzerCLI

- name: Configure pseudo-parser
run: |
Expand All @@ -88,17 +100,10 @@ jobs:
-DPSEUDO_ENABLE_TESTS=ON

- name: Build pseudo-parser feature module and tools
run: |
ninja -C build clangd_pseudo pseudo-tool
ninja -C build ClangPseudoTests || true
run: ninja -C build clangd_pseudo pseudo-tool

- name: Run unit tests (if available)
run: |
if [ -f ./build/unittests/ClangPseudoTests ]; then
./build/unittests/ClangPseudoTests
else
echo "Skipping ClangPseudoTests (LLVMTestingSupport not in distribution package)"
fi
- name: Run unit and lit tests
run: ninja -C build ClangPseudoTests PseudoModuleTests check-clang-pseudo

- name: Test loading feature module into clangd (-load) and LSP diagnostics
shell: bash
Expand Down Expand Up @@ -158,16 +163,23 @@ jobs:
path: |
llvm-build
llvm-project
key: clangd-macos-arm64-v1
key: clangd-macos-arm64-v2
restore-keys: |
clangd-macos-arm64-

# restore-keys can hand back a tree from an older cache key without an
# exact cache-hit; reuse it and let the build step update it incrementally.
- name: Checkout upstream llvm-project
if: steps.cache-clangd.outputs.cache-hit != 'true'
shell: bash
run: |
git clone --filter=blob:none --no-checkout --depth 1 https://github.com/llvm/llvm-project.git llvm-project
git -C llvm-project sparse-checkout set llvm clang clang-tools-extra cmake third-party libc
git -C llvm-project checkout
if [ -d llvm-project/.git ]; then
echo "Reusing llvm-project restored from a previous cache"
else
git clone --filter=blob:none --no-checkout --depth 1 https://github.com/llvm/llvm-project.git llvm-project
git -C llvm-project sparse-checkout set llvm clang clang-tools-extra cmake third-party libc
git -C llvm-project checkout
fi

- name: Build Clangd from main
if: steps.cache-clangd.outputs.cache-hit != 'true'
Expand All @@ -190,7 +202,7 @@ jobs:
-DCLANG_ENABLE_ARCMT=OFF \
-DCLANG_TOOL_CLANG_CHECK_BUILD=OFF \
-DCLANG_TOOL_CLANG_FORMAT_BUILD=OFF
ninja -C llvm-build clangd
ninja -C llvm-build clangd FileCheck not count LLVMFuzzerCLI

- name: Save Clangd cache
if: steps.cache-clangd.outputs.cache-hit != 'true'
Expand All @@ -199,7 +211,12 @@ jobs:
path: |
llvm-build
llvm-project
key: clangd-macos-arm64-v1
key: clangd-macos-arm64-v2

# No-op when the cached tree already has them; covers caches saved
# before these targets were part of the clangd build step.
- name: Build LLVM test utilities (FileCheck, not, count, FuzzerCLI)
run: ninja -C llvm-build FileCheck not count LLVMFuzzerCLI

- name: Configure pseudo-parser
run: |
Expand All @@ -212,17 +229,10 @@ jobs:
-DPSEUDO_ENABLE_TESTS=ON

- name: Build pseudo-parser feature module and tools
run: |
ninja -C build clangd_pseudo pseudo-tool
ninja -C build ClangPseudoTests || true
run: ninja -C build clangd_pseudo pseudo-tool

- name: Run unit tests (if available)
run: |
if [ -f ./build/unittests/ClangPseudoTests ]; then
./build/unittests/ClangPseudoTests
else
echo "Skipping ClangPseudoTests (LLVMTestingSupport not in distribution package)"
fi
- name: Run unit and lit tests
run: ninja -C build ClangPseudoTests PseudoModuleTests check-clang-pseudo

- name: Test loading feature module into clangd (-load) and LSP diagnostics
shell: bash
Expand Down Expand Up @@ -288,16 +298,23 @@ jobs:
path: |
llvm-build
llvm-project
key: clangd-windows-x86_64-v1
key: clangd-windows-x86_64-v2
restore-keys: |
clangd-windows-x86_64-

# restore-keys can hand back a tree from an older cache key without an
# exact cache-hit; reuse it and let the build step update it incrementally.
- name: Checkout upstream llvm-project
if: steps.cache-clangd.outputs.cache-hit != 'true'
shell: bash
run: |
git clone --filter=blob:none --no-checkout --depth 1 https://github.com/llvm/llvm-project.git llvm-project
git -C llvm-project sparse-checkout set llvm clang clang-tools-extra cmake third-party libc
git -C llvm-project checkout
if [ -d llvm-project/.git ]; then
echo "Reusing llvm-project restored from a previous cache"
else
git clone --filter=blob:none --no-checkout --depth 1 https://github.com/llvm/llvm-project.git llvm-project
git -C llvm-project sparse-checkout set llvm clang clang-tools-extra cmake third-party libc
git -C llvm-project checkout
fi

- name: Build Clangd with plugin symbol exports (LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON)
if: steps.cache-clangd.outputs.cache-hit != 'true'
Expand All @@ -322,7 +339,7 @@ jobs:
-DCLANG_ENABLE_ARCMT=OFF ^
-DCLANG_TOOL_CLANG_CHECK_BUILD=OFF ^
-DCLANG_TOOL_CLANG_FORMAT_BUILD=OFF
ninja -C llvm-build clangd
ninja -C llvm-build clangd FileCheck not count LLVMFuzzerCLI

- name: Save Clangd cache
if: steps.cache-clangd.outputs.cache-hit != 'true'
Expand All @@ -331,7 +348,13 @@ jobs:
path: |
llvm-build
llvm-project
key: clangd-windows-x86_64-v1
key: clangd-windows-x86_64-v2

# No-op when the cached tree already has them; covers caches saved
# before these targets were part of the clangd build step.
- name: Build LLVM test utilities (FileCheck, not, count, FuzzerCLI)
shell: cmd
run: ninja -C llvm-build FileCheck not count LLVMFuzzerCLI

- name: Configure pseudo-parser
shell: cmd
Expand All @@ -344,13 +367,17 @@ jobs:
-DCLANGD_INCLUDE_DIRS="%CD%/llvm-project/clang-tools-extra/clangd" ^
-DCMAKE_SHARED_LINKER_FLAGS="/FORCE:MULTIPLE" ^
-DCMAKE_MODULE_LINKER_FLAGS="/FORCE:MULTIPLE" ^
-DPSEUDO_ENABLE_TESTS=OFF
-DPSEUDO_ENABLE_TESTS=ON

- name: Build pseudo-parser feature module and tools
shell: cmd
run: |
ninja -C build -v clangd_pseudo pseudo-tool

- name: Run unit and lit tests
shell: cmd
run: ninja -C build ClangPseudoTests PseudoModuleTests check-clang-pseudo

- name: Test feature module LSP diagnostics with clangd (-load)
shell: bash
run: |
Expand Down
71 changes: 70 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if(NOT TARGET LibEdit::LibEdit)
add_library(LibEdit::LibEdit INTERFACE IMPORTED)
endif()
Expand Down Expand Up @@ -32,6 +34,13 @@ if(NOT DEFINED LLVM_MAIN_SRC_DIR)
${LLVM_LIBRARY_DIRS}
)
add_definitions(${LLVM_DEFINITIONS})

# Standalone builds have no LLVM build tree to inherit output locations
# from. Collect executables under bin/ and libraries under lib/ so the lit
# configuration (CURRENT_TOOLS_DIR, SHLIBDIR) can find the tools it runs.
set(LLVM_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin")
set(LLVM_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib")
set(LLVM_SHLIB_OUTPUT_INTDIR "${LLVM_LIBRARY_OUTPUT_INTDIR}")
endif()

if(MSVC)
Expand All @@ -57,7 +66,39 @@ endif()

if(NOT CLANGD_INCLUDE_DIRS)
message(WARNING "CLANGD_INCLUDE_DIRS was not found. Please specify -DCLANGD_INCLUDE_DIRS=/path/to/clang-tools-extra/clangd if building clangd_pseudo.")
else()
# Normalize to a CMake-style path. A native Windows path with backslashes
# breaks LLVM's macro-based helpers (add_unittest, add_llvm_executable),
# which re-parse their arguments and treat "\a" as an escape sequence.
get_filename_component(CLANGD_INCLUDE_DIRS "${CLANGD_INCLUDE_DIRS}" ABSOLUTE)
endif()

# Locate an llvm-project source tree. Tests need it for gtest, the LLVM
# testing libraries, lit, and clangd's test support sources.
set(PSEUDO_LLVM_SOURCE_DIR "" CACHE PATH
"Path to an llvm-project checkout matching the LLVM package in use (used to build test dependencies)")
if(NOT PSEUDO_LLVM_SOURCE_DIR)
if(DEFINED ENV{PSEUDO_LLVM_SOURCE_DIR})
set(PSEUDO_LLVM_SOURCE_DIR "$ENV{PSEUDO_LLVM_SOURCE_DIR}")
elseif(CLANGD_INCLUDE_DIRS AND EXISTS "${CLANGD_INCLUDE_DIRS}/../../llvm/utils/lit/lit.py")
get_filename_component(PSEUDO_LLVM_SOURCE_DIR "${CLANGD_INCLUDE_DIRS}/../.." ABSOLUTE)
elseif(LLVM_BUILD_MAIN_SRC_DIR AND EXISTS "${LLVM_BUILD_MAIN_SRC_DIR}/../third-party/unittest")
get_filename_component(PSEUDO_LLVM_SOURCE_DIR "${LLVM_BUILD_MAIN_SRC_DIR}/.." ABSOLUTE)
endif()
endif()
Comment thread
ArcsinX marked this conversation as resolved.
Resolved
if(PSEUDO_LLVM_SOURCE_DIR)
# Normalize user-supplied values too: the path ends up in a C++ string
# literal, where native Windows backslashes would become escape sequences.
get_filename_component(PSEUDO_LLVM_SOURCE_DIR "${PSEUDO_LLVM_SOURCE_DIR}" ABSOLUTE)
endif()

# Python drives the resource bundler in tool/ and lit in test/. Find it once
# here: find_package() results are directory-scoped, and add_lit_target builds
# its command from Python3_EXECUTABLE, so a lookup inside tool/ would leave
# test/ invoking lit.py bare. Unix runs that through the shebang; Windows
# hands it to the .py file association, which runs detached and reports
# success without executing anything visible.
find_package(Python3 REQUIRED COMPONENTS Interpreter)

include_directories(BEFORE
include
Expand All @@ -74,7 +115,35 @@ if(CLANGD_INCLUDE_DIRS)
add_subdirectory(clangd)
endif()

option(PSEUDO_ENABLE_TESTS "Build pseudo-parser tests" ON)
# Tests default to ON when their dependencies can be satisfied, so a plain
# configure against an LLVM package without testing libraries and without an
# llvm-project tree still builds the plugin. Once tests are ON, a missing
# dependency is a configure error (see cmake/LLVMTestingLibs.cmake).
# PseudoModuleTests has extra prerequisites (clangDaemon, clangd's test
# scaffolding) and is skipped with a status message when they are absent, so
# ClangPseudoTests and the lit suite still build; CI builds that target
# explicitly so a skip cannot pass unnoticed there.
if(TARGET LLVMTestingSupport
OR (PSEUDO_LLVM_SOURCE_DIR AND EXISTS "${PSEUDO_LLVM_SOURCE_DIR}/third-party/unittest/CMakeLists.txt"))
Comment thread
ArcsinX marked this conversation as resolved.
Resolved
set(PSEUDO_ENABLE_TESTS_DEFAULT ON)
else()
set(PSEUDO_ENABLE_TESTS_DEFAULT OFF)
message(STATUS "Test dependencies not found; PSEUDO_ENABLE_TESTS defaults to OFF. "
"Set PSEUDO_LLVM_SOURCE_DIR to an llvm-project checkout to enable them.")
endif()
option(PSEUDO_ENABLE_TESTS "Build pseudo-parser tests" ${PSEUDO_ENABLE_TESTS_DEFAULT})
option(PSEUDO_ENABLE_FUZZER "Build clang-pseudo-fuzzer even when tests are off (the lit suite always builds it)" OFF)
option(PSEUDO_ENABLE_BENCHMARKS "Build pseudo-parser benchmarks (needs LLVM's google benchmark target)" OFF)

if(PSEUDO_ENABLE_TESTS OR PSEUDO_ENABLE_FUZZER)
add_subdirectory(fuzzer)
endif()

if(PSEUDO_ENABLE_BENCHMARKS)
add_subdirectory(benchmarks)
endif()

if(PSEUDO_ENABLE_TESTS)
add_subdirectory(unittests)
add_subdirectory(test)
endif()
42 changes: 37 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,41 @@ cmake -B build -G Ninja \
-DCLANGD_INCLUDE_DIRS=/path/to/llvm-project/clang-tools-extra/clangd \
-DPSEUDO_ENABLE_TESTS=ON

# 3. Build the dynamic feature module, CLI tool, and tests
ninja -C build clangd_pseudo clang-pseudo ClangPseudoTests
# 3. Build the dynamic feature module and the CLI tool
ninja -C build clangd_pseudo pseudo-tool

# 4. Run tests
./build/unittests/ClangPseudoTests
# 4. Build and run every test: lit regression tests, ClangPseudoTests and
# PseudoModuleTests (the gtest binaries run through the lit shim in test/Unit)
ninja -C build check-clang-pseudo
```

### Test dependencies

The tests need gtest, LLVM's testing libraries, `lit`, `FileCheck`, `not`,
`count`, and clangd's test scaffolding. Installed LLVM packages do not ship
most of these, so the build compiles them from an `llvm-project` source tree
that matches the LLVM you build against. That tree is found automatically
when `CLANGD_INCLUDE_DIRS` points inside one (as in the example above);
otherwise pass `-DPSEUDO_LLVM_SOURCE_DIR=/path/to/llvm-project`. `FileCheck`,
`not` and `count` are taken from the LLVM `bin/` directory, and the fuzzer
links `LLVMFuzzerCLI`, so build them in your LLVM tree if they are missing
(`ninja -C llvm-build FileCheck not count LLVMFuzzerCLI`).

`PseudoModuleTests` additionally needs the `clangDaemon` library, which an
LLVM build tree that built `clangd` exports, and clangd's test scaffolding
from `clang-tools-extra/clangd/unittests`. When either is missing, that one
target is skipped with a status message and the other tests still build.

`PSEUDO_ENABLE_TESTS` defaults to ON when these dependencies are found and
to OFF otherwise, so a plain configure always builds the plugin and the tool.
With tests ON, a missing dependency is a configure error rather than a
silent skip.

Optional targets: `-DPSEUDO_ENABLE_FUZZER=ON` builds `clang-pseudo-fuzzer`
without the tests (the lit suite always builds it);
`-DPSEUDO_ENABLE_BENCHMARKS=ON` builds `ClangPseudoBenchmark` and requires
LLVM's `benchmark` target (`LLVM_INCLUDE_BENCHMARKS=ON`).

---

## Repository Structure
Expand All @@ -107,7 +135,11 @@ pseudo-parser/
├── gen/ # clang-pseudo-gen code generator
├── tool/ # Standalone clang-pseudo CLI tool and HTML forest browser
├── clangd/ # Clangd FeatureModule implementation (PseudoModule)
├── unittests/ # Unit test suite
├── unittests/ # gtest suites (core parser and PseudoModule)
├── test/ # lit regression tests
├── fuzzer/ # clang-pseudo-fuzzer
├── benchmarks/ # Parser benchmark (opt-in)
├── cmake/ # Build helpers (test dependency fallback)
├── docs/ # Design documents and grammar disambiguation notes
└── .github/workflows/ # CI pipeline for Linux and macOS
```
Expand Down
19 changes: 16 additions & 3 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
if(NOT TARGET benchmark)
message(FATAL_ERROR
"PSEUDO_ENABLE_BENCHMARKS needs LLVM's google benchmark target, which is "
"only exported from an LLVM build tree configured with "
"LLVM_INCLUDE_BENCHMARKS=ON.")
endif()

add_benchmark(ClangPseudoBenchmark Benchmark.cpp)

target_link_libraries(ClangPseudoBenchmark
PRIVATE
clangPseudo
clangPseudoCLI
clangPseudoGrammar
Pseudo
PseudoCLI
PseudoGrammar
LLVMSupport
)

clang_target_link_libraries(ClangPseudoBenchmark
PRIVATE
clangBasic
clangLex
)
Loading
Loading