From 2d0d56af2126323b4683d4e6e5444c833043c0a3 Mon Sep 17 00:00:00 2001 From: sean-parent Date: Wed, 18 Nov 2026 02:01:03 -0800 Subject: [PATCH 1/3] Update C++ dependencies and simplify testing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CMakeLists.txt | 23 ++---------- README.md | 2 +- docs/tutorial.md | 22 +++++++++-- tests/consumer.cmake.in | 70 ----------------------------------- tests/consumer/CMakeLists.txt | 14 ------- tests/consumer/main.cpp | 19 ---------- 6 files changed, 22 insertions(+), 128 deletions(-) delete mode 100644 tests/consumer.cmake.in delete mode 100644 tests/consumer/CMakeLists.txt delete mode 100644 tests/consumer/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f1e0c07..b058795 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.24) include(cmake/CPM.cmake) -CPMAddPackage("gh:stlab/cpp-library@6.0.1") +CPMAddPackage("gh:stlab/cpp-library@6.0.2") include("${cpp-library_SOURCE_DIR}/cpp-library.cmake") cpp_library_enable_dependency_tracking() @@ -10,7 +10,7 @@ project(std LANGUAGES CXX) include(CTest) option(CEL_INSTALL "Enable installation for CEL libraries" ${PROJECT_IS_TOP_LEVEL}) -CPMAddPackage("gh:stlab/cel-parser@1.0.2") +CPMAddPackage("gh:stlab/cel-parser@1.1.0") cpp_library_setup( DESCRIPTION "The f64 CEL standard library" @@ -20,29 +20,12 @@ cpp_library_setup( TESTS std_test.cpp EXAMPLES example.cpp DOCS_INPUTS README.md docs/tutorial.md docs/reference.md + DOCS_EXCLUDE_SYMBOLS cel::op_lookup DOCS_OPTIONS "USE_MDFILE_AS_MAINPAGE = ${CMAKE_CURRENT_SOURCE_DIR}/README.md" - "EXCLUDE_SYMBOLS = cel::op_lookup" - "WARN_AS_ERROR = YES" - "FULL_PATH_NAMES = NO" - "STRIP_FROM_INC_PATH = ${CMAKE_CURRENT_SOURCE_DIR}/include" ) -cpp_library_map_dependency("cel::parser" "cel-parser 1.0.2 CONFIG") target_link_libraries(std PUBLIC cel::parser) if(CEL_INSTALL) install(FILES LICENSE licenses/CPM-MIT.txt DESTINATION "${CMAKE_INSTALL_DATADIR}/licenses/cel-std") endif() - -if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING) - configure_file(tests/consumer.cmake.in consumer.cmake @ONLY) - foreach(mode source installed) - if(mode STREQUAL "installed" AND NOT CEL_INSTALL) - continue() - endif() - add_test(NAME consumer_${mode} - COMMAND "${CMAKE_COMMAND}" "-DMODE=${mode}" "-DCONFIG=$" - -P "${CMAKE_CURRENT_BINARY_DIR}/consumer.cmake") - set_tests_properties(consumer_${mode} PROPERTIES TIMEOUT 300) - endforeach() -endif() diff --git a/README.md b/README.md index 9eada04..73789ca 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ compiled example and installed-package instructions. ## Build and test -Configure, build, and run all unit, example, and consumer tests: +Configure, build, and run all unit and example tests: ```sh cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_DOCS=OFF diff --git a/docs/tutorial.md b/docs/tutorial.md index fe95e10..8d8c7df 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -69,17 +69,31 @@ fails. ## Consume an installed package -To install a release build, run: +Install `cel-runtime` 1.1.1 and `cel-parser` 1.1.0 separately before installing +`cel-std`. From the `cel-std` source directory, run: ```sh +cmake -S /PATH/TO/cel-runtime -B build/runtime -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_TESTING=OFF -DBUILD_DOCS=OFF +cmake --build build/runtime --config Release +cmake --install build/runtime --config Release --prefix /PATH/TO/PREFIX + +cmake -S /PATH/TO/cel-parser -B build/parser -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_TESTING=OFF -DBUILD_DOCS=OFF -DCPM_USE_LOCAL_PACKAGES=ON \ + -DCMAKE_PREFIX_PATH=/PATH/TO/PREFIX +cmake --build build/parser --config Release +cmake --install build/parser --config Release --prefix /PATH/TO/PREFIX + cmake -S . -B build/release -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_TESTING=OFF -DBUILD_DOCS=OFF -DCEL_INSTALL=ON + -DBUILD_TESTING=OFF -DBUILD_DOCS=OFF -DCPM_USE_LOCAL_PACKAGES=ON \ + -DCMAKE_PREFIX_PATH=/PATH/TO/PREFIX cmake --build build/release --config Release cmake --install build/release --config Release --prefix /PATH/TO/PREFIX ``` -Replace `/PATH/TO/PREFIX` with your installation prefix. This installs the -standard library and its parser/runtime dependencies. +Replace `/PATH/TO/cel-runtime` and `/PATH/TO/cel-parser` with the respective +source directories, and `/PATH/TO/PREFIX` with your installation prefix. +Each install command installs only that library, not its dependencies. In the consuming project, find the package and link its exported target: diff --git a/tests/consumer.cmake.in b/tests/consumer.cmake.in deleted file mode 100644 index 6c7476e..0000000 --- a/tests/consumer.cmake.in +++ /dev/null @@ -1,70 +0,0 @@ -# Runs an independent source or installed consumer; any failed command is fatal. -# Complexity: O(consumer configuration, compilation, and execution). -function(run) - execute_process(COMMAND ${ARGV} COMMAND_ERROR_IS_FATAL ANY) -endfunction() - -set(root "@CMAKE_CURRENT_BINARY_DIR@/consumer-${MODE}") -set(options - "-DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@" - "-DCMAKE_CXX_COMPILER=@CMAKE_CXX_COMPILER@" - "-DCMAKE_CXX_FLAGS=@CMAKE_CXX_FLAGS@" - "-DCMAKE_EXE_LINKER_FLAGS=@CMAKE_EXE_LINKER_FLAGS@") -set(build_config) -set(test_config) -if(CONFIG) - list(APPEND build_config --config "${CONFIG}") - list(APPEND test_config -C "${CONFIG}") -endif() - -if(MODE STREQUAL "source") - list(APPEND options "-DCEL_STD_SOURCE_DIR=@CMAKE_CURRENT_SOURCE_DIR@" - "-DBUILD_TESTING=OFF" "-DCEL_INSTALL=OFF") -elseif(MODE STREQUAL "installed") - run("@CMAKE_COMMAND@" --install "@cel-parser_BINARY_DIR@" - ${build_config} --prefix "${root}/prefix") - run("@CMAKE_COMMAND@" --install "@CMAKE_CURRENT_BINARY_DIR@" - ${build_config} --prefix "${root}/prefix") - list(APPEND options - "-DCMAKE_PREFIX_PATH=${root}/prefix" - "-DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF" - "-DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF") -else() - message(FATAL_ERROR "Unknown consumer mode: ${MODE}") -endif() - -run("@CMAKE_COMMAND@" -S "@CMAKE_CURRENT_SOURCE_DIR@/tests/consumer" - -B "${root}/build" -G "@CMAKE_GENERATOR@" ${options}) -run("@CMAKE_COMMAND@" --build "${root}/build" ${build_config} --parallel 2) -run("@CMAKE_CTEST_COMMAND@" --test-dir "${root}/build" - ${test_config} --output-on-failure) - -if(MODE STREQUAL "installed") - # Reject parser packages predating the runtime layout update. - set(old_parser_prefix "${root}/old-parser-prefix") - set(version_probe "${root}/version-probe") - file(REMOVE_RECURSE "${old_parser_prefix}" "${version_probe}") - file(COPY "${root}/prefix/" DESTINATION "${old_parser_prefix}") - include(CMakePackageConfigHelpers) - write_basic_package_version_file( - "${old_parser_prefix}/@CMAKE_INSTALL_LIBDIR@/cmake/cel-parser/cel-parserConfigVersion.cmake" - VERSION 1.0.1 COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT) - file(MAKE_DIRECTORY "${version_probe}") - file(WRITE "${version_probe}/CMakeLists.txt" - "cmake_minimum_required(VERSION 3.24)\n" - "project(parser_version_probe LANGUAGES NONE)\n" - "find_package(cel-std CONFIG REQUIRED)\n") - execute_process(COMMAND "@CMAKE_COMMAND@" - -S "${version_probe}" -B "${version_probe}/build" -G "@CMAKE_GENERATOR@" - "-DCMAKE_PREFIX_PATH=${old_parser_prefix}" - "-DCMAKE_FIND_ROOT_PATH=${old_parser_prefix}" - -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY - -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF - RESULT_VARIABLE version_result OUTPUT_VARIABLE version_output ERROR_VARIABLE version_error) - if(version_result EQUAL 0 OR NOT "${version_output}${version_error}" MATCHES "cel-parser" - OR NOT "${version_output}${version_error}" MATCHES "1\\.0\\.2" - OR NOT "${version_output}${version_error}" MATCHES "1\\.0\\.1") - message(FATAL_ERROR - "Installed cel-std must reject parser 1.0.1:\n${version_output}${version_error}") - endif() -endif() diff --git a/tests/consumer/CMakeLists.txt b/tests/consumer/CMakeLists.txt deleted file mode 100644 index e433463..0000000 --- a/tests/consumer/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.24) -project(cel_std_consumer LANGUAGES CXX) -enable_testing() - -if(CEL_STD_SOURCE_DIR) - include("${CEL_STD_SOURCE_DIR}/cmake/CPM.cmake") - CPMAddPackage(NAME cel-std SOURCE_DIR "${CEL_STD_SOURCE_DIR}") -else() - find_package(cel-std CONFIG REQUIRED) -endif() - -add_executable(consumer main.cpp) -target_link_libraries(consumer PRIVATE cel::std) -add_test(NAME consumer COMMAND consumer) diff --git a/tests/consumer/main.cpp b/tests/consumer/main.cpp deleted file mode 100644 index 7002950..0000000 --- a/tests/consumer/main.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: BSL-1.0 -#include -#include -#include -#include - -/// Returns success when a standalone consumer can evaluate scalar and tuple operations. -/// -/// Complexity: O(expression compilation and execution) time and program storage. -int main() { - cel::op_lookup lookup; - cel::stdlib::install(lookup); - cel::parser parser(std::move(lookup)); - cel::raw_stack stack; - const auto scalar = parser.parse_str("sqrt(9.0)").prepare().call(stack); - const auto pair = - parser.parse_str("0.0.sin_cos()").prepare>().call(stack); - return scalar == 3.0 && pair == std::tuple{0.0, 1.0} ? 0 : 1; -} From 445146a9b30e637bc90492487695d70ffe5be428 Mon Sep 17 00:00:00 2001 From: sean-parent Date: Wed, 18 Nov 2026 09:40:02 -0800 Subject: [PATCH 2/3] Add repository guidance for Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/copilot-instructions.md | 125 ++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 .github/copilot-instructions.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..dd14328 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,125 @@ +# Repository guidance + +`cel-std` is a C++20 library that installs the Rust CEL standard library's +35 retained `f64` operations into the C++ CEL parser. Its public CMake target +is `cel::std`; the installed package name is `cel-std`. + +## Build, test, and lint + +Run commands from the repository root. Use CMake 3.24 or later, a C++20 +compiler, and Ninja for the presets. CPM downloads pinned dependencies into +`.cache/cpm`; dependency declarations live in `CMakeLists.txt`. + +Configure, build, and run the unit-test executable and compiled example: + +```sh +cmake --preset=test +cmake --build --preset=test --parallel 2 +ctest --preset=test --output-on-failure --no-tests=error +``` + +CTest registers `std_test` and `example`, not individual doctest cases. +Run a single doctest case directly after building: + +```sh +build/test/std_test --list-test-cases +build/test/std_test \ + --test-case="sin_cos returns a structural sine then cosine tuple" +``` + +Run only the example through CTest: + +```sh +ctest --preset=test -R '^example$' --output-on-failure +``` + +Run static analysis with the repository's `.clang-tidy` configuration and +`clang-tidy` on `PATH`: + +```sh +cmake --preset=clang-tidy +cmake --build --preset=clang-tidy --parallel 2 +ctest --preset=clang-tidy +``` + +Use `.clang-format` for C++ formatting. + +Build the Release library without tests: + +```sh +cmake --preset=default +cmake --build --preset=default --parallel 2 +``` + +Build documentation with Doxygen 1.13.1 or later: + +```sh +cmake --preset=docs +cmake --build --preset=docs +``` + +The generated site is `build/docs/html/index.html`. CI tests Ubuntu GCC, +Ubuntu Clang, macOS, and Windows, runs clang-tidy, and checks installed +package artifacts. The docs CI job runs on published releases. + +## Architecture + +- `include/cel/std.hpp` exposes `cel::stdlib::install(cel::op_lookup&)`. + `src/std.cpp` contains the registrations and numeric adapters; parsing + and execution belong to the external `cel-parser` and `cel-runtime` + libraries. `cel::parser` is a public dependency and supplies the runtime + transitively. +- The internal `add` helper registers both the typed + operation with `register_op` and a stateless `function_marker` with + `register_function`. Preserve both registrations: ordinary calls, + receiver calls, and calls inside closure bodies use this setup. +- Install into a lookup before moving it into `cel::parser`. Compile with + `parse_str`, prepare the C++ result type, and execute with a caller-owned + `cel::raw_stack`. Emitted programs retain their callbacks and can outlive + the parser. +- `cpp_library_setup` from `stlab/cpp-library` defines the library, tests, + example, documentation, and packaging. Prefer its supported parameters + over duplicating its defaults. The `init` preset forces template + regeneration, including presets and CI; do not use it as a normal build. +- Installation is non-recursive: install runtime, parser, and this library + separately, in that order. See `docs/tutorial.md` for the + `CPM_USE_LOCAL_PACKAGES` and `CMAKE_PREFIX_PATH` commands. + +## Numeric and registration conventions + +- Keep the port limited to `double` operands and results, except for + `sin_cos`, which returns a structural CEL tuple adapted as + `std::tuple`. Integer and `f32` overloads and `powi` are + outside this port. `docs/reference.md` lists the retained signatures. +- Receiver syntax supplies the first operand and must match ordinary-call + argument order. Install each exact signature once per lookup; unrelated + registrations and disjoint overloads must remain usable. Registration + failures propagate, and installation is not transactional. +- Preserve Rust operation semantics rather than blindly substituting + similarly named C++ functions. Existing adapters handle nearest-even + rounding, Euclidean remainder, and clamp validation. `mul_add` uses + `std::fma` for a single rounding step. +- Require IEEE 754 binary64 and avoid fast-math modes that discard NaNs, + infinities, or signed zeros. `round_ties_even` must remain independent of + the ambient rounding mode without changing it. Compare transcendental + results with tolerances; NaN payloads and signs are unspecified. +- Invalid clamp bounds throw + `std::invalid_argument("invalid clamp bounds")`, including NaN bounds. + Other numeric domain failures produce NaN or infinity as specified by + the linked CEL language book. Unsupported signatures fail during parsing + with `cel::parse_error`. + +## Tests and documentation + +`tests/std_test.cpp` owns the doctest main. Its `evaluate` helper destroys +the parser before executing the emitted program, so expression tests also +exercise callback lifetime. The scalar case table covers both ordinary and +receiver syntax; separate cases cover closures, overload coexistence, +rejected signatures, floating-point edge cases, and tuple structure. + +`examples/example.cpp` is compiled and run by CTest and included directly +in the Doxygen tutorial. Keep that example consistent with the tutorial. +`README.md`, `docs/tutorial.md`, `docs/reference.md`, and the public header +feed the generated documentation. Use the CEL language-book links in +`docs/reference.md` for operation contracts, accounting for this port's +smaller type and operation set. From fbbfcbe1dc5b62afc3eac0ba7c8402adf267dbe3 Mon Sep 17 00:00:00 2001 From: sean-parent Date: Wed, 18 Nov 2026 22:32:31 -0800 Subject: [PATCH 3/3] Update cpp-library to 6.1.0 and cel-parser to 1.1.1 Use automatic license installation and initialize the shared install option before loading same-namespace dependencies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CMakeLists.txt | 12 ++++-------- docs/tutorial.md | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b058795..8e602ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.24) include(cmake/CPM.cmake) -CPMAddPackage("gh:stlab/cpp-library@6.0.2") +CPMAddPackage("gh:stlab/cpp-library@6.1.0") include("${cpp-library_SOURCE_DIR}/cpp-library.cmake") cpp_library_enable_dependency_tracking() @@ -9,9 +9,7 @@ project(std LANGUAGES CXX) include(CTest) -option(CEL_INSTALL "Enable installation for CEL libraries" ${PROJECT_IS_TOP_LEVEL}) -CPMAddPackage("gh:stlab/cel-parser@1.1.0") - +# Initialize the shared CEL_INSTALL default before same-namespace dependencies. cpp_library_setup( DESCRIPTION "The f64 CEL standard library" NAMESPACE cel @@ -19,13 +17,11 @@ cpp_library_setup( SOURCES std.cpp TESTS std_test.cpp EXAMPLES example.cpp + LICENSE_FILES licenses/CPM-MIT.txt DOCS_INPUTS README.md docs/tutorial.md docs/reference.md DOCS_EXCLUDE_SYMBOLS cel::op_lookup DOCS_OPTIONS "USE_MDFILE_AS_MAINPAGE = ${CMAKE_CURRENT_SOURCE_DIR}/README.md" ) +CPMAddPackage("gh:stlab/cel-parser@1.1.1") target_link_libraries(std PUBLIC cel::parser) -if(CEL_INSTALL) - install(FILES LICENSE licenses/CPM-MIT.txt - DESTINATION "${CMAKE_INSTALL_DATADIR}/licenses/cel-std") -endif() diff --git a/docs/tutorial.md b/docs/tutorial.md index 8d8c7df..924774c 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -69,7 +69,7 @@ fails. ## Consume an installed package -Install `cel-runtime` 1.1.1 and `cel-parser` 1.1.0 separately before installing +Install `cel-runtime` 1.1.2 and `cel-parser` 1.1.1 separately before installing `cel-std`. From the `cel-std` source directory, run: ```sh