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.
You might also like...
An okayish python script to generate a random Euler circuit with given number of vertices and edges.

Euler-Circuit-Test-Case-Generator An okayish python script to generate a random Euler circuit with given number of vertices and edges. Executing the S

Python 3 script unpacking statically x86 CryptOne packer.
Python 3 script unpacking statically x86 CryptOne packer.

Python 3 script unpacking statically x86 CryptOne packer. CryptOne versions: 2021/08 until now (2021/12)

A simple python script to generate an iCalendar file for the university classes.
A simple python script to generate an iCalendar file for the university classes.

iCal Generator This is a simple python script to generate an iCalendar file for the university classes. Installation Clone the repository git clone ht

A Python script that parses and checks public proxies. Multithreading is supported.
A Python script that parses and checks public proxies. Multithreading is supported.

A Python script that parses and checks public proxies. Multithreading is supported.

Python code to generate and store certificates automatically , using names from a csv file

WOC-certificate-generator Python code to generate and store certificates automatically , using names from a csv file IMPORTANT In order to make the co

Script to decrypt / import chromium (edge/chrome) cookies

Cloonie Script to decrypt / import chromium (edge/chrome) cookies. Requirements Install the python dependencies via pip: pip install -r requirements.t

Simple script to export contacts from telegram into vCard file

Telegram Contacts Exporter Simple script to export contacts from telegram into vCard file Getting Started Prerequisites You must to put your Telegram

A script to parse and display buy_tag and sell_reason for freqtrade backtesting trades

freqtrade-buyreasons A script to parse and display buy_tag and sell_reason for freqtrade backtesting trades Usage Copy the buy_reasons.py script into

aws ec2.py companion script to generate sshconfigs with auto bastion host discovery

ec2-bastion-sshconfig This script will interate over instances found by ec2.py and if those instances are not publically accessible it will search the

Owner
Julien VERNAY
French Student at Télécom-St-Etienne and UQAC (Canada). C - C++ - Python - Javascript
Julien VERNAY
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
SH-PUBLIC is a python based cloning script. You can clone unlimited UID facebook accounts by using this tool.

SH-PUBLIC is a python based cloning script. You can clone unlimited UID facebook accounts by using this tool. This tool works on any Android devices without root.

(Md. Tanvir Ahmed) 5 Mar 9, 2022
Find dependent python scripts of a python script in a project directory.

Find dependent python scripts of a python script in a project directory.

null 2 Dec 5, 2021
Python script to launch burp scans automatically

SimpleAutoBurp Python script that takes a config.json file as config and uses Burp Suite Pro to scan a list of websites.

Adan Álvarez 26 Jul 18, 2022
Small Python script to parse endlessh's output and print some neat statistics

endlessh_parser endlessh_parser is a small Python script that parses endlessh's output and prints some neat statistics about it Usage Install all the

ManicRobot 1 Oct 18, 2021
Helper script to bootstrap a Python environment with the tools required to build and install packages.

python-bootstrap Helper script to bootstrap a Python environment with the tools required to build and install packages. Usage $ python -m bootstrap.bu

Filipe Laíns 7 Oct 6, 2022
python script to generate color coded resistor images

Resistor image generator I got nerdsniped into making this. It's not finished at all, and the code is messy. The end goal it generate a whole E-series

MichD 1 Nov 12, 2021
A python script to generate wallpaper

wallpaper eits Warning You need to set the path to Robot Mono font in the source code. (Settings are in the main function) Usage A script that given a

Henrique Tsuyoshi Yara 5 Dec 2, 2021
Python script to get some stats on nodes in a Blender material nodetree

Python script to get some stats on nodes in a Blender material nodetree. It counts the nodes, the node types and the max deep level for group nodes.

Alek Mugnozzo 2 Sep 3, 2022
Daiho Tool is a Script Gathering for Windows/Linux systems written in Python.

Daiho is a Script Developed with Python3. It gathers a total of 22 Discord tools (including a RAT, a Raid Tool, a Nuker Tool, a Token Grabberr, etc). It has a pleasant and intuitive interface to facilitate the use of all with help and explanations for each of them.

AstraaDev 32 Jan 5, 2023