freedos-micro-python 0.1.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.
- freedos_micro_python-0.1.0/LICENSE +25 -0
- freedos_micro_python-0.1.0/PKG-INFO +131 -0
- freedos_micro_python-0.1.0/README.md +103 -0
- freedos_micro_python-0.1.0/pyproject.toml +58 -0
- freedos_micro_python-0.1.0/setup.cfg +4 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/__init__.py +8 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/cli.py +106 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/gen_qstrdefs.py +275 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/arch/bpstruct.h +2 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/arch/cc.h +4 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/arch/epstruct.h +1 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/base64_uc386dos.c +164 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/file_uc386dos.c +228 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/lib/axtls/crypto/crypto.h +45 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/lwip-arch-cc.h +46 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/lwip_uc386dos.c +248 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/lwipopts.h +117 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/math_gamma.c +63 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/modtime_uc386dos.c +60 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/modtls_axtls_uc386dos.c +461 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/mpconfigport.h +358 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/mphal_uc386dos.c +103 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/mphalport.h +11 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/os_uc386dos.c +264 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/path_uc386dos.c +307 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/pktdrv_uc386dos.c +650 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/qstrdefsport.h +2 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/shutil_uc386dos.c +111 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/tempfile_uc386dos.c +129 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/time_real_uc386dos.c +77 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/uc386_net_uc386dos.c +126 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/urllib_parse_uc386dos.c +360 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/port/urllib_uc386dos.c +29 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/scripts/build.sh +641 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/scripts/build_port.sh +241 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python/scripts/fetch.sh +238 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python.egg-info/PKG-INFO +131 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python.egg-info/SOURCES.txt +42 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python.egg-info/dependency_links.txt +1 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python.egg-info/entry_points.txt +2 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python.egg-info/requires.txt +4 -0
- freedos_micro_python-0.1.0/src/freedos_micro_python.egg-info/top_level.txt +1 -0
- freedos_micro_python-0.1.0/tests/test_gen_qstrdefs.py +188 -0
- freedos_micro_python-0.1.0/tests/test_smoke.py +3132 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 freedos_micro_python contributors
|
|
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.
|
|
22
|
+
|
|
23
|
+
Note: this license covers the integration glue (build scripts, port files,
|
|
24
|
+
CLI wrapper, tests). The MicroPython upstream sources fetched by build_port.sh
|
|
25
|
+
remain under their original MIT license — see https://github.com/micropython/micropython.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: freedos_micro_python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MicroPython port for FreeDOS / i386 — built end-to-end through the uc386 C23 compiler
|
|
5
|
+
Author: freedos_micro_python contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/avwohl/freedos_micro_python
|
|
8
|
+
Project-URL: Repository, https://github.com/avwohl/freedos_micro_python
|
|
9
|
+
Project-URL: Issues, https://github.com/avwohl/freedos_micro_python/issues
|
|
10
|
+
Keywords: micropython,python,freedos,dos,i386,retro-computing,embedded,interpreter
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
20
|
+
Classifier: Topic :: System :: Emulators
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: uc386>=0.1.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# freedos_micro_python
|
|
30
|
+
|
|
31
|
+
[MicroPython](https://github.com/micropython/micropython) port for
|
|
32
|
+
**FreeDOS / i386**, built end-to-end through the
|
|
33
|
+
[uc386](https://pypi.org/project/uc386/) C23 compiler. Produces a
|
|
34
|
+
runnable flat-binary or PMODE/W `.exe` with a fully-functional
|
|
35
|
+
Python REPL — arithmetic, control flow, classes, list comprehensions,
|
|
36
|
+
exception handling, and ~25 named builtins all work.
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
MicroPython uc386-triage on 2026-05-01; uc386-dos with i386
|
|
40
|
+
Type "help()" for more information.
|
|
41
|
+
>>> def fib(n):
|
|
42
|
+
... if n < 2: return n
|
|
43
|
+
... return fib(n-1) + fib(n-2)
|
|
44
|
+
...
|
|
45
|
+
>>> print([fib(i) for i in range(10)])
|
|
46
|
+
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Status
|
|
50
|
+
|
|
51
|
+
- ~444 KB binary at the EXTRA_FEATURES + axtls TLS configuration
|
|
52
|
+
- ~70 smoke tests pin REPL banner, builtins, comprehensions, exceptions,
|
|
53
|
+
module imports (`os`, `time`, `re`, `json`, `hashlib`, `ssl`, ...),
|
|
54
|
+
and the long-int / float code paths
|
|
55
|
+
- See [`NOTES.md`](NOTES.md) for the full per-slice development log
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
pip install freedos_micro_python
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This pulls in `uc386` (the compiler) automatically. You also need:
|
|
64
|
+
|
|
65
|
+
- a Unix-y shell to drive the `build_port.sh` script (macOS / Linux)
|
|
66
|
+
- `git` (for fetching the upstream MicroPython sources)
|
|
67
|
+
- `make` is **not** required
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
mkdir mp-build && cd mp-build
|
|
73
|
+
freedos-micropython fetch # clones upstream MicroPython into ./upstream
|
|
74
|
+
freedos-micropython build # per-TU triage build (generates qstrdefs)
|
|
75
|
+
freedos-micropython port # multi-TU build → ./build/micropython.bin
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Wall-clock for the `port` step is ~14 minutes on a recent Mac. The
|
|
79
|
+
output is `./build/micropython.bin`, a flat i386 DOS binary runnable
|
|
80
|
+
under uc386's emulator:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from uc386.dos_emu import run
|
|
84
|
+
res = run("build/micropython.bin", timeout_seconds=10.0,
|
|
85
|
+
instruction_limit=2_000_000_000)
|
|
86
|
+
print(res.stdout) # → "MicroPython uc386-triage on ...\n..."
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To produce a real DOS `.exe` (PMODE/W bound, ~12 KB stub overhead):
|
|
90
|
+
use uc386's `addons/harness/exe.py`.
|
|
91
|
+
|
|
92
|
+
## Testing
|
|
93
|
+
|
|
94
|
+
After a successful `port` build:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pytest --pyargs freedos_micro_python # parametric: tests live in tests/
|
|
98
|
+
# or, against a checkout:
|
|
99
|
+
pytest tests/
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The smoke tests skip cleanly if `build/micropython.bin` doesn't exist.
|
|
103
|
+
|
|
104
|
+
## Layout
|
|
105
|
+
|
|
106
|
+
- `src/freedos_micro_python/scripts/` — the three shell scripts
|
|
107
|
+
(`fetch.sh`, `build.sh`, `build_port.sh`); invoked via the CLI
|
|
108
|
+
wrapper, which sets `UC386_LIB_INCLUDE` from the installed `uc386`
|
|
109
|
+
- `src/freedos_micro_python/port/` — the FreeDOS port files
|
|
110
|
+
(`mpconfigport.h`, `*_uc386dos.c`, lwIP + axtls glue)
|
|
111
|
+
- `src/freedos_micro_python/gen_qstrdefs.py` — qstr table generator
|
|
112
|
+
(mirrors upstream's `tools/makeqstrdata.py`)
|
|
113
|
+
- `src/freedos_micro_python/cli.py` — the `freedos-micropython` CLI
|
|
114
|
+
- `tests/` — pytest smoke tests + qstr unit tests
|
|
115
|
+
- `rigs/dosbox-x-rig/` — DOSBox-X regression rig (network packet driver)
|
|
116
|
+
- `rigs/tls-rig/` — axtls TLS regression rig
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
[MIT](LICENSE), matching upstream MicroPython. The integration glue
|
|
121
|
+
(scripts, port files, CLI, tests) is what's covered here; the
|
|
122
|
+
upstream MicroPython sources fetched by `build_port.sh` retain their
|
|
123
|
+
own MIT license.
|
|
124
|
+
|
|
125
|
+
## Related projects
|
|
126
|
+
|
|
127
|
+
- [uc386](https://github.com/avwohl/uc386) — the C23 compiler that
|
|
128
|
+
builds this port. Hosts the `dos_emu` test harness.
|
|
129
|
+
- [uc_core](https://github.com/avwohl/uc_core) — shared C23 frontend
|
|
130
|
+
used by uc386 (and the Z80 sibling, uc80).
|
|
131
|
+
- [MicroPython](https://github.com/micropython/micropython) — upstream.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# freedos_micro_python
|
|
2
|
+
|
|
3
|
+
[MicroPython](https://github.com/micropython/micropython) port for
|
|
4
|
+
**FreeDOS / i386**, built end-to-end through the
|
|
5
|
+
[uc386](https://pypi.org/project/uc386/) C23 compiler. Produces a
|
|
6
|
+
runnable flat-binary or PMODE/W `.exe` with a fully-functional
|
|
7
|
+
Python REPL — arithmetic, control flow, classes, list comprehensions,
|
|
8
|
+
exception handling, and ~25 named builtins all work.
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
MicroPython uc386-triage on 2026-05-01; uc386-dos with i386
|
|
12
|
+
Type "help()" for more information.
|
|
13
|
+
>>> def fib(n):
|
|
14
|
+
... if n < 2: return n
|
|
15
|
+
... return fib(n-1) + fib(n-2)
|
|
16
|
+
...
|
|
17
|
+
>>> print([fib(i) for i in range(10)])
|
|
18
|
+
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Status
|
|
22
|
+
|
|
23
|
+
- ~444 KB binary at the EXTRA_FEATURES + axtls TLS configuration
|
|
24
|
+
- ~70 smoke tests pin REPL banner, builtins, comprehensions, exceptions,
|
|
25
|
+
module imports (`os`, `time`, `re`, `json`, `hashlib`, `ssl`, ...),
|
|
26
|
+
and the long-int / float code paths
|
|
27
|
+
- See [`NOTES.md`](NOTES.md) for the full per-slice development log
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
pip install freedos_micro_python
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This pulls in `uc386` (the compiler) automatically. You also need:
|
|
36
|
+
|
|
37
|
+
- a Unix-y shell to drive the `build_port.sh` script (macOS / Linux)
|
|
38
|
+
- `git` (for fetching the upstream MicroPython sources)
|
|
39
|
+
- `make` is **not** required
|
|
40
|
+
|
|
41
|
+
## Quick start
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
mkdir mp-build && cd mp-build
|
|
45
|
+
freedos-micropython fetch # clones upstream MicroPython into ./upstream
|
|
46
|
+
freedos-micropython build # per-TU triage build (generates qstrdefs)
|
|
47
|
+
freedos-micropython port # multi-TU build → ./build/micropython.bin
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Wall-clock for the `port` step is ~14 minutes on a recent Mac. The
|
|
51
|
+
output is `./build/micropython.bin`, a flat i386 DOS binary runnable
|
|
52
|
+
under uc386's emulator:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from uc386.dos_emu import run
|
|
56
|
+
res = run("build/micropython.bin", timeout_seconds=10.0,
|
|
57
|
+
instruction_limit=2_000_000_000)
|
|
58
|
+
print(res.stdout) # → "MicroPython uc386-triage on ...\n..."
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
To produce a real DOS `.exe` (PMODE/W bound, ~12 KB stub overhead):
|
|
62
|
+
use uc386's `addons/harness/exe.py`.
|
|
63
|
+
|
|
64
|
+
## Testing
|
|
65
|
+
|
|
66
|
+
After a successful `port` build:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pytest --pyargs freedos_micro_python # parametric: tests live in tests/
|
|
70
|
+
# or, against a checkout:
|
|
71
|
+
pytest tests/
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The smoke tests skip cleanly if `build/micropython.bin` doesn't exist.
|
|
75
|
+
|
|
76
|
+
## Layout
|
|
77
|
+
|
|
78
|
+
- `src/freedos_micro_python/scripts/` — the three shell scripts
|
|
79
|
+
(`fetch.sh`, `build.sh`, `build_port.sh`); invoked via the CLI
|
|
80
|
+
wrapper, which sets `UC386_LIB_INCLUDE` from the installed `uc386`
|
|
81
|
+
- `src/freedos_micro_python/port/` — the FreeDOS port files
|
|
82
|
+
(`mpconfigport.h`, `*_uc386dos.c`, lwIP + axtls glue)
|
|
83
|
+
- `src/freedos_micro_python/gen_qstrdefs.py` — qstr table generator
|
|
84
|
+
(mirrors upstream's `tools/makeqstrdata.py`)
|
|
85
|
+
- `src/freedos_micro_python/cli.py` — the `freedos-micropython` CLI
|
|
86
|
+
- `tests/` — pytest smoke tests + qstr unit tests
|
|
87
|
+
- `rigs/dosbox-x-rig/` — DOSBox-X regression rig (network packet driver)
|
|
88
|
+
- `rigs/tls-rig/` — axtls TLS regression rig
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
[MIT](LICENSE), matching upstream MicroPython. The integration glue
|
|
93
|
+
(scripts, port files, CLI, tests) is what's covered here; the
|
|
94
|
+
upstream MicroPython sources fetched by `build_port.sh` retain their
|
|
95
|
+
own MIT license.
|
|
96
|
+
|
|
97
|
+
## Related projects
|
|
98
|
+
|
|
99
|
+
- [uc386](https://github.com/avwohl/uc386) — the C23 compiler that
|
|
100
|
+
builds this port. Hosts the `dos_emu` test harness.
|
|
101
|
+
- [uc_core](https://github.com/avwohl/uc_core) — shared C23 frontend
|
|
102
|
+
used by uc386 (and the Z80 sibling, uc80).
|
|
103
|
+
- [MicroPython](https://github.com/micropython/micropython) — upstream.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "freedos_micro_python"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "MicroPython port for FreeDOS / i386 — built end-to-end through the uc386 C23 compiler"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"uc386>=0.1.0",
|
|
14
|
+
]
|
|
15
|
+
authors = [
|
|
16
|
+
{name = "freedos_micro_python contributors"}
|
|
17
|
+
]
|
|
18
|
+
keywords = [
|
|
19
|
+
"micropython", "python", "freedos", "dos", "i386",
|
|
20
|
+
"retro-computing", "embedded", "interpreter"
|
|
21
|
+
]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 3 - Alpha",
|
|
24
|
+
"Environment :: Console",
|
|
25
|
+
"Intended Audience :: Developers",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.10",
|
|
28
|
+
"Programming Language :: Python :: 3.11",
|
|
29
|
+
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Programming Language :: Python :: 3.13",
|
|
31
|
+
"Topic :: Software Development :: Compilers",
|
|
32
|
+
"Topic :: System :: Emulators",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/avwohl/freedos_micro_python"
|
|
37
|
+
Repository = "https://github.com/avwohl/freedos_micro_python"
|
|
38
|
+
Issues = "https://github.com/avwohl/freedos_micro_python/issues"
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
freedos-micropython = "freedos_micro_python.cli:main"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.package-data]
|
|
47
|
+
freedos_micro_python = [
|
|
48
|
+
"scripts/*.sh",
|
|
49
|
+
"port/*.c",
|
|
50
|
+
"port/*.h",
|
|
51
|
+
"port/arch/*.h",
|
|
52
|
+
"port/lib/**/*.h",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[project.optional-dependencies]
|
|
56
|
+
dev = [
|
|
57
|
+
"pytest>=7.0",
|
|
58
|
+
]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""freedos-micropython CLI: builds the FreeDOS MicroPython binary.
|
|
2
|
+
|
|
3
|
+
Subcommands:
|
|
4
|
+
fetch Run scripts/fetch.sh to clone upstream MicroPython.
|
|
5
|
+
build Run scripts/build.sh (per-TU triage build, generates qstrdefs).
|
|
6
|
+
port Run scripts/build_port.sh (multi-TU build → micropython.bin).
|
|
7
|
+
|
|
8
|
+
Each subcommand is a thin wrapper around the bundled shell script. The
|
|
9
|
+
wrapper:
|
|
10
|
+
|
|
11
|
+
1. Locates uc386's lib/ via the installed package and exports
|
|
12
|
+
UC386_LIB_INCLUDE so the scripts don't have to compute it.
|
|
13
|
+
2. Picks a working directory: uses --workdir if given, else cwd.
|
|
14
|
+
3. Execs the script with stdin/stdout/stderr passed through.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import os
|
|
21
|
+
import subprocess
|
|
22
|
+
import sys
|
|
23
|
+
from importlib.resources import files
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _uc386_lib_include() -> Path:
|
|
28
|
+
import uc386
|
|
29
|
+
return Path(uc386.__file__).resolve().parent / "lib" / "include"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _scripts_dir() -> Path:
|
|
33
|
+
return Path(str(files("freedos_micro_python") / "scripts"))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _port_dir() -> Path:
|
|
37
|
+
return Path(str(files("freedos_micro_python") / "port"))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _ensure_port_symlink(workdir: Path) -> None:
|
|
41
|
+
"""The shipped scripts reference port files as `uc386-dos/foo.c`.
|
|
42
|
+
Make sure `workdir/uc386-dos` points at the bundled port dir so
|
|
43
|
+
those references resolve regardless of where the user is running
|
|
44
|
+
from."""
|
|
45
|
+
link = workdir / "uc386-dos"
|
|
46
|
+
target = _port_dir()
|
|
47
|
+
if link.is_symlink():
|
|
48
|
+
if link.resolve() == target.resolve():
|
|
49
|
+
return
|
|
50
|
+
link.unlink()
|
|
51
|
+
elif link.exists():
|
|
52
|
+
# Real directory at uc386-dos/ — leave it alone, user knows
|
|
53
|
+
# what they're doing.
|
|
54
|
+
return
|
|
55
|
+
link.symlink_to(target)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _run_script(name: str, workdir: Path, extra_args: list[str]) -> int:
|
|
59
|
+
script = _scripts_dir() / name
|
|
60
|
+
if not script.exists():
|
|
61
|
+
print(f"freedos-micropython: bundled script not found: {script}",
|
|
62
|
+
file=sys.stderr)
|
|
63
|
+
return 1
|
|
64
|
+
env = os.environ.copy()
|
|
65
|
+
env["UC386_LIB_INCLUDE"] = str(_uc386_lib_include())
|
|
66
|
+
env["FREEDOS_MP_PORT_DIR"] = str(_port_dir())
|
|
67
|
+
env["FREEDOS_MP_SCRIPTS_DIR"] = str(_scripts_dir())
|
|
68
|
+
workdir.mkdir(parents=True, exist_ok=True)
|
|
69
|
+
_ensure_port_symlink(workdir)
|
|
70
|
+
return subprocess.run(
|
|
71
|
+
[str(script), *extra_args],
|
|
72
|
+
cwd=workdir, env=env,
|
|
73
|
+
).returncode
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def main(argv: list[str] | None = None) -> int:
|
|
77
|
+
ap = argparse.ArgumentParser(
|
|
78
|
+
prog="freedos-micropython",
|
|
79
|
+
description=(
|
|
80
|
+
"Build the FreeDOS / i386 MicroPython port end-to-end "
|
|
81
|
+
"through the uc386 C23 compiler. Produces a flat .bin "
|
|
82
|
+
"runnable under uc386.dos_emu (or a PMODE/W .exe via "
|
|
83
|
+
"uc386's exe.py harness)."
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
ap.add_argument(
|
|
87
|
+
"--workdir", type=Path, default=Path.cwd(),
|
|
88
|
+
help="Directory the build runs in (upstream/ and build/ "
|
|
89
|
+
"land here). Default: current dir.",
|
|
90
|
+
)
|
|
91
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
92
|
+
sub.add_parser("fetch", help="Clone upstream micropython into ./upstream")
|
|
93
|
+
sub.add_parser("build", help="Per-TU triage build (generates qstrdefs)")
|
|
94
|
+
sub.add_parser("port", help="Multi-TU build → build/micropython.bin")
|
|
95
|
+
|
|
96
|
+
ns, extra = ap.parse_known_args(argv)
|
|
97
|
+
script_map = {
|
|
98
|
+
"fetch": "fetch.sh",
|
|
99
|
+
"build": "build.sh",
|
|
100
|
+
"port": "build_port.sh",
|
|
101
|
+
}
|
|
102
|
+
return _run_script(script_map[ns.cmd], ns.workdir, extra)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
if __name__ == "__main__":
|
|
106
|
+
raise SystemExit(main())
|