diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6aa8282e..4d0c6b4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,13 +15,12 @@ jobs: - name: Install unit tests requirements run: | - python3 -m venv .env - . .env/bin/activate - pip install -r tests/unit_tests/requirements.txt + pipx install uv + uv sync - name: Build run: | - . .env/bin/activate + . .venv/bin/activate cmake . \ -Bbuild \ @@ -83,13 +82,12 @@ jobs: - name: Install unit tests requirements run: | - python3 -m venv .env - . .env/bin/activate - pip install -r tests/unit_tests/requirements.txt + pipx install uv + uv sync - name: Build run: | - . .env/bin/activate + . .venv/bin/activate cmake . \ -Bbuild \ @@ -112,10 +110,13 @@ jobs: - name: Install unit tests requirements run: | - pip install -r tests\unit_tests\requirements.txt + pipx install uv + uv sync - name: Build run: | + .\.venv\Scripts\activate + cmake . -Bbuild cmake --build build --config Release @@ -181,13 +182,12 @@ jobs: - name: Install unit tests requirements run: | - python3 -m venv .env - . .env/bin/activate - pip install -r tests/unit_tests/requirements.txt + pipx install uv + uv sync - name: Build run: | - . .env/bin/activate + . .venv/bin/activate cmake . \ -Bbuild \ diff --git a/README.md b/README.md index 0228ab5a..e3c15b4d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # A compiler front end for the C++ language -cxx-frontend is a work-in-progress compiler frontend for C++23 +cxx-frontend is a work-in-progress compiler frontend for C++26 and C23 The compiler frontend is designed to be a powerful tool for developers, enabling them to parse, analyze, and modify C++ source code. This project aims to provide a robust foundation for building a complete C++ frontend, staying up-to-date with the latest language features and standards. @@ -17,53 +17,60 @@ For updates, improvements, and recent features in cxx-frontend, please consult t - **Multi-Language Support**: In addition to C++, the library provides APIs for TypeScript and JavaScript. -- **C++-23 Support**: Latest language enhancements, syntax, and features (WIP). +- **C++-26 and C23 Support**: Latest language enhancements, syntax, and features (WIP). -## Syntax Checker and AST Browser Showcase +## Playground -Storybook and CodeMirror are used to demonstrate how to create a syntax checker and navigate the Abstract Syntax Tree (AST) +The playground uses the Monaco Editor to demonstrate how to create a syntax checker and navigate the Abstract Syntax Tree (AST). https://robertoraggi.github.io/cplusplus/ -## Installing from npm +## Native Build and CLI tools -To integrate the latest stable version of the C++ Compiler Frontend bindings into your project, you can install them from npm: +On Linux, macOS and Windows: + +install the python packages required to run the unit tests (optional) ```sh -npm install cxx-frontend +uv sync && source .venv/bin/activate ``` -Once installed, you can use the bindings in your Node.js or web projects as needed. +configure the source code -## Getting Started Using Example Projects +```sh +cmake --preset default +``` -These projects are pre-configured and serve as starting points for various [use cases](https://github.com/robertoraggi/cplusplus/tree/main/templates). +build -For Node.js +```sh +cmake --build build +``` + +run the unit tests ```sh -npx degit robertoraggi/cplusplus/templates/cxx-parse cxx-parse -cd cxx-parse -npm install -node . +cd build +ctest --progress ``` -For web-based applications, use these commands to clone, set up, and start a development server: +Dump the AST to stdout ```sh -npx degit robertoraggi/cplusplus/templates/cxx-browser-esm-vite cxx-browser-esm-vite -cd cxx-browser-esm-vite -npm install -npm run dev + ./build/src/frontend/cxx tests/manual/source.cc -ast-dump ``` ## Build the npm package (requires docker) +prepare the package + ```sh -# prepare the package npm ci +``` + +compile WASM and TypeScript code -# compile WASM and TypeScript code +```sh npm run build:cxx-frontend ``` @@ -72,8 +79,11 @@ npm run build:cxx-frontend ```sh npm ci npm run build:wasi +``` -# run the C++ front end CLI tool using wasmtime +run the C++ front end CLI tool using wasmtime + +```sh wasmtime \ --mapdir=/::build.wasi/install \ --mapdir tests::tests \ @@ -81,46 +91,36 @@ wasmtime \ tests/manual/source.cc -ast-dump ``` -## Native Build and CLI tools +## Installing from npm -On Linux, macOS and Windows: +To integrate the latest stable version of the C++ Compiler Frontend bindings into your project, you can install them from npm: ```sh -# install the python packages required to run the unit tests (optional) -pip install -r tests/unit_tests/requirements.txt - -# configure the source code -cmake . \ - -G Ninja \ - -B build \ - -DCMAKE_BUILD_TYPE=Release \ - -DCXX_INTERPROCEDURAL_OPTIMIZATION=1 +npm install cxx-frontend +``` -# build -cmake --build build +Once installed, you can use the bindings in your Node.js or web projects as needed. -# run the unit tests -cd build -ctest --progress -``` +## Getting Started Using Example Projects -## Serialize the AST +These projects are pre-configured and serve as starting points for various [use cases](https://github.com/robertoraggi/cplusplus/tree/main/templates). -Use `-emit-ast` to serialize the AST of a C++ program to a flatbuffer binary file +For Node.js ```sh -# serialize the AST -$ ./build/src/frontend/cxx -emit-ast source.cc -o source.ast +npx degit robertoraggi/cplusplus/templates/cxx-parse cxx-parse +cd cxx-parse +npm install +node . ``` -You can use any flatbuffers supported decoder to read the AST, e.g. +For web-based applications, use these commands to clone, set up, and start a development server: ```sh -# Use flatc to dump the AST to JSON -$ ./build/_deps/flatbuffers-build/flatc --raw-binary -t build/src/parser/cxx/ast.bfbs -- source.ast - -$ ll source.* -source.ast source.cc source.json +npx degit robertoraggi/cplusplus/templates/cxx-browser-esm-vite cxx-browser-esm-vite +cd cxx-browser-esm-vite +npm install +npm run dev ``` ## License diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..5878ebca --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "cplusplus" +version = "1.1.27" +description = "A compiler frontend for C++23" +readme = "README.md" +requires-python = ">=3.11" +dependencies = [ + "filecheck>=1.0.2", + "lit>=18.1.8", +] diff --git a/tests/unit_tests/requirements.txt b/tests/unit_tests/requirements.txt deleted file mode 100644 index 36cfdee1..00000000 --- a/tests/unit_tests/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -lit==18.1.8 -filecheck==0.0.24 diff --git a/uv.lock b/uv.lock new file mode 100644 index 00000000..96f38d65 --- /dev/null +++ b/uv.lock @@ -0,0 +1,36 @@ +version = 1 +revision = 2 +requires-python = ">=3.11" + +[[package]] +name = "cplusplus" +version = "1.1.27" +source = { virtual = "." } +dependencies = [ + { name = "filecheck" }, + { name = "lit" }, +] + +[package.metadata] +requires-dist = [ + { name = "filecheck", specifier = ">=1.0.2" }, + { name = "lit", specifier = ">=18.1.8" }, +] + +[[package]] +name = "filecheck" +version = "1.0.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/54/c3/2c1c282331ccf4866043ac2a663ac38f0d8a867b76bb5ea8765104c9e971/filecheck-1.0.2.tar.gz", hash = "sha256:49d2a56e37a8ff9db62ecf33a37c5343fa2bf32e53321339687b0dceb3e09828", size = 19901, upload-time = "2025-05-07T09:00:46.765Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/da/54/b1370c4c4b9bbcae69c535b30c106d114e2b28cdf7e28842a315bbd9d19d/filecheck-1.0.2-py3-none-any.whl", hash = "sha256:af950e48a82c3923d945d8688b69ff4879c7ec0e9739b17b41a3326a980419ff", size = 23723, upload-time = "2025-05-07T09:00:45.458Z" }, +] + +[[package]] +name = "lit" +version = "18.1.8" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/47/b4/d7e210971494db7b9a9ac48ff37dfa59a8b14c773f9cf47e6bda58411c0d/lit-18.1.8.tar.gz", hash = "sha256:47c174a186941ae830f04ded76a3444600be67d5e5fb8282c3783fba671c4edb", size = 161127, upload-time = "2024-06-25T14:33:14.489Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/96/06/b36f150fa7c5bcc96a31a4d19a20fddbd1d965b6f02510b57a3bb8d4b930/lit-18.1.8-py3-none-any.whl", hash = "sha256:a873ff7acd76e746368da32eb7355625e2e55a2baaab884c9cc130f2ee0300f7", size = 96365, upload-time = "2024-06-25T14:33:12.101Z" }, +]