{"id":17769862,"url":"https://github.com/wojciechmula/cleanup-headers","last_synced_at":"2026-03-06T02:07:42.687Z","repository":{"id":66099953,"uuid":"118229607","full_name":"WojciechMula/cleanup-headers","owner":"WojciechMula","description":"Remove unnecessary includes from C/C++ source files","archived":false,"fork":false,"pushed_at":"2018-10-04T17:23:15.000Z","size":14,"stargazers_count":27,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T16:21:14.715Z","etag":null,"topics":["c","cpp","dependencies","includes"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WojciechMula.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-20T09:40:24.000Z","updated_at":"2024-02-14T15:44:42.000Z","dependencies_parsed_at":"2023-04-27T14:47:11.716Z","dependency_job_id":null,"html_url":"https://github.com/WojciechMula/cleanup-headers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WojciechMula/cleanup-headers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WojciechMula%2Fcleanup-headers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WojciechMula%2Fcleanup-headers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WojciechMula%2Fcleanup-headers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WojciechMula%2Fcleanup-headers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WojciechMula","download_url":"https://codeload.github.com/WojciechMula/cleanup-headers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WojciechMula%2Fcleanup-headers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30158946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T22:39:40.138Z","status":"online","status_checked_at":"2026-03-06T02:00:08.268Z","response_time":250,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cpp","dependencies","includes"],"created_at":"2024-10-26T21:19:24.926Z","updated_at":"2026-03-06T02:07:42.666Z","avatar_url":"https://github.com/WojciechMula.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"================================================================================\n                            Cleanup C++/C headers\n================================================================================\n\nThis simple script helps in removing unnecessary includes from C/C++ files.\n\nA huge code base or legacy code usually means that implementation files are\nfull of includes pilled up over years. Likewise, creating a new project by\nforking an old one ends up with tons of leftovers.\n\n\nHow it works?\n-----------------------------------------------------------\n\nThe only thing you need is **the full command** that creates an object file.\n\nThe script systematically comments out one include file at once and recompiles\nsource. When program/object file still compiles, then the commented out include\nis considered unneeded.\n\n**Caveat 1** (noticed by my colleague Leszek): such a mechanical way of removing\nincludes may lead to creating indirect dependencies. Some symbols required by\nimplementation might be provided (accidentally) by includes present in headers\nfiles. When one remove include from the implementation file, then later changes\nto the header file might break the compilation.\n\n**Caveat 2**: the script doesn't interpret any other preprocessor directive\nthan ``#include``. Conditional includes enabled by ``ifdefs`` will be removed\nunconditionally.\n\n\nHow to use it?\n-----------------------------------------------------------\n\nHere's an example from my toy project https://github.com/WojciechMula/avx512popcnt-superoptimizer\n\nThe head of the main program::\n\n    $ head -n 15 avx512popcnt.cpp\n    #include \u003ccstdint\u003e\n    #include \u003ccstdlib\u003e\n    #include \u003ccstdio\u003e\n    #include \u003ccassert\u003e\n    #include \u003cvector\u003e\n    #include \u003cmemory\u003e\n    #include \u003crandom\u003e\n    #include \u003calgorithm\u003e\n    #include \u003cbitset\u003e\n\n    #include \u003csys/types.h\u003e\n    #include \u003cunistd.h\u003e\n\n    #include \"binary.cpp\"\n\nWhen run ``make``, we capture the command which builds the program::\n\n    $ make avx512popcnt\n    g++ -Wall -Wextra -pedantic -std=c++14 -O3 avx512popcnt.cpp -o lineavx512popcnt\n\nNow the script comes::\n\n    $ python cleanup.py g++ -Wall -Wextra -pedantic -std=c++14 -O3 avx512popcnt.cpp -o avx512popcnt\n    Checking compilation of avx512popcnt.cpp... OK\n    Removing cstdint (1/12)... OK\n    Removing cstdlib (2/12)... OK\n    Removing cstdio (3/12)... OK\n    Removing cassert (4/12)... not possible\n    Removing vector (5/12)... OK\n    Removing memory (6/12)... not possible\n    Removing random (7/12)... not possible\n    Removing algorithm (8/12)... OK\n    Removing bitset (9/12)... OK\n    Removing sys/types.h (10/12)... OK\n    Removing unistd.h (11/12)... not possible\n    Removing binary.cpp (12/12)... not possible\n    avx512popcnt.cpp: not required cstdint, cstdlib, cstdio, vector, algorithm, bitset, sys/types.h\n    avx512popcnt.cpp was updated\n\nIt turned out that eight includes weren't needed at all.\n\n\nConfiguration\n-----------------------------------------------------------\n\nYou can control behaviour of the script via a config file. The config\nfile must be located either in ``~/.config/cleanup-headers/config.ini``\nor its path must be provided by the environment variable\n``CLEANUP_HEADERS_CONFIG``. Please refer to the sample ``config.ini``\nfor more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwojciechmula%2Fcleanup-headers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwojciechmula%2Fcleanup-headers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwojciechmula%2Fcleanup-headers/lists"}