circuitpython/mpy-cross
Jim Mussared f31a358eb2 mpy-cross/main: Don't set a default native architecture.
If `-march` isn't set then it means the user hasn't thought about it, or in
the case of freezing, MPY_CROSS_FLAGS isn't set.  It's almost certainly
going to lead to problems, as there's no reason why the host architecture
is likely to be the right choice.

Compiling regular Python code is unaffected, but if `@native`/`@viper` is
used, the compiler will raise `SyntaxError: invalid arch`.

For situations where you explicitly want to use the host architecture (e.g.
for running tests on the unix port), added -march=host that keeps the old
behavior.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-11-17 22:37:45 +11:00
..
mpy_cross mpy-cross/mpy_cross: Add docstrings to public methods. 2022-09-28 11:47:11 +10:00
gccollect.c all: Update to point to files in new shared/ directory. 2021-07-12 17:08:10 +10:00
main.c mpy-cross/main: Don't set a default native architecture. 2022-11-17 22:37:45 +11:00
Makefile extmod: Make extmod.mk self-contained. 2022-10-11 23:31:49 +11:00
mpconfigport.h mpy-cross,unix: Include alloca.h for NetBSD. 2022-08-23 13:39:18 +10:00
mphalport.h mpy-cross: Make build independent of extmod directory. 2018-07-10 14:11:28 +10:00
mpy-cross.vcxproj windows: Unify project file headers. 2022-02-25 16:41:11 +11:00
qstrdefsport.h mpy-cross: Add new component, a cross compiler for MicroPython bytecode. 2016-02-25 10:12:21 +00:00
README.md all: Remove MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE. 2021-09-16 16:04:03 +10:00

MicroPython cross compiler

This directory contains the MicroPython cross compiler, which runs under any Unix-like system and compiles .py scripts into .mpy files.

Build it as usual:

$ make

The compiler is called mpy-cross. Invoke it as:

$ ./mpy-cross foo.py

This will create a file foo.mpy which can then be copied to a place accessible by the target MicroPython runtime (eg onto a pyboard's filesystem), and then imported like any other Python module using import foo.

Different target runtimes may require a different format of the compiled bytecode, and such options can be passed to the cross compiler.

If the Python code contains @native or @viper annotations, then you must specify -march to match the target architecture.

Run ./mpy-cross -h to get a full list of options.

The optimisation level is 0 by default. Optimisation levels are detailed in https://docs.micropython.org/en/latest/library/micropython.html#micropython.opt_level