emx-onnx-cgen 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of emx-onnx-cgen might be problematic. Click here for more details.
- emx_onnx_cgen-0.2.0/MANIFEST.in +1 -0
- emx_onnx_cgen-0.2.0/PKG-INFO +128 -0
- emx_onnx_cgen-0.2.0/README.md +121 -0
- emx_onnx_cgen-0.2.0/build_backend.py +81 -0
- emx_onnx_cgen-0.2.0/pyproject.toml +20 -0
- emx_onnx_cgen-0.2.0/setup.cfg +4 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/__init__.py +6 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/__main__.py +9 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/_build_info.py +4 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/cli.py +328 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/codegen/__init__.py +25 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/codegen/c_emitter.py +9044 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/compiler.py +601 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/dtypes.py +40 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/errors.py +14 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/ir/__init__.py +3 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/ir/model.py +55 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/__init__.py +3 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/arg_reduce.py +99 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/attention.py +421 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/average_pool.py +229 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/batch_normalization.py +116 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/cast.py +70 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/common.py +72 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/concat.py +31 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/constant_of_shape.py +85 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/conv.py +192 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/cumsum.py +118 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/depth_space.py +114 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/dropout.py +46 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/elementwise.py +164 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/expand.py +151 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/eye_like.py +43 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/flatten.py +60 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/gather.py +48 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/gather_elements.py +60 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/gemm.py +139 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/grid_sample.py +149 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/group_normalization.py +68 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/identity.py +43 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/instance_normalization.py +50 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/layer_normalization.py +110 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/logsoftmax.py +47 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/lp_normalization.py +45 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/lrn.py +104 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/lstm.py +355 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/matmul.py +120 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/maxpool.py +195 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/mean_variance_normalization.py +49 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/negative_log_likelihood_loss.py +250 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/pad.py +287 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/range.py +104 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/reduce.py +544 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/registry.py +51 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/reshape.py +188 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/resize.py +445 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/rms_normalization.py +67 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/shape.py +78 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/size.py +33 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/slice.py +425 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/softmax.py +47 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/softmax_cross_entropy_loss.py +129 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/split.py +150 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/squeeze.py +161 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/tile.py +81 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/transpose.py +46 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/unsqueeze.py +157 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/variadic.py +95 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/lowering/where.py +73 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/onnx_import.py +261 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/ops.py +565 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/runtime/__init__.py +1 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/runtime/evaluator.py +2206 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen/validation.py +76 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen.egg-info/PKG-INFO +128 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen.egg-info/SOURCES.txt +91 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen.egg-info/dependency_links.txt +1 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen.egg-info/entry_points.txt +2 -0
- emx_onnx_cgen-0.2.0/src/emx_onnx_cgen.egg-info/top_level.txt +2 -0
- emx_onnx_cgen-0.2.0/src/shared/__init__.py +2 -0
- emx_onnx_cgen-0.2.0/src/shared/scalar_functions.py +2405 -0
- emx_onnx_cgen-0.2.0/src/shared/scalar_types.py +243 -0
- emx_onnx_cgen-0.2.0/tests/test_cli.py +71 -0
- emx_onnx_cgen-0.2.0/tests/test_codegen_data_file.py +43 -0
- emx_onnx_cgen-0.2.0/tests/test_codegen_signature.py +50 -0
- emx_onnx_cgen-0.2.0/tests/test_endtoend_features.py +142 -0
- emx_onnx_cgen-0.2.0/tests/test_golden.py +461 -0
- emx_onnx_cgen-0.2.0/tests/test_golden_ops.py +560 -0
- emx_onnx_cgen-0.2.0/tests/test_mixed_dtypes.py +129 -0
- emx_onnx_cgen-0.2.0/tests/test_multi_output.py +44 -0
- emx_onnx_cgen-0.2.0/tests/test_official_onnx_files.py +516 -0
- emx_onnx_cgen-0.2.0/tests/test_onnx_import.py +41 -0
- emx_onnx_cgen-0.2.0/tests/test_ops.py +3520 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include build_backend.py
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: emx-onnx-cgen
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: emmtrix ONNX-to-C Code Generator
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# emmtrix ONNX-to-C Code Generator (emx-onnx-cgen)
|
|
9
|
+
|
|
10
|
+
[](https://pypi.org/project/emx-onnx-cgen)
|
|
11
|
+
|
|
12
|
+
`emx-onnx-cgen` compiles ONNX models to portable, deterministic C code for deeply embedded systems. The generated code is designed to run without dynamic memory allocation, operating systems, or external runtimes, making it suitable for safety-critical and resource-constrained targets.
|
|
13
|
+
|
|
14
|
+
Key characteristics:
|
|
15
|
+
|
|
16
|
+
- **No dynamic memory allocation** (`malloc`, `free`, heap usage)
|
|
17
|
+
- **Static, compile-time known memory layout** for parameters, activations, and temporaries
|
|
18
|
+
- **Deterministic control flow** (explicit loops, no hidden dispatch or callbacks)
|
|
19
|
+
- **No OS or libc dependencies** beyond basic C
|
|
20
|
+
- **Single-threaded execution model**
|
|
21
|
+
- **Bitwise-stable code generation** for reproducible builds
|
|
22
|
+
- **Readable, auditable C code** suitable for certification and code reviews
|
|
23
|
+
- Designed for **bare-metal and RTOS-based systems**
|
|
24
|
+
|
|
25
|
+
## Goals
|
|
26
|
+
|
|
27
|
+
- Correctness-first compilation with outputs comparable to ONNX Runtime.
|
|
28
|
+
- Deterministic and reproducible C code generation.
|
|
29
|
+
- Clean, pass-based compiler architecture (import → normalize → optimize → lower → emit).
|
|
30
|
+
- Minimal C runtime with explicit, predictable data movement.
|
|
31
|
+
|
|
32
|
+
## Non-goals
|
|
33
|
+
|
|
34
|
+
- Aggressive performance optimizations in generated C.
|
|
35
|
+
- Implicit runtime dependencies or dynamic loading.
|
|
36
|
+
- Training/backpropagation support.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- CLI for ONNX-to-C compilation and verification.
|
|
41
|
+
- Deterministic codegen with explicit tensor shapes and loop nests.
|
|
42
|
+
- Minimal C runtime templates in `templates/`.
|
|
43
|
+
- ONNX Runtime comparison for end-to-end validation.
|
|
44
|
+
- Official ONNX operator coverage tracking.
|
|
45
|
+
- Support for a wide range of ONNX operators (see `OFFICIAL_ONNX_FILE_SUPPORT.md`).
|
|
46
|
+
- Supported data types:
|
|
47
|
+
- `float`, `double`, `float16`
|
|
48
|
+
- `int8_t`, `uint8_t`, `int16_t`, `uint16_t`, `int32_t`, `uint32_t`, `int64_t`, `uint64_t`
|
|
49
|
+
- `bool`
|
|
50
|
+
- Supporting dynamic dimensions by utilizing C99 variable-length arrays (VLAs).
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
Install the package directly from PyPI (recommended):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install emx-onnx-cgen
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Optional for verification and tests:
|
|
61
|
+
|
|
62
|
+
- `onnxruntime`
|
|
63
|
+
- `numpy`
|
|
64
|
+
- A C compiler (`cc`, `gcc`, `clang` or via `--cc`)
|
|
65
|
+
|
|
66
|
+
## Quickstart
|
|
67
|
+
|
|
68
|
+
Compile an ONNX model into a C source file:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
emx-onnx-cgen compile path/to/model.onnx build/model.c
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Verify an ONNX model end-to-end against ONNX Runtime:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
emx-onnx-cgen verify path/to/model.onnx
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## CLI Reference
|
|
81
|
+
|
|
82
|
+
`emx-onnx-cgen` provides two subcommands: `compile` and `verify`.
|
|
83
|
+
|
|
84
|
+
### `compile`
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
emx-onnx-cgen compile <model.onnx> <output.c> [options]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Options:
|
|
91
|
+
|
|
92
|
+
- `--template-dir`: Directory containing the C templates (default: `templates`).
|
|
93
|
+
- `--model-name`: Override the generated model name (default: output file stem).
|
|
94
|
+
- `--emit-testbench`: Emit a JSON-producing `main()` testbench for validation.
|
|
95
|
+
- `--emit-data-file`: Emit constant data arrays into a companion `_data` C file.
|
|
96
|
+
- `--no-restrict-arrays`: Disable `restrict` qualifiers on generated array parameters.
|
|
97
|
+
|
|
98
|
+
### `verify`
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
emx-onnx-cgen verify <model.onnx> [options]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Options:
|
|
105
|
+
|
|
106
|
+
- `--template-dir`: Directory containing the C templates (default: `templates`).
|
|
107
|
+
- `--model-name`: Override the generated model name (default: model file stem).
|
|
108
|
+
- `--cc`: Explicit C compiler command for building the testbench binary.
|
|
109
|
+
|
|
110
|
+
## Output
|
|
111
|
+
|
|
112
|
+
By default, the compiler emits a single C source file that includes:
|
|
113
|
+
|
|
114
|
+
- A generated entry point that mirrors the ONNX graph inputs/outputs.
|
|
115
|
+
- Tensor buffers for constants and temporaries.
|
|
116
|
+
- A lightweight runtime implemented via templates in `templates/`.
|
|
117
|
+
|
|
118
|
+
When `--emit-data-file` is enabled, the main C source declares constant arrays
|
|
119
|
+
as `extern`, and a second file named like the output with a `_data` suffix
|
|
120
|
+
contains the constant definitions.
|
|
121
|
+
|
|
122
|
+
## Official ONNX test coverage
|
|
123
|
+
|
|
124
|
+
See [`OFFICIAL_ONNX_FILE_SUPPORT.md`](OFFICIAL_ONNX_FILE_SUPPORT.md) for the generated support matrix.
|
|
125
|
+
|
|
126
|
+
## Maintained by
|
|
127
|
+
|
|
128
|
+
This project is maintained by [emmtrix](https://www.emmtrix.com).
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# emmtrix ONNX-to-C Code Generator (emx-onnx-cgen)
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/emx-onnx-cgen)
|
|
4
|
+
|
|
5
|
+
`emx-onnx-cgen` compiles ONNX models to portable, deterministic C code for deeply embedded systems. The generated code is designed to run without dynamic memory allocation, operating systems, or external runtimes, making it suitable for safety-critical and resource-constrained targets.
|
|
6
|
+
|
|
7
|
+
Key characteristics:
|
|
8
|
+
|
|
9
|
+
- **No dynamic memory allocation** (`malloc`, `free`, heap usage)
|
|
10
|
+
- **Static, compile-time known memory layout** for parameters, activations, and temporaries
|
|
11
|
+
- **Deterministic control flow** (explicit loops, no hidden dispatch or callbacks)
|
|
12
|
+
- **No OS or libc dependencies** beyond basic C
|
|
13
|
+
- **Single-threaded execution model**
|
|
14
|
+
- **Bitwise-stable code generation** for reproducible builds
|
|
15
|
+
- **Readable, auditable C code** suitable for certification and code reviews
|
|
16
|
+
- Designed for **bare-metal and RTOS-based systems**
|
|
17
|
+
|
|
18
|
+
## Goals
|
|
19
|
+
|
|
20
|
+
- Correctness-first compilation with outputs comparable to ONNX Runtime.
|
|
21
|
+
- Deterministic and reproducible C code generation.
|
|
22
|
+
- Clean, pass-based compiler architecture (import → normalize → optimize → lower → emit).
|
|
23
|
+
- Minimal C runtime with explicit, predictable data movement.
|
|
24
|
+
|
|
25
|
+
## Non-goals
|
|
26
|
+
|
|
27
|
+
- Aggressive performance optimizations in generated C.
|
|
28
|
+
- Implicit runtime dependencies or dynamic loading.
|
|
29
|
+
- Training/backpropagation support.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- CLI for ONNX-to-C compilation and verification.
|
|
34
|
+
- Deterministic codegen with explicit tensor shapes and loop nests.
|
|
35
|
+
- Minimal C runtime templates in `templates/`.
|
|
36
|
+
- ONNX Runtime comparison for end-to-end validation.
|
|
37
|
+
- Official ONNX operator coverage tracking.
|
|
38
|
+
- Support for a wide range of ONNX operators (see `OFFICIAL_ONNX_FILE_SUPPORT.md`).
|
|
39
|
+
- Supported data types:
|
|
40
|
+
- `float`, `double`, `float16`
|
|
41
|
+
- `int8_t`, `uint8_t`, `int16_t`, `uint16_t`, `int32_t`, `uint32_t`, `int64_t`, `uint64_t`
|
|
42
|
+
- `bool`
|
|
43
|
+
- Supporting dynamic dimensions by utilizing C99 variable-length arrays (VLAs).
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
Install the package directly from PyPI (recommended):
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install emx-onnx-cgen
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Optional for verification and tests:
|
|
54
|
+
|
|
55
|
+
- `onnxruntime`
|
|
56
|
+
- `numpy`
|
|
57
|
+
- A C compiler (`cc`, `gcc`, `clang` or via `--cc`)
|
|
58
|
+
|
|
59
|
+
## Quickstart
|
|
60
|
+
|
|
61
|
+
Compile an ONNX model into a C source file:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
emx-onnx-cgen compile path/to/model.onnx build/model.c
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Verify an ONNX model end-to-end against ONNX Runtime:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
emx-onnx-cgen verify path/to/model.onnx
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## CLI Reference
|
|
74
|
+
|
|
75
|
+
`emx-onnx-cgen` provides two subcommands: `compile` and `verify`.
|
|
76
|
+
|
|
77
|
+
### `compile`
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
emx-onnx-cgen compile <model.onnx> <output.c> [options]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Options:
|
|
84
|
+
|
|
85
|
+
- `--template-dir`: Directory containing the C templates (default: `templates`).
|
|
86
|
+
- `--model-name`: Override the generated model name (default: output file stem).
|
|
87
|
+
- `--emit-testbench`: Emit a JSON-producing `main()` testbench for validation.
|
|
88
|
+
- `--emit-data-file`: Emit constant data arrays into a companion `_data` C file.
|
|
89
|
+
- `--no-restrict-arrays`: Disable `restrict` qualifiers on generated array parameters.
|
|
90
|
+
|
|
91
|
+
### `verify`
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
emx-onnx-cgen verify <model.onnx> [options]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Options:
|
|
98
|
+
|
|
99
|
+
- `--template-dir`: Directory containing the C templates (default: `templates`).
|
|
100
|
+
- `--model-name`: Override the generated model name (default: model file stem).
|
|
101
|
+
- `--cc`: Explicit C compiler command for building the testbench binary.
|
|
102
|
+
|
|
103
|
+
## Output
|
|
104
|
+
|
|
105
|
+
By default, the compiler emits a single C source file that includes:
|
|
106
|
+
|
|
107
|
+
- A generated entry point that mirrors the ONNX graph inputs/outputs.
|
|
108
|
+
- Tensor buffers for constants and temporaries.
|
|
109
|
+
- A lightweight runtime implemented via templates in `templates/`.
|
|
110
|
+
|
|
111
|
+
When `--emit-data-file` is enabled, the main C source declares constant arrays
|
|
112
|
+
as `extern`, and a second file named like the output with a `_data` suffix
|
|
113
|
+
contains the constant definitions.
|
|
114
|
+
|
|
115
|
+
## Official ONNX test coverage
|
|
116
|
+
|
|
117
|
+
See [`OFFICIAL_ONNX_FILE_SUPPORT.md`](OFFICIAL_ONNX_FILE_SUPPORT.md) for the generated support matrix.
|
|
118
|
+
|
|
119
|
+
## Maintained by
|
|
120
|
+
|
|
121
|
+
This project is maintained by [emmtrix](https://www.emmtrix.com).
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import subprocess
|
|
6
|
+
|
|
7
|
+
from setuptools import build_meta as _build_meta
|
|
8
|
+
|
|
9
|
+
BUILD_INFO_MODULE = (
|
|
10
|
+
Path(__file__).resolve().parent / "src" / "emx_onnx_cgen" / "_build_info.py"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _write_build_info() -> None:
|
|
15
|
+
build_date = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
16
|
+
git_version = _read_git_version()
|
|
17
|
+
|
|
18
|
+
# Ensure the package directory exists (useful for clean checkouts / CI)
|
|
19
|
+
BUILD_INFO_MODULE.parent.mkdir(parents=True, exist_ok=True)
|
|
20
|
+
|
|
21
|
+
BUILD_INFO_MODULE.write_text(
|
|
22
|
+
'"""Auto-generated by build backend. Do not edit."""\n'
|
|
23
|
+
f"BUILD_DATE = {build_date!r}\n"
|
|
24
|
+
f"GIT_VERSION = {git_version!r}\n",
|
|
25
|
+
encoding="utf-8",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _read_git_version() -> str:
|
|
30
|
+
try:
|
|
31
|
+
result = subprocess.run(
|
|
32
|
+
["git", "rev-parse", "--short", "HEAD"],
|
|
33
|
+
check=True,
|
|
34
|
+
capture_output=True,
|
|
35
|
+
text=True,
|
|
36
|
+
)
|
|
37
|
+
except (OSError, subprocess.CalledProcessError):
|
|
38
|
+
return "unknown"
|
|
39
|
+
return result.stdout.strip() or "unknown"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
|
|
43
|
+
_write_build_info()
|
|
44
|
+
return _build_meta.build_wheel(
|
|
45
|
+
wheel_directory,
|
|
46
|
+
config_settings=config_settings,
|
|
47
|
+
metadata_directory=metadata_directory,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
|
|
52
|
+
_write_build_info()
|
|
53
|
+
return _build_meta.build_editable(
|
|
54
|
+
wheel_directory,
|
|
55
|
+
config_settings=config_settings,
|
|
56
|
+
metadata_directory=metadata_directory,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def build_sdist(sdist_directory, config_settings=None):
|
|
61
|
+
return _build_meta.build_sdist(sdist_directory, config_settings=config_settings)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def get_requires_for_build_wheel(config_settings=None):
|
|
65
|
+
return _build_meta.get_requires_for_build_wheel(config_settings=config_settings)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def get_requires_for_build_editable(config_settings=None):
|
|
69
|
+
return _build_meta.get_requires_for_build_editable(config_settings=config_settings)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
|
|
73
|
+
return _build_meta.prepare_metadata_for_build_wheel(
|
|
74
|
+
metadata_directory, config_settings=config_settings
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def prepare_metadata_for_build_editable(metadata_directory, config_settings=None):
|
|
79
|
+
return _build_meta.prepare_metadata_for_build_editable(
|
|
80
|
+
metadata_directory, config_settings=config_settings
|
|
81
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "build_backend"
|
|
4
|
+
backend-path = ["."]
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "emx-onnx-cgen"
|
|
8
|
+
version = "0.2.0"
|
|
9
|
+
description = "emmtrix ONNX-to-C Code Generator"
|
|
10
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
emx-onnx-cgen = "emx_onnx_cgen.cli:main"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools]
|
|
17
|
+
package-dir = {"" = "src"}
|
|
18
|
+
|
|
19
|
+
[tool.setuptools.packages.find]
|
|
20
|
+
where = ["src"]
|