pybend 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.
- pybend-0.2.0/.gitignore +12 -0
- pybend-0.2.0/LICENSE +21 -0
- pybend-0.2.0/PKG-INFO +241 -0
- pybend-0.2.0/README.md +198 -0
- pybend-0.2.0/bootloader/Cargo.toml +16 -0
- pybend-0.2.0/bootloader/src/bootstrapper.rs +212 -0
- pybend-0.2.0/bootloader/src/extractor.rs +75 -0
- pybend-0.2.0/bootloader/src/main.rs +38 -0
- pybend-0.2.0/docs/advanced.md +118 -0
- pybend-0.2.0/docs/configuration.md +78 -0
- pybend-0.2.0/docs/index.md +68 -0
- pybend-0.2.0/mkdocs.yml +42 -0
- pybend-0.2.0/pybend/__init__.py +3 -0
- pybend-0.2.0/pybend/cli.py +172 -0
- pybend-0.2.0/pybend/compiler.py +79 -0
- pybend-0.2.0/pybend/config.py +133 -0
- pybend-0.2.0/pybend/dependency_resolver.py +80 -0
- pybend-0.2.0/pybend/importer.py +128 -0
- pybend-0.2.0/pybend/splicer.py +20 -0
- pybend-0.2.0/pybend/templates/linux/x86_64/.gitkeep +0 -0
- pybend-0.2.0/pybend/templates/linux/x86_64/bootloader +0 -0
- pybend-0.2.0/pybend/vfs_builder.py +104 -0
- pybend-0.2.0/pyproject.toml +54 -0
- pybend-0.2.0/tests/test_cli.py +128 -0
- pybend-0.2.0/tests/test_config.py +119 -0
- pybend-0.2.0/tests/test_dependency_resolver.py +69 -0
- pybend-0.2.0/tests/test_importer.py +104 -0
- pybend-0.2.0/tests/test_integration.py +129 -0
- pybend-0.2.0/tests/test_splicer.py +55 -0
- pybend-0.2.0/tests/test_validation.py +100 -0
- pybend-0.2.0/tests/test_vfs_builder.py +155 -0
pybend-0.2.0/.gitignore
ADDED
pybend-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jude Nii Klemesu Commey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pybend-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pybend
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Compile Python applications into standalone native binaries
|
|
5
|
+
Author: Jude Nii Klemesu Commey
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Jude Nii Klemesu Commey
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Keywords: binary,compiler,deployment,freezer,standalone
|
|
29
|
+
Classifier: Development Status :: 3 - Alpha
|
|
30
|
+
Classifier: Intended Audience :: Developers
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Programming Language :: Python :: 3
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
36
|
+
Classifier: Programming Language :: Rust
|
|
37
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
38
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
39
|
+
Requires-Python: >=3.11
|
|
40
|
+
Requires-Dist: click>=8.0
|
|
41
|
+
Requires-Dist: rich>=13.0
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# PyBend ๐ชถ
|
|
45
|
+
|
|
46
|
+
> Compile Python applications into standalone native binaries that run entirely in volatile memory.
|
|
47
|
+
|
|
48
|
+
PyBend is a zero-configuration, high-performance Python-to-Native-Binary compiler toolchain. It compiles your Python applications, third-party packages, and native C-extensions into a single, standalone executable โ with **zero physical disk I/O at runtime**.
|
|
49
|
+
|
|
50
|
+
Unlike traditional freezers (PyInstaller, cx_Freeze, Nuitka) that extract dependencies to `/tmp` or `%TEMP%`, PyBend keeps everything in RAM via a custom PEP 451 meta-path importer backed by an embedded Virtual File System.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## ๐ Performance Snapshot
|
|
55
|
+
|
|
56
|
+
| Metric | PyBend | PyInstaller |
|
|
57
|
+
|--------|--------|-------------|
|
|
58
|
+
| **Cold-Start Latency** | ~23 ms | ~300โ500 ms |
|
|
59
|
+
| **Disk I/O at Runtime** | 0 physical writes | Writes to `/tmp` |
|
|
60
|
+
| **Binary Size (base)** | ~340 KB (engine) + VFS | ~30 MB+ |
|
|
61
|
+
| **Code on Disk** | Never | Extracted to temp |
|
|
62
|
+
|
|
63
|
+
## ๐ ๏ธ How It Works
|
|
64
|
+
|
|
65
|
+
### 1. AST Tracing & Tree-Shaking
|
|
66
|
+
Scans your import graph using Python's `modulefinder`. Only the modules your app actually imports are included โ no bloat.
|
|
67
|
+
|
|
68
|
+
### 2. Optimization Pass (-OO)
|
|
69
|
+
All source is compiled to bytecode with assertions and docstrings stripped, yielding 8โ15% smaller payloads.
|
|
70
|
+
|
|
71
|
+
### 3. Dual-Table VFS v2 Layout
|
|
72
|
+
Bytecode, native `.so` extensions, and static assets are packed into a structured binary blob:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
76
|
+
โ BENDVFS BLOB โ
|
|
77
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
78
|
+
โ [4B: "BEND" Magic] [4B: Code Entry Count] โ
|
|
79
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
80
|
+
โ โ Code Module Table โ โ
|
|
81
|
+
โ โ name โ (offset, compressed_size, โ โ
|
|
82
|
+
โ โ uncompressed_size, is_c_ext) โ โ
|
|
83
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
84
|
+
โ [4B: Asset Entry Count] โ
|
|
85
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
86
|
+
โ โ Asset Table โ โ
|
|
87
|
+
โ โ path โ (offset, compressed_size, โ โ
|
|
88
|
+
โ โ uncompressed_size) โ โ
|
|
89
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
90
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
91
|
+
โ โ Compressed Payload Pool (zlib DEFLATE) โ โ
|
|
92
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
93
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 4. RAM-Mapped Execution
|
|
97
|
+
- The Rust bootloader memory-maps itself via `memmap2`, locates the VFS by its `BEND` footer signature, and passes it to the embedded Python runtime.
|
|
98
|
+
- A `BendMemoryFinder` is injected into `sys.meta_path[0]` per PEP 451 โ all imports resolve from RAM.
|
|
99
|
+
- C-extensions are written to anonymous `memfd_create` file descriptors and loaded with `dlopen` โ the kernel pages them directly from RAM.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## ๐ฆ Quick Start
|
|
104
|
+
|
|
105
|
+
### 1. Install
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install pybend
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 2. Zero-Config Build
|
|
112
|
+
|
|
113
|
+
If your project directory contains `main.py` or `app.py`:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pybend build
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
That's it. The output lands at `./dist/<name>.bin`.
|
|
120
|
+
|
|
121
|
+
### 3. Explicit Build
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pybend build --entry src/server.py --output deploy/server.bin -O 2
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 4. Config-Driven Build (`pybend.toml`)
|
|
128
|
+
|
|
129
|
+
```toml
|
|
130
|
+
[build]
|
|
131
|
+
entry_point = "src/main.py"
|
|
132
|
+
output_exe = "dist/app.bin"
|
|
133
|
+
optimization_level = 2
|
|
134
|
+
include_modules = ["hidden_dep"]
|
|
135
|
+
exclude_modules = ["test", "unittest"]
|
|
136
|
+
include_data = ["config.json", "assets/"]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pybend build
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 5. Fetching Embedded Assets at Runtime
|
|
144
|
+
|
|
145
|
+
Any file listed in `include_data` can be streamed from memory:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
import pybend
|
|
149
|
+
|
|
150
|
+
config = pybend.get_asset("config.json")
|
|
151
|
+
template = pybend.get_asset("templates/email.html")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
No disk access. No extraction. Directly from the VFS.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## ๐๏ธ Project Structure
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
pybend/
|
|
162
|
+
โโโ pyproject.toml # Hatchling build config
|
|
163
|
+
โโโ bootloader/ # Rust runtime engine
|
|
164
|
+
โ โโโ Cargo.toml
|
|
165
|
+
โ โโโ src/
|
|
166
|
+
โ โโโ main.rs
|
|
167
|
+
โ โโโ extractor.rs
|
|
168
|
+
โ โโโ bootstrapper.rs
|
|
169
|
+
โโโ pybend/ # Python build orchestration
|
|
170
|
+
โ โโโ __init__.py
|
|
171
|
+
โ โโโ cli.py # Click CLI
|
|
172
|
+
โ โโโ compiler.py # Pipeline orchestrator
|
|
173
|
+
โ โโโ config.py # TOML + CLI config resolution
|
|
174
|
+
โ โโโ dependency_resolver.py # Import tracing + filtering
|
|
175
|
+
โ โโโ importer.py # Runtime VFS finder & loaders
|
|
176
|
+
โ โโโ splicer.py # Binary tail-splicing
|
|
177
|
+
โ โโโ vfs_builder.py # VFS blob construction
|
|
178
|
+
โ โโโ templates/ # Pre-built bootloader binaries
|
|
179
|
+
โโโ docs/ # MkDocs documentation
|
|
180
|
+
โโโ tests/ # Test suite
|
|
181
|
+
โโโ .github/workflows/ # CI/CD pipelines
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## โ๏ธ Configuration Reference
|
|
187
|
+
|
|
188
|
+
### CLI Flags
|
|
189
|
+
|
|
190
|
+
| Flag | Shorthand | Description |
|
|
191
|
+
|------|-----------|-------------|
|
|
192
|
+
| `--entry` | `-e` | Entry point script path |
|
|
193
|
+
| `--output` | `-o` | Output executable path |
|
|
194
|
+
| `--optimize` | `-O` | Optimization level (0, 1, 2) |
|
|
195
|
+
| `--include` | `-i` | Force-include a module |
|
|
196
|
+
| `--exclude` | `-x` | Exclude a module |
|
|
197
|
+
| `--template` | `-t` | Custom bootloader binary |
|
|
198
|
+
| `--config` | `-c` | Custom pybend.toml path |
|
|
199
|
+
|
|
200
|
+
### pybend.toml Fields
|
|
201
|
+
|
|
202
|
+
| Field | Type | Default | Description |
|
|
203
|
+
|-------|------|---------|-------------|
|
|
204
|
+
| `entry_point` | string | auto-discover | Entry script path |
|
|
205
|
+
| `output_exe` | string | `dist/<name>.bin` | Output binary path |
|
|
206
|
+
| `optimization_level` | int | `2` | Bytecode optimization (0/1/2) |
|
|
207
|
+
| `include_modules` | string[] | `[]` | Force-include modules |
|
|
208
|
+
| `exclude_modules` | string[] | `[]` | Exclude modules |
|
|
209
|
+
| `include_data` | string[] | `[]` | Static file paths to embed |
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## ๐งช Testing
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
# Python test suite (22 tests)
|
|
217
|
+
python -m unittest discover -s tests -v
|
|
218
|
+
|
|
219
|
+
# Rust tests
|
|
220
|
+
cd bootloader && RUSTFLAGS="-L lib" cargo test
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Current test coverage: **22 Python tests + 2 Rust tests โ all passing**.
|
|
224
|
+
|
|
225
|
+
Includes end-to-end compilation + execution tests, C-extension loading via `memfd_create`, VFS structural validation, latency benchmarks, and disk-isolation verification.
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## ๐ฏ Target Platform
|
|
230
|
+
|
|
231
|
+
- **Linux x86_64** (primary, production-tested)
|
|
232
|
+
|
|
233
|
+
Future targets: `aarch64-unknown-linux-musl`, `x86_64-pc-windows-gnu`, `aarch64-apple-darwin`.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## ๐ License
|
|
238
|
+
|
|
239
|
+
MIT โ see [LICENSE](LICENSE).
|
|
240
|
+
|
|
241
|
+
Copyright (c) 2026 Jude Nii Klemesu Commey
|
pybend-0.2.0/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# PyBend ๐ชถ
|
|
2
|
+
|
|
3
|
+
> Compile Python applications into standalone native binaries that run entirely in volatile memory.
|
|
4
|
+
|
|
5
|
+
PyBend is a zero-configuration, high-performance Python-to-Native-Binary compiler toolchain. It compiles your Python applications, third-party packages, and native C-extensions into a single, standalone executable โ with **zero physical disk I/O at runtime**.
|
|
6
|
+
|
|
7
|
+
Unlike traditional freezers (PyInstaller, cx_Freeze, Nuitka) that extract dependencies to `/tmp` or `%TEMP%`, PyBend keeps everything in RAM via a custom PEP 451 meta-path importer backed by an embedded Virtual File System.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## ๐ Performance Snapshot
|
|
12
|
+
|
|
13
|
+
| Metric | PyBend | PyInstaller |
|
|
14
|
+
|--------|--------|-------------|
|
|
15
|
+
| **Cold-Start Latency** | ~23 ms | ~300โ500 ms |
|
|
16
|
+
| **Disk I/O at Runtime** | 0 physical writes | Writes to `/tmp` |
|
|
17
|
+
| **Binary Size (base)** | ~340 KB (engine) + VFS | ~30 MB+ |
|
|
18
|
+
| **Code on Disk** | Never | Extracted to temp |
|
|
19
|
+
|
|
20
|
+
## ๐ ๏ธ How It Works
|
|
21
|
+
|
|
22
|
+
### 1. AST Tracing & Tree-Shaking
|
|
23
|
+
Scans your import graph using Python's `modulefinder`. Only the modules your app actually imports are included โ no bloat.
|
|
24
|
+
|
|
25
|
+
### 2. Optimization Pass (-OO)
|
|
26
|
+
All source is compiled to bytecode with assertions and docstrings stripped, yielding 8โ15% smaller payloads.
|
|
27
|
+
|
|
28
|
+
### 3. Dual-Table VFS v2 Layout
|
|
29
|
+
Bytecode, native `.so` extensions, and static assets are packed into a structured binary blob:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
33
|
+
โ BENDVFS BLOB โ
|
|
34
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
35
|
+
โ [4B: "BEND" Magic] [4B: Code Entry Count] โ
|
|
36
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
37
|
+
โ โ Code Module Table โ โ
|
|
38
|
+
โ โ name โ (offset, compressed_size, โ โ
|
|
39
|
+
โ โ uncompressed_size, is_c_ext) โ โ
|
|
40
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
41
|
+
โ [4B: Asset Entry Count] โ
|
|
42
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
43
|
+
โ โ Asset Table โ โ
|
|
44
|
+
โ โ path โ (offset, compressed_size, โ โ
|
|
45
|
+
โ โ uncompressed_size) โ โ
|
|
46
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
47
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
48
|
+
โ โ Compressed Payload Pool (zlib DEFLATE) โ โ
|
|
49
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
50
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 4. RAM-Mapped Execution
|
|
54
|
+
- The Rust bootloader memory-maps itself via `memmap2`, locates the VFS by its `BEND` footer signature, and passes it to the embedded Python runtime.
|
|
55
|
+
- A `BendMemoryFinder` is injected into `sys.meta_path[0]` per PEP 451 โ all imports resolve from RAM.
|
|
56
|
+
- C-extensions are written to anonymous `memfd_create` file descriptors and loaded with `dlopen` โ the kernel pages them directly from RAM.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## ๐ฆ Quick Start
|
|
61
|
+
|
|
62
|
+
### 1. Install
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install pybend
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 2. Zero-Config Build
|
|
69
|
+
|
|
70
|
+
If your project directory contains `main.py` or `app.py`:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pybend build
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
That's it. The output lands at `./dist/<name>.bin`.
|
|
77
|
+
|
|
78
|
+
### 3. Explicit Build
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pybend build --entry src/server.py --output deploy/server.bin -O 2
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 4. Config-Driven Build (`pybend.toml`)
|
|
85
|
+
|
|
86
|
+
```toml
|
|
87
|
+
[build]
|
|
88
|
+
entry_point = "src/main.py"
|
|
89
|
+
output_exe = "dist/app.bin"
|
|
90
|
+
optimization_level = 2
|
|
91
|
+
include_modules = ["hidden_dep"]
|
|
92
|
+
exclude_modules = ["test", "unittest"]
|
|
93
|
+
include_data = ["config.json", "assets/"]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pybend build
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 5. Fetching Embedded Assets at Runtime
|
|
101
|
+
|
|
102
|
+
Any file listed in `include_data` can be streamed from memory:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import pybend
|
|
106
|
+
|
|
107
|
+
config = pybend.get_asset("config.json")
|
|
108
|
+
template = pybend.get_asset("templates/email.html")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
No disk access. No extraction. Directly from the VFS.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## ๐๏ธ Project Structure
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
pybend/
|
|
119
|
+
โโโ pyproject.toml # Hatchling build config
|
|
120
|
+
โโโ bootloader/ # Rust runtime engine
|
|
121
|
+
โ โโโ Cargo.toml
|
|
122
|
+
โ โโโ src/
|
|
123
|
+
โ โโโ main.rs
|
|
124
|
+
โ โโโ extractor.rs
|
|
125
|
+
โ โโโ bootstrapper.rs
|
|
126
|
+
โโโ pybend/ # Python build orchestration
|
|
127
|
+
โ โโโ __init__.py
|
|
128
|
+
โ โโโ cli.py # Click CLI
|
|
129
|
+
โ โโโ compiler.py # Pipeline orchestrator
|
|
130
|
+
โ โโโ config.py # TOML + CLI config resolution
|
|
131
|
+
โ โโโ dependency_resolver.py # Import tracing + filtering
|
|
132
|
+
โ โโโ importer.py # Runtime VFS finder & loaders
|
|
133
|
+
โ โโโ splicer.py # Binary tail-splicing
|
|
134
|
+
โ โโโ vfs_builder.py # VFS blob construction
|
|
135
|
+
โ โโโ templates/ # Pre-built bootloader binaries
|
|
136
|
+
โโโ docs/ # MkDocs documentation
|
|
137
|
+
โโโ tests/ # Test suite
|
|
138
|
+
โโโ .github/workflows/ # CI/CD pipelines
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## โ๏ธ Configuration Reference
|
|
144
|
+
|
|
145
|
+
### CLI Flags
|
|
146
|
+
|
|
147
|
+
| Flag | Shorthand | Description |
|
|
148
|
+
|------|-----------|-------------|
|
|
149
|
+
| `--entry` | `-e` | Entry point script path |
|
|
150
|
+
| `--output` | `-o` | Output executable path |
|
|
151
|
+
| `--optimize` | `-O` | Optimization level (0, 1, 2) |
|
|
152
|
+
| `--include` | `-i` | Force-include a module |
|
|
153
|
+
| `--exclude` | `-x` | Exclude a module |
|
|
154
|
+
| `--template` | `-t` | Custom bootloader binary |
|
|
155
|
+
| `--config` | `-c` | Custom pybend.toml path |
|
|
156
|
+
|
|
157
|
+
### pybend.toml Fields
|
|
158
|
+
|
|
159
|
+
| Field | Type | Default | Description |
|
|
160
|
+
|-------|------|---------|-------------|
|
|
161
|
+
| `entry_point` | string | auto-discover | Entry script path |
|
|
162
|
+
| `output_exe` | string | `dist/<name>.bin` | Output binary path |
|
|
163
|
+
| `optimization_level` | int | `2` | Bytecode optimization (0/1/2) |
|
|
164
|
+
| `include_modules` | string[] | `[]` | Force-include modules |
|
|
165
|
+
| `exclude_modules` | string[] | `[]` | Exclude modules |
|
|
166
|
+
| `include_data` | string[] | `[]` | Static file paths to embed |
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## ๐งช Testing
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# Python test suite (22 tests)
|
|
174
|
+
python -m unittest discover -s tests -v
|
|
175
|
+
|
|
176
|
+
# Rust tests
|
|
177
|
+
cd bootloader && RUSTFLAGS="-L lib" cargo test
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Current test coverage: **22 Python tests + 2 Rust tests โ all passing**.
|
|
181
|
+
|
|
182
|
+
Includes end-to-end compilation + execution tests, C-extension loading via `memfd_create`, VFS structural validation, latency benchmarks, and disk-isolation verification.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## ๐ฏ Target Platform
|
|
187
|
+
|
|
188
|
+
- **Linux x86_64** (primary, production-tested)
|
|
189
|
+
|
|
190
|
+
Future targets: `aarch64-unknown-linux-musl`, `x86_64-pc-windows-gnu`, `aarch64-apple-darwin`.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## ๐ License
|
|
195
|
+
|
|
196
|
+
MIT โ see [LICENSE](LICENSE).
|
|
197
|
+
|
|
198
|
+
Copyright (c) 2026 Jude Nii Klemesu Commey
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "bootloader"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
|
|
6
|
+
[dependencies]
|
|
7
|
+
memmap2 = "0.9"
|
|
8
|
+
pyo3 = "0.28"
|
|
9
|
+
flate2 = "1.0"
|
|
10
|
+
|
|
11
|
+
[profile.release]
|
|
12
|
+
opt-level = "z"
|
|
13
|
+
lto = true
|
|
14
|
+
codegen-units = 1
|
|
15
|
+
panic = "abort"
|
|
16
|
+
strip = "symbols"
|