A Python Wrapper for the API of the Tiny C Compiler (TCC)
Project description
pytcc
is a self-contained python extension for compiling C code (utilizing TCC).
What this extensions sets apart from other TCC extensions is, that no separate
TCC installation is required. By simply adding pytcc
to your
requirements.txt
your environment will be setup.
TCC is a full-fledged, blazing fast (up to 9 times faster compilation time than GCC) and extraordinary small (about 300 kb) C99 compiler originally written by Fabrice Bellard and now actively maintained by the community.
This extensions provides a pythonic interface of the API of TCC's tcclib. This library allows not only generating executables and libraries, but also running the generated code in the addressspace of your python process without the need of creating a file on disk.
Installation
The easiest way to install the tool is via pip:
pip install --upgrade pip # only needed if current pip version < 19.3
pip install pytcc
Alternatively you could build it on your own from source (see chapter "Howto build").
First Steps
To compile a bunch of C files to ank executable and run it (with include/library search path and macros specified):
import pytcc
import subprocess
tcc_setup = pytcc.TCC(include_dirs=['incl'], library_dirs=['libs'], MACRO="value")
exe_binary = tcc_setup.build_to_exe('exename', 'src1.c', 'src2.c')
subprocess.run([str(exe_binary.path)])
If you want to build dynamic library instead of an executable and you want to create it from in-memory source code it would look like:
import pytcc
import ctypes
tcc_setup = pytcc.TCC()
lib_binary = tcc_setup.build_to_lib('libname', pytcc.CCode('''
__attribute__((dllexport)) int func(int p) {
return p+1;
}
'''))
lib = ctypes.CDLL(str(lib_binary.path))
print(lib.func(123))
Alternatively you could build a library in memory and retrieve its symbols:
import pytcc
import ctypes
func_t = ctypes.CFUNCTYPE(None, ctypes.c_int)
tcc_setup = pytcc.TCC()
mem_binary = tcc_setup.build_to_mem('src1.c', 'src2.c')
var_obj = ctypes.c_int.from_address(mem_binary['var'])
func_obj = func_t(mem_binary['func'])
func_obj(var_obj)
Current status
- Provides tcclib API as pythonic interface
- Supports all major platforms:
- Windows x86 and x64
- macOS x64 (does not support executable/library generation yet and cannot find standard headers by default)
- linux x64
- Provide ready to use binary wheels for all supported platforms
Roadmap
- Make it work on macOS without manually referring to the headerfiles of XCode by adding the darwin headerfiles to the TCC package
- MAYBE: Extend TCC (and PyTCC) to provide access to AST
Howto Build
To build this extension the following software (apart from python) is required as prerequisites:
- CMake
- C Compiler
- tox [OPTIONAL]
First of all you have to build the TCC binaries by running cmake to create your platform specific project files and then build your project files. In the last step you build the python C-extension as wheel via setup.py.
Linux
>> cmake -B tinycc-bin/linux64
>> cmake --build tinycc-bin/linux64 --config Release
>> pip wheel -w wheels .
macOS
>> cmake -B tinycc-bin/mac64
>> cmake --build tinycc-bin/mac64 --config Release
>> pip wheel -w wheels .
Win32
>> cmake -A Win32 -B tinycc-bin/win32
>> cmake --build tinycc-bin/win32 --config Release
>> pip wheel -w wheels .
Win64
>> cmake -A x64 -B tinycc-bin/win64
>> cmake --build tinycc-bin/win64 --config Release
>> pip wheel -w wheels .
Alternatively you could choose any directory as output for the TCC libraries
build by cmake and set the environment variable TCC_BUILD_DIR
to the
corresponding directory.
If you want to run the unittests the recommended way is running tox after you built the TCC binaries.
Howto debug
To debug pytcc it is recommended to run cmake when the python environment that shall be used for the tests is activated. CMake will then create an additional target: "pytcc". This one can be used for creating the C extention without setup.py. As cmake is supported by most C IDEs you can use the resulting project file to debug the project:
For example on linux the sequence looks like:
>> source .tox/py36/bin/activate # tox has to be run before this command!
>> cd tinycc-bin/linux64
>> rm -R * # necessary as CMake cache has to be reset
>> cmake ../..
>> make pytcc
>> export PYTHONPATH=.
>> python -m pytest ../../tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file pytcc-0.9.27.1.1-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 534.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1950fc084e76d8d0265f42f1e659f0f98eb8f4ef22af68615350be2a61680233 |
|
MD5 | f46cbfe5e2bfd152de1209a443d49db4 |
|
BLAKE2b-256 | 758392313228a255e547fcc00e92f2e221d4b003e3cccb40f9b8c2c8270c267f |
File details
Details for the file pytcc-0.9.27.1.1-cp311-cp311-win32.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp311-cp311-win32.whl
- Upload date:
- Size: 500.4 kB
- Tags: CPython 3.11, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c000acf09375303ed21d9f2326078e21194536345e335d311e3b9e8cf8d1efe3 |
|
MD5 | 0edf504ab11e643b29f02280c12c0468 |
|
BLAKE2b-256 | 9b2efffa13df4c20ce7e85a013e6a7c1bc91826a630b33f45747d90b51c16b05 |
File details
Details for the file pytcc-0.9.27.1.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 534.9 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13825510638e8d3219ba6c86a71de92a952c88de7cb5400ffff8ad0a868f3bd3 |
|
MD5 | 2738c6acf0d34fb56c5686257fa24f77 |
|
BLAKE2b-256 | 9087b175a1c7a56465c0158d75cc8dcdfcff818c12a7cbd10f1493f73c95cd3b |
File details
Details for the file pytcc-0.9.27.1.1-cp310-cp310-win32.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp310-cp310-win32.whl
- Upload date:
- Size: 500.5 kB
- Tags: CPython 3.10, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98d4a67ea24684db4e53ce6cfbb3fe8c8dcf0978906dabbbb0f4b46cbe905d0e |
|
MD5 | e82f16304ce1f8e78af92fe557824bd9 |
|
BLAKE2b-256 | d8679fd37d8d078ce6ea1fef3628e16d192e5be9689b56bc4259e16ae8bc3ec5 |
File details
Details for the file pytcc-0.9.27.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 564.4 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b2979b2da090cc15fc387a7de7cec20658802f31a5675a92c051106e414d0ef |
|
MD5 | 3e055003a095f6c134caa1d9d878c9f1 |
|
BLAKE2b-256 | cbadad0d3f202b6032e24650e39557bbedd63fac295c6b84c0d8e3f0ea5e195c |
File details
Details for the file pytcc-0.9.27.1.1-cp310-cp310-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp310-cp310-macosx_10_15_x86_64.whl
- Upload date:
- Size: 236.9 kB
- Tags: CPython 3.10, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d348c9c978d51d00ced5ec60e32fe6cd59a510f7741ef83e4f613575de41489b |
|
MD5 | 3a2f755a33dc4d9383aecf364ffe9e1d |
|
BLAKE2b-256 | 7c1ec1adbb180456f98d4eeed29bf75e3636e966501f37f07044e3d0dd6fd6c4 |
File details
Details for the file pytcc-0.9.27.1.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 536.5 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52f2c8f17514e72232c141ea2eab236e585e0793538310dd80ae1ad7f12f9616 |
|
MD5 | 027ee04f42d334e123a89f5e959b7641 |
|
BLAKE2b-256 | 05aceb41e0103cb07e1c125fa8316adcc3f0eba5304537135e25a9a6011eb1c2 |
File details
Details for the file pytcc-0.9.27.1.1-cp39-cp39-win32.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp39-cp39-win32.whl
- Upload date:
- Size: 501.7 kB
- Tags: CPython 3.9, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12956e5299c0190ec9fba5af3b7a92bd2019106709d4bfef9f577e51b3873cb4 |
|
MD5 | a128e640f116413be7e98b277cb8589e |
|
BLAKE2b-256 | ecb0e85811da8a9590cfefcdfe069180178e184ccf61fc841c1a1c4a8d787c58 |
File details
Details for the file pytcc-0.9.27.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 568.2 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | baf200cb2d87662a9d796bd2d1dda16299281477034df6480381728f94956b48 |
|
MD5 | 6f75f152c598a37cb1f17d3ecd527d12 |
|
BLAKE2b-256 | c9cc7d9ae8bf373fafedd65196c6b3354a95f1cd76e2206c435baf04317377b1 |
File details
Details for the file pytcc-0.9.27.1.1-cp39-cp39-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp39-cp39-macosx_10_15_x86_64.whl
- Upload date:
- Size: 235.0 kB
- Tags: CPython 3.9, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be5848adaa586a2c18aa414902f7ccdcfd5a6077f18aa70d7f917ee76e64292e |
|
MD5 | 09f01cea94c5d2490bd005e554e7ad65 |
|
BLAKE2b-256 | 15833914738982d33b22e89d23428cfdda3b04b1092916db12e23eed2e1881a9 |
File details
Details for the file pytcc-0.9.27.1.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 537.0 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 300a16de659e30f1e200ee06be4760822b8ea7cb44a9843aa9fb8ee583cefeb8 |
|
MD5 | 6c0d7b59e97a288ab555e3d18328e4f3 |
|
BLAKE2b-256 | 1ebc0d5324d9e58a4e7573635b11efb898237b67ae593efea9340840fe677c08 |
File details
Details for the file pytcc-0.9.27.1.1-cp38-cp38-win32.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp38-cp38-win32.whl
- Upload date:
- Size: 502.1 kB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0afcf21a0ce389ec62cac09cb64981dd272235f453f678094b337ad24558fa00 |
|
MD5 | 7f22213607c293cde03d1aea3c0e4254 |
|
BLAKE2b-256 | 0619ebf98ef0cc38f6058ca1056661d1cac2e29c25f0e98478dfa4a3c3a51c57 |
File details
Details for the file pytcc-0.9.27.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 577.1 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d002b248b932be8d3397e15d9966524ceee2227c8eb4f4135bcd0c66b0995d77 |
|
MD5 | b5b5f42f92e62f2a11c201de1947450e |
|
BLAKE2b-256 | 6758e79d6b6b9b845b8ed34e71f302095dee7a8d0e0cfd0fb7acad501d996928 |
File details
Details for the file pytcc-0.9.27.1.1-cp38-cp38-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp38-cp38-macosx_10_15_x86_64.whl
- Upload date:
- Size: 234.0 kB
- Tags: CPython 3.8, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eda24e45258fb0ef6389303763d77af44e9a4e410798231b345ab609f21b528b |
|
MD5 | e2342975c02b87c8075b46e68416c054 |
|
BLAKE2b-256 | 08a20f37f338aea97cd4b22763b95a03ea83c482087ce7e5f23aec3f377d8517 |
File details
Details for the file pytcc-0.9.27.1.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 534.5 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df74f614c5f146bc5ce5e44e79955b03e8dc6c368b09f3056494de9e6401c7b5 |
|
MD5 | c94fb34d5cce6845e961427dea6cd1f2 |
|
BLAKE2b-256 | 3b598c6689bd8657fffa0bd544d6a3dccd3cc29381af4de61678f9dca8d6cfb2 |
File details
Details for the file pytcc-0.9.27.1.1-cp37-cp37m-win32.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp37-cp37m-win32.whl
- Upload date:
- Size: 500.5 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ab8a963d434b53ff8fe56624074e41ab334727d829b182c8ffc40781a2e6dc7 |
|
MD5 | 697bd7eb925be8fd30ff4a8bb78bc486 |
|
BLAKE2b-256 | 673d0fa4211126fac2dec17985bc9b7f597bae04d42c7cfce96bfa414d157a53 |
File details
Details for the file pytcc-0.9.27.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 527.5 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fb79f7fcf84b8c16cc1096f77713c24846656f838bf32236e715de591003d5d |
|
MD5 | 98b726f181f626d8ddd5c99fc7f0d07e |
|
BLAKE2b-256 | 7edbee6ca43f82fe36cdcd5104162490aab3c89ac46aac0d4c57fbc9cc87b9e6 |
File details
Details for the file pytcc-0.9.27.1.1-cp37-cp37m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp37-cp37m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 232.4 kB
- Tags: CPython 3.7m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94a8d10cddbaf03ea8e465c3b08ae9a1927a622fda011e4848e2549c7fdd0c5a |
|
MD5 | a5f5a7426ff19cf728966f4e34e7704b |
|
BLAKE2b-256 | 9ffd2ce6b9a00792ff49070c22919f29cff0581e3b0fccec7b391f2cfd3365c4 |
File details
Details for the file pytcc-0.9.27.1.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 540.2 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 175ce635565736220932ebd19b3f305f77bf2c859a2bbdbb99dd8a394bfc25e9 |
|
MD5 | adcc6fd480f678b3802ec5132c82dc35 |
|
BLAKE2b-256 | 9cddb74a42b083769895f1d92394ecb7011672a99fa8d2dbcbcacbd231bb413f |
File details
Details for the file pytcc-0.9.27.1.1-cp36-cp36m-win32.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp36-cp36m-win32.whl
- Upload date:
- Size: 503.5 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a91d11f66b53165a7642ccd83894ae23acf19655b4d2346d19a199629f77d7a |
|
MD5 | 922d32cb9607a4ff12529f3a8446fb6e |
|
BLAKE2b-256 | 3314a37670e2eaa895fec4fe9df0e509cab308cf7ca2039faeba3221ceb97774 |
File details
Details for the file pytcc-0.9.27.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 532.4 kB
- Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5308d2001fb7d4bf7adde0112ddbd1f45b7ad2ddca5a70c751bd4604bb7bc16b |
|
MD5 | b0e6840a6a8db931112c87bf1f508597 |
|
BLAKE2b-256 | 4b993d0c1cf9094e02e7daef52e716e08cd67ec54a0c0f5a10229ae66d5f98cb |
File details
Details for the file pytcc-0.9.27.1.1-cp36-cp36m-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: pytcc-0.9.27.1.1-cp36-cp36m-macosx_10_14_x86_64.whl
- Upload date:
- Size: 232.1 kB
- Tags: CPython 3.6m, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c0c4ce73bf14e4bebe81f0aa1c35bee34b9a4659c95288d11b89d01792e8b89 |
|
MD5 | bd98446eaafe9d14d0ccdacd2144c074 |
|
BLAKE2b-256 | 8efc56f4eedca838c6a6174a3297f7745f18241c2b3eb8f96d6184cafa3508a7 |