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
Simple Python tool that generates a pseudo-random password with numbers, letters, and special characters in accordance with password policy best practices.

Simple Python tool that generates a pseudo-random password with numbers, letters, and special characters in accordance with password policy best practices.

Joe Helle 7 Mar 25, 2022
Extract the download URL from OneDrive or SharePoint share link and push it to aria2

OneDriveShareLinkPushAria2 Extract the download URL from OneDrive or SharePoint share link and push it to aria2 从OneDrive或SharePoint共享链接提取下载URL并将其推送到a

高玩梁 262 Jan 08, 2023
Kanye West Lyrics Generator

aikanye Kanye West Lyrics Generator Python script for generating Kanye West lyrics Put kanye.txt in the same folder as the python script and run "pyth

4 Jan 21, 2022
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

Google Developer Student Club - IIIT Kalyani 10 May 26, 2022
Create C bindings for python automatically with the help of libclang

Python C Import Dynamic library + header + ctypes = Module like object! Create C bindings for python automatically with the help of libclang. Examples

1 Jul 25, 2022
Playing with python imports and inducing those pesky errors.

super-duper-python-imports In this repository we are playing with python imports and inducing those pesky ImportErrors. File Organization project │

James Kelsey 2 Oct 14, 2021
Dice Rolling Simulator using Python-random

Dice Rolling Simulator As the name of the program suggests, we will be imitating a rolling dice. This is one of the interesting python projects and wi

PyLaboratory 1 Feb 02, 2022
A Randomizer Oracle

Tezos Randomizer Tezod Randomizer "Oracle". It's a smart contract that you can call to get a random number between X and Y (for now). It uses entropy

Asbjorn Enge 19 Sep 13, 2022
Aurin - A quick AUR installer for Arch Linux. Install packages from AUR website in a click.

Aurin - A quick AUR installer for Arch Linux. Install packages from AUR website in a click.

Suleman 51 Nov 04, 2022
🍰 ConnectMP - An easy and efficient way to share data between Processes in Python.

ConnectMP - Taking Multi-Process Data Sharing to the moon 🚀 Contribute · Community · Documentation 🎫 Introduction : 🍤 ConnectMP is the easiest and

Aiden Ellis 1 Dec 24, 2021
Customized python validations.

A customized python validations.

Wilfred V. Pine 2 Apr 20, 2022
Python utility for discovering interesting CFPreferences values on iDevices

Description Simple utility to search for interesting preferences in iDevices. Installation python3 -m pip install -U --user cfprefsmon Example In this

12 Aug 19, 2022
MicroMIUI - Script to optimize miui and not only

MicroMIUI - Script to optimize miui and not only

Groiznyi-Studio 1 Nov 02, 2021
A small utility that sorts your files.

FileSorter A small utility that sorts your files. TODO: Scan directory to find files(thanks @corruptmemry for this!) Split extensions to determine fil

2 Jun 16, 2022
A python mathematics module

A python mathematics module

Fayas Noushad 4 Nov 28, 2021
A fixture that allows runtime xfail

pytest-runtime-xfail pytest plugin, providing a runtime_xfail fixture, which is callable as runtime_xfail(), to allow runtime decisions to mark a test

Brian Okken 4 Apr 06, 2022
Blender 2.93 addon for loading Quake II MD2 files

io_mesh_md2 is a Blender 2.93 addon for importing Quake II MD2 files.

Joshua Skelton 11 Aug 31, 2022
✨ Un générateur d'adresse IP aléatoire totalement fait en Python par moi, et en français.

IP Generateur ❗ Un générateur d'adresse IP aléatoire totalement fait en Python par moi, et en français. 🔮 Avec l'utilisation du module "random", j'ai

MrGabin 3 Jun 06, 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 02, 2021
These scripts look for non-printable unicode characters in all text files in a source tree

find-unicode-control These scripts look for non-printable unicode characters in all text files in a source tree. find_unicode_control.py should work w

Siddhesh Poyarekar 25 Aug 30, 2022