cpp20.py is a Python script to compile C++20 code using modules.

Overview

cpp20.py

cpp20.py is a Python script to compile C++20 code using modules. It browses the source files to determine their dependencies. Then, it compiles then in order using the correct flags.

NEW: You can use the --cache option to reuse artifacts from previous builds. Caching is done only by comparing modification times of files. Caching is not robust and may be invalidated due to modifying files without updating modification times forward, or changing compilation flags. In these cases, remove the --cache flag to cause a full rebuild.

Dependencies:

  • g++ >= 11 (for C++20 module implementations)
  • Python >= 3.9 (for graphlib.TopologicalSorter)

Usage:

The most basic usage is:

python3 cpp20.py

This will compile all source files found in the current directory (recursively) into an executable myproj.

You can specify what is the result of the compilation:

python3 cpp20.py --lib=abc --so=abc --exe=abc
  • --lib={} will create the static library lib{}.a
  • --so={} will create the shared library lib{}.so
  • --exe={} will create the executable {}

You can specify which directories and patterns to look for:

python3 cpp20.py dir1 dir2 --patterns="*.hpp,*.cpp,*.h" --patterns+="*.cppm" --patterns-="*.h"
  • --patterns= specifies the patterns of filenames to inspect. The default is *.h,*.c,*.hxx,*.cxx,*.ixx,*.mxx,*.hpp,*.cpp,*.cppm
  • --patterns+= specifies additional patterns (useful if you want to keep default patterns)
  • --patterns-= specifies patterns to exclude

You can display informations about browsed files:

python3 cpp20.py --show=list,deps,order,cmd

Any comma-separated list of either list, deps, order and cmd is allowed. Each option will output a block of lines to the standard output. By default, the project will still be built. You can pass --nobuild to only output the informations without building the project. By default, paths are displayed relatively to the current directory. This works only if all involved files are inside the current directory (potentially recursively). If this is not the case or if you want to display absolute paths, you can pass --absolutepaths.

list will output a CSV line per file, with their kind (one of primary-module-interface, module-partition-interface, module-partition, module-unit, global-unit, header-unit, header or system-header-unit) and their module name (or empty).

...$python3 cpp20.py --show=list
"example/A.cppm", primary-module-interface, A
"example/A0.cpp", module-partition, A:p0
"example/A1.cppm", module-partition-interface, A:p1
"example/B.ixx", primary-module-interface, B
"example/B0.mxx", module-partition-interface, B:p0
"example/Bimpl.cxx", module-unit, B
"example/C.cpp", primary-module-interface, C
"example/H.hpp", header,
"example/H0.h", header-unit,
"example/H1.hxx", header,
"example/main.cpp", global-unit,
"sys:cstdio", system-header-unit,
"sys:iostream", header,
"sys:string_view", system-header-unit,

deps will show each file followed by their dependencies.

...$python3 cpp20.py --show=deps
"example/A.cppm", "sys:string_view", "example/A1.cppm"
"example/A0.cpp", "sys:iostream"
"example/A1.cppm",
"example/B.ixx",
"example/B0.mxx", "example/H0.h"
"example/Bimpl.cxx", "example/H.hpp", "example/A.cppm"
"example/C.cpp", "example/H.hpp", "example/A.cppm", "example/B.ixx"
"example/H.hpp", "example/H1.hxx"
"example/H0.h",
"example/H1.hxx", "example/H0.h"
"example/main.cpp", "example/C.cpp", "sys:cstdio"

order will display lines of paths, such that each file is on a line after its dependencies.

...$python3 cpp20.py --show=order
"example/B.ixx", "sys:iostream", "example/H0.h", "example/A1.cppm", "sys:cstdio", "sys:string_view"
"example/A0.cpp", "example/B0.mxx", "example/H1.hxx", "example/A.cppm"
"example/H.hpp"
"example/C.cpp", "example/Bimpl.cxx"
"example/main.cpp"

cmd will display commands to be executed. Each group of command can be executed in parallel.

...$python3 cpp20.py --show=cmd
mkdir -p /home/julien/Bureau/cpp20.py/obj/example

g++ -std=c++20 -fmodules-ts -x c++ example/A1.cppm -c -o /home/julien/Bureau/cpp20.py/obj/example/A1.cppm.o
g++ -std=c++20 -fmodules-ts -x c++ example/B.ixx -c -o /home/julien/Bureau/cpp20.py/obj/example/B.ixx.o
g++ -std=c++20 -fmodules-ts -x c++-header example/H0.h
g++ -std=c++20 -fmodules-ts -x c++-system-header cstdio
g++ -std=c++20 -fmodules-ts -x c++-system-header string_view

g++ -std=c++20 -fmodules-ts -x c++ example/A.cppm -c -o /home/julien/Bureau/cpp20.py/obj/example/A.cppm.o
g++ -std=c++20 -fmodules-ts -x c++ example/A0.cpp -c -o /home/julien/Bureau/cpp20.py/obj/example/A0.cpp.o
g++ -std=c++20 -fmodules-ts -x c++ example/B0.mxx -c -o /home/julien/Bureau/cpp20.py/obj/example/B0.mxx.o


g++ -std=c++20 -fmodules-ts -x c++ example/Bimpl.cxx -c -o /home/julien/Bureau/cpp20.py/obj/example/Bimpl.cxx.o
g++ -std=c++20 -fmodules-ts -x c++ example/C.cpp -c -o /home/julien/Bureau/cpp20.py/obj/example/C.cpp.o

g++ -std=c++20 -fmodules-ts -x c++ example/main.cpp -c -o /home/julien/Bureau/cpp20.py/obj/example/main.cpp.o

g++ /home/julien/Bureau/cpp20.py/obj/example/A1.cppm.o /home/julien/Bureau/cpp20.py/obj/example/B.ixx.o /home/julien/Bureau/cpp20.py/obj/example/B0.mxx.o /home/julien/Bureau/cpp20.py/obj/example/A0.cpp.o /home/julien/Bureau/cpp20.py/obj/example/A.cppm.o /home/julien/Bureau/cpp20.py/obj/example/C.cpp.o /home/julien/Bureau/cpp20.py/obj/example/Bimpl.cxx.o /home/julien/Bureau/cpp20.py/obj/example/main.cpp.o -o myprog

rm -r obj gcm.cache

Limitations

  • Limitations inherited from g++ implementation.
  • The parser will recognize declarations inside multiline comments.
  • Comments inside declarations (module /*test*/ hello;) are not supported.
Owner
Julien VERNAY
French Student at Télécom-St-Etienne and UQAC (Canada). C - C++ - Python - Javascript
Julien VERNAY
Genart - Generate random art to sell as nfts

Genart - Generate random art to sell as nfts Usage git clone

Will 13 Mar 17, 2022
A library from RCTI+ to handle RabbitMQ tasks (connect, send, receive, etc) in Python.

Introduction A library from RCTI+ to handle RabbitMQ tasks (connect, send, receive, etc) in Python. Requirements Python =3.7.3 Pika ==1.2.0 Aio-pika

Dali Kewara 1 Feb 05, 2022
MongoDB utility to inflate the contents of small collection to a new larger collection

MongoDB Data Inflater ("data-inflater") The data-inflater tool is a MongoDB utility to automate the creation of a new large database collection using

Paul Done 3 Nov 28, 2021
Spacegit is a .git exposed finder

Spacegit Spacegit is a basic .git exposed finder Usage: You need python3 installed to run spacegit use: python3 spacegit.py (url) Disclaimer: **This i

2 Nov 30, 2021
Random Number Generator

Application for generating a random number.

Michael J Bailey 1 Oct 12, 2021
This repository contains scripts that help you validate QR codes.

Validation tools This repository contains scripts that help you validate QR codes. It's hacky, and a warning for Apple Silicon users: the dependencies

Ryan Barrett 8 Mar 01, 2022
A sys-botbase client for remote control automation of Nintendo Switch consoles. Based on SysBot.NET, written in python.

SysBot.py A sys-botbase client for remote control automation of Nintendo Switch consoles. Based on SysBot.NET, written in python. Setup: Download the

7 Dec 16, 2022
Dependency Injector is a dependency injection framework for Python.

What is Dependency Injector? Dependency Injector is a dependency injection framework for Python. It helps implementing the dependency injection princi

ETS Labs 2.6k Jan 04, 2023
Install, run, and update apps without root and only in your home directory

Qube Apps Install, run, and update apps in the private storage of a Qube. Build and install in Qubes Get the code: git clone https://github.com/micahf

Micah Lee 26 Dec 27, 2022
Rabbito is a mini tool to find serialized objects in input values

Rabbito-ObjectFinder Rabbito is a mini tool to find serialized objects in input values What does Rabbito do Rabbito has the main object finding Serial

7 Dec 13, 2021
This script allows you to retrieve all functions / variables names of a Python code, and the variables values.

Memory Extractor This script allows you to retrieve all functions / variables names of a Python code, and the variables values. How to use it ? The si

Venax 2 Dec 26, 2021
NetConfParser is a tool that helps you analyze the rpcs coming and going from a netconf client to a server

NetConfParser is a tool that helps you analyze the rpcs coming and going from a netconf client to a server

Aero 1 Mar 31, 2022
A thing to simplify listening for PG notifications with asyncpg

asyncpg-listen This library simplifies usage of listen/notify with asyncpg: Handles loss of a connection Simplifies notifications processing from mult

ANNA 18 Dec 23, 2022
An online streamlit development platform

streamlit-playground An online streamlit development platform Run, Experiment and Play with streamlit Components Develop full-fledged apps online All

Akshansh Kumar 3 Nov 06, 2021
Simple tool for creating changelogs

Description Simple utility for quickly generating changelogs, assuming your commits are ordered as they should be. This tool will simply log all lates

2 Jan 05, 2022
Python @deprecat decorator to deprecate old python classes, functions or methods.

deprecat Decorator Python @deprecat decorator to deprecate old python classes, functions or methods. Installation pip install deprecat Usage To use th

12 Dec 12, 2022
convert a dict-list object from / to a typed object(class instance with type annotation)

objtyping 带类型定义的对象转换器 由来 Python不是强类型语言,开发人员没有给数据定义类型的习惯。这样虽然灵活,但处理复杂业务逻辑的时候却不够方便——缺乏类型检查可能导致很难发现错误,在IDE里编码时也没

Song Hui 15 Dec 22, 2022
python-codicefiscale: a tiny library for encode/decode Italian fiscal code - codifica/decodifica del Codice Fiscale.

python-codicefiscale python-codicefiscale is a tiny library for encode/decode Italian fiscal code - codifica/decodifica del Codice Fiscale. Features T

Fabio Caccamo 53 Dec 14, 2022
Export watched content from Tautulli to the Letterboxd CSV Import Format

Export watched content from Tautulli to the Letterboxd CSV Import Format

Evan J 5 Aug 31, 2022
A simple tool to extract python code from a Jupyter notebook, and then run pylint on it for static analysis.

Jupyter Pylinter A simple tool to extract python code from a Jupyter notebook, and then run pylint on it for static analysis. If you find this tool us

Edmund Goodman 10 Oct 13, 2022