kopia lustrzana https://github.com/micropython/micropython
ports/embed: Enable freezing Python modules.
Use FROZEN_MANIFEST as documented in docs/reference/manifest.rst. Signed-off-by: Christian Walther <cwalther@gmx.ch>
rodzic
1be753fb7e
commit
d3656e97fe
|
@ -15,6 +15,8 @@ Building the example
|
||||||
|
|
||||||
First build the embed port using:
|
First build the embed port using:
|
||||||
|
|
||||||
|
$ make -C mpy-cross
|
||||||
|
$ cd examples/embedding-full
|
||||||
$ make -f micropython_embed.mk submodules
|
$ make -f micropython_embed.mk submodules
|
||||||
$ make -f micropython_embed.mk
|
$ make -f micropython_embed.mk
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,9 @@ static const char *example_2 =
|
||||||
"help(random)\n"
|
"help(random)\n"
|
||||||
"import time\n"
|
"import time\n"
|
||||||
"help(time)\n"
|
"help(time)\n"
|
||||||
|
"import frozenhello\n"
|
||||||
|
"help(frozenhello)\n"
|
||||||
|
"print('frozenhello.hello():', frozenhello.hello())\n"
|
||||||
"\n"
|
"\n"
|
||||||
"print('finish')\n"
|
"print('finish')\n"
|
||||||
;
|
;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
module("frozenhello.py", base_path="modules")
|
|
@ -8,5 +8,8 @@ MICROPYTHON_TOP = ../..
|
||||||
# Include modules from extmod in the output.
|
# Include modules from extmod in the output.
|
||||||
EMBED_EXTRA = extmod
|
EMBED_EXTRA = extmod
|
||||||
|
|
||||||
|
# Freeze Python modules.
|
||||||
|
FROZEN_MANIFEST ?= manifest.py
|
||||||
|
|
||||||
# Include the main makefile fragment to build the MicroPython component.
|
# Include the main makefile fragment to build the MicroPython component.
|
||||||
include $(MICROPYTHON_TOP)/ports/embed/embed.mk
|
include $(MICROPYTHON_TOP)/ports/embed/embed.mk
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
def hello():
|
||||||
|
return "Hello from the cold!"
|
|
@ -36,3 +36,13 @@
|
||||||
|
|
||||||
// We have our own implementation of mp_hal_stdout_tx_strn_cooked().
|
// We have our own implementation of mp_hal_stdout_tx_strn_cooked().
|
||||||
#undef MP_PLAT_PRINT_STRN
|
#undef MP_PLAT_PRINT_STRN
|
||||||
|
|
||||||
|
// Enable freezing of Python modules. These would be set automatically for the
|
||||||
|
// port build based on the presence of FROZEN_MANIFEST by py/mkrules.mk, but
|
||||||
|
// must be set explicitly for the application build.
|
||||||
|
#define MICROPY_MODULE_FROZEN_MPY 1
|
||||||
|
#define MICROPY_MODULE_FROZEN_STR 1
|
||||||
|
#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool
|
||||||
|
// must match MPY_TOOL_FLAGS or defaults for mpy-tool.py arguments
|
||||||
|
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
|
||||||
|
#define MPZ_DIG_SIZE (16)
|
||||||
|
|
|
@ -34,6 +34,11 @@ GENHDR_OUTPUT = $(addprefix $(BUILD)/genhdr/, \
|
||||||
root_pointers.h \
|
root_pointers.h \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Define the module freezing output.
|
||||||
|
ifneq ($(FROZEN_MANIFEST),)
|
||||||
|
FROZEN_OUTPUT = $(BUILD)/frozen_content.c
|
||||||
|
endif
|
||||||
|
|
||||||
# Define the top-level target, the generated output files.
|
# Define the top-level target, the generated output files.
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: micropython-embed-package
|
all: micropython-embed-package
|
||||||
|
@ -49,9 +54,12 @@ PACKAGE_DIR_LIST = $(addprefix $(PACKAGE_DIR)/,py extmod shared/runtime genhdr p
|
||||||
ifeq ($(filter extmod,$(EMBED_EXTRA)),extmod)
|
ifeq ($(filter extmod,$(EMBED_EXTRA)),extmod)
|
||||||
PACKAGE_DIR_LIST += $(addprefix $(PACKAGE_DIR)/,lib/uzlib lib/crypto-algorithms lib/re1.5)
|
PACKAGE_DIR_LIST += $(addprefix $(PACKAGE_DIR)/,lib/uzlib lib/crypto-algorithms lib/re1.5)
|
||||||
endif
|
endif
|
||||||
|
ifneq ($(FROZEN_MANIFEST),)
|
||||||
|
PACKAGE_DIR_LIST += $(addprefix $(PACKAGE_DIR)/,frozen)
|
||||||
|
endif
|
||||||
|
|
||||||
.PHONY: micropython-embed-package
|
.PHONY: micropython-embed-package
|
||||||
micropython-embed-package: $(GENHDR_OUTPUT)
|
micropython-embed-package: $(GENHDR_OUTPUT) $(FROZEN_OUTPUT)
|
||||||
$(ECHO) "Generate micropython_embed output:"
|
$(ECHO) "Generate micropython_embed output:"
|
||||||
$(Q)$(RM) -rf $(PACKAGE_DIR_LIST)
|
$(Q)$(RM) -rf $(PACKAGE_DIR_LIST)
|
||||||
$(Q)$(MKDIR) -p $(PACKAGE_DIR_LIST)
|
$(Q)$(MKDIR) -p $(PACKAGE_DIR_LIST)
|
||||||
|
@ -72,6 +80,10 @@ endif
|
||||||
$(Q)$(CP) $(TOP)/shared/runtime/gchelper_generic.c $(PACKAGE_DIR)/shared/runtime
|
$(Q)$(CP) $(TOP)/shared/runtime/gchelper_generic.c $(PACKAGE_DIR)/shared/runtime
|
||||||
$(ECHO) "- genhdr"
|
$(ECHO) "- genhdr"
|
||||||
$(Q)$(CP) $(GENHDR_OUTPUT) $(PACKAGE_DIR)/genhdr
|
$(Q)$(CP) $(GENHDR_OUTPUT) $(PACKAGE_DIR)/genhdr
|
||||||
|
ifneq ($(FROZEN_MANIFEST),)
|
||||||
|
$(ECHO) "- frozen"
|
||||||
|
$(Q)$(CP) $(FROZEN_OUTPUT) $(PACKAGE_DIR)/frozen
|
||||||
|
endif
|
||||||
$(ECHO) "- port"
|
$(ECHO) "- port"
|
||||||
$(Q)$(CP) $(MICROPYTHON_EMBED_PORT)/port/*.[ch] $(PACKAGE_DIR)/port
|
$(Q)$(CP) $(MICROPYTHON_EMBED_PORT)/port/*.[ch] $(PACKAGE_DIR)/port
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue