https://github.com/maxrt101/pybuild
Build tool for C++ projects
https://github.com/maxrt101/pybuild
build-tool cpp python3
Last synced: about 2 months ago
JSON representation
Build tool for C++ projects
- Host: GitHub
- URL: https://github.com/maxrt101/pybuild
- Owner: maxrt101
- Created: 2022-07-13T23:17:01.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-10T00:22:00.000Z (almost 4 years ago)
- Last Synced: 2025-04-05T18:51:31.553Z (about 1 year ago)
- Topics: build-tool, cpp, python3
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pybuild
Build tool for C++ written in python
## How to run
To build included example C++ project run `./example.py`
To run test run `./example.py test`
To run cppcheck run `./example.py cppcheck`
## About pybuild
pybuild is a build tool for C++ projects.
Main feaures are:
- Intuitive API for managing tasks, subtasks and dependencies
- Caching of last build time. Prevents from redundant rebuilds.
- A set of functions to perform common operations with C++ source/object files (compile, link into executables, shared or dynamic libraries)
## Example pybuild file
Simplest pybuild file could look like this:
```python
#!/usr/bin/env python3
from pybuild.config import format as cf # cf - config format, formats a string, replacing {} with corresponding config entry
import pybuild
@build.task()
def app(ctx):
pybuild.cpp.compile(cf('{topdir}/example/src/app.cc'))
pybuild.cpp.link_exe(
files=[cf('{build_dir}/{profile}/obj/app.o')],
output='app'
)
pybuild.cli.run('app') # 'app' is default task name
```
Main executable units of pybuild are called tasks.
To create a task define a function and annotate it with `@pybuild.task()`:
```python
@pybuild.task()
def app(ctx):
...
```
Tasks can have substasks. Subtasks are annotated with `@pybuild.subtask('parent task name')`.
```python
@pybuild.task()
def lib(ctx):
ctx.run_subtasks()
pybuild.cpp.create_static_lib(
files=pybuild.cpp.get_objs([
cf('{build_dir}/{profile}/obj/utils'),
cf('{build_dir}/{profile}/obj/core')
]),
output='libexample.a'
)
@pybuild.subtask('lib')
def core(ctx):
pybuild.cpp.compile_batch(pybuild.utils.get_files(cf('{topdir}/src/core'), r'.+\.cc'), 'core')
@pybuild.subtask('lib')
def utils(ctx):
pybuild.cpp.compile_batch(pybuild.utils.get_files(cf('{topdir}/src/utils'), r'.+\.cc'), 'utils')
```
Also tasks can depend on each other. Dependencies are passed as a list of task names to `build.task` annotation:
```python
@pybuild.task()
def install_headers(ctx):
...
@pybuild.task()
def dependencies(ctx):
ctx.run_subtasks()
@pybuild.task(['install_headers', 'dependencies'])
def lib(ctx):
...
```