Skip to content

Commit 66e6ad0

Browse files
committed
py/mkrules.mk: Make MICROPY_MODULE_FROZEN_STR conditional on compiler.
When MICROPY_ENABLE_COMPILER=0, MICROPY_MODULE_FROZEN_STR defaults to 0 since frozen .py source files require the compiler at runtime. Only pre-compiled .mpy bytecode can be used without the compiler. Also pass MICROPY_ENABLE_COMPILER=0 to CFLAGS when explicitly set. ports/windows/variants/pydfu: Disable compiler for frozen .mpy only. The pydfu variant uses only pre-compiled frozen .mpy modules, so the compiler is not needed. This reduces binary size by ~90KB. Tested on Unix port with MICROPY_ENABLE_COMPILER=0 - frozen modules execute correctly without the compiler.
1 parent 9480e9b commit 66e6ad0

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

ports/windows/variants/pydfu/mpconfigvariant.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626

2727
// Minimal variant for pydfu standalone application.
2828
// Disables features not needed to reduce binary size.
29-
30-
// Note: MICROPY_ENABLE_COMPILER cannot be disabled because the build system
31-
// unconditionally enables MICROPY_MODULE_FROZEN_STR which requires the compiler.
32-
// This is a MicroPython core limitation.
29+
// The compiler is disabled via mpconfigvariant.mk since only frozen .mpy
30+
// bytecode is used.
3331

3432
// Disable modules not needed by pydfu
3533
#define MICROPY_PY_JSON (0)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Minimal variant for pydfu standalone application.
22
# Enables FFI for pyusb to call libusb.
3+
# Disables compiler since only frozen .mpy bytecode is used.
34

45
MICROPY_PY_FFI = 1
6+
MICROPY_ENABLE_COMPILER = 0

py/mkrules.mk

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,23 @@ endif
212212
# Set compile options needed to enable frozen code.
213213
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
214214
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
215+
216+
# MICROPY_MODULE_FROZEN_STR enables freezing .py files as source text that
217+
# requires the compiler at runtime. If the compiler is disabled, default this
218+
# to 0 since only pre-compiled .mpy files can be used.
219+
ifeq ($(MICROPY_ENABLE_COMPILER),0)
220+
MICROPY_MODULE_FROZEN_STR ?= 0
221+
else
222+
MICROPY_MODULE_FROZEN_STR ?= 1
223+
endif
224+
ifneq ($(MICROPY_MODULE_FROZEN_STR),0)
215225
CFLAGS += -DMICROPY_MODULE_FROZEN_STR
226+
endif
227+
228+
# Pass MICROPY_ENABLE_COMPILER to CFLAGS if explicitly set.
229+
ifeq ($(MICROPY_ENABLE_COMPILER),0)
230+
CFLAGS += -DMICROPY_ENABLE_COMPILER=0
231+
endif
216232

217233
# Set default path variables to be passed to makemanifest.py. These will be
218234
# available in path substitutions. Additional variables can be set per-board

0 commit comments

Comments
 (0)