Skip to content

Commit 0d2c1bf

Browse files
dhalberttannewt
authored andcommitted
Fix problems that prevented use of internal frozen modules:
1. Allow -Wlto-type-mismatch to be just a warning when building with frozen modules. 2. Fix extern decls that triggered -Wnested-externs when building with frozen modules. 3. Pass the correct value of -mlongint-impl to $(MPY_TOOL). New file mpconfigport.mk to do this.
1 parent af823e6 commit 0d2c1bf

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

atmel-samd/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ ifneq ($(FROZEN_DIR),)
140140
# To use frozen source modules, put your .py files in a subdirectory (eg scripts/)
141141
# and then invoke make with FROZEN_DIR=scripts (be sure to build from scratch).
142142
CFLAGS += -DMICROPY_MODULE_FROZEN_STR
143+
CFLAGS += -Wno-error=lto-type-mismatch
143144
endif
144145

145146
ifneq ($(FROZEN_MPY_DIR),)
146147
# To use frozen bytecode, put your .py files in a subdirectory (eg frozen/) and
147148
# then invoke make with FROZEN_MPY_DIR=frozen (be sure to build from scratch).
148149
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
149150
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
151+
CFLAGS += -Wno-error=lto-type-mismatch
150152
endif
151153

152154
#LIBM_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)

atmel-samd/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#define MICROPY_PY_STRUCT (1)
6363
#define MICROPY_PY_SYS (1)
6464
#define MICROPY_CPYTHON_COMPAT (0)
65+
// If you change MICROPY_LONGINT_IMPL, also change MPY_TOOL_LONGINT_IMPL in mpconfigport.mk.
6566
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
6667
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
6768
#define MICROPY_STREAMS_NON_BLOCK (1)

atmel-samd/mpconfigport.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Define an equivalent for MICROPY_LONGINT_IMPL, to pass to $(MPY-TOOL) in py/mkrules.mk
2+
# $(MPY-TOOL) needs to know what kind of longint to use (if any) to freeze long integers.
3+
# This should correspond to the MICROPY_LONGINT_IMPL definition in mpconfigport.h.
4+
MPY_TOOL_LONGINT_IMPL = -mlongint-impl=none

py/builtinhelp.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ STATIC void mp_help_add_from_names(mp_obj_t list, const char *name) {
7676
}
7777
#endif
7878

79+
// These externs were originally declared inside mp_help_print_modules(),
80+
// but they triggered -Wnested-externs, so they were moved outside.
81+
#if MICROPY_MODULE_FROZEN_STR
82+
extern const char mp_frozen_str_names[];
83+
#endif
84+
85+
#if MICROPY_MODULE_FROZEN_MPY
86+
extern const char mp_frozen_mpy_names[];
87+
#endif
88+
7989
STATIC void mp_help_print_modules(void) {
8090
mp_obj_t list = mp_obj_new_list(0, NULL);
8191

@@ -86,12 +96,10 @@ STATIC void mp_help_print_modules(void) {
8696
#endif
8797

8898
#if MICROPY_MODULE_FROZEN_STR
89-
extern const char mp_frozen_str_names[];
9099
mp_help_add_from_names(list, mp_frozen_str_names);
91100
#endif
92101

93102
#if MICROPY_MODULE_FROZEN_MPY
94-
extern const char mp_frozen_mpy_names[];
95103
mp_help_add_from_names(list, mp_frozen_mpy_names);
96104
#endif
97105

py/mkrules.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ $(BUILD)/frozen_mpy/%.mpy: $(FROZEN_MPY_DIR)/%.py $(TOP)/mpy-cross/mpy-cross
118118
$(Q)$(MPY_CROSS) -o $@ -s $(<:$(FROZEN_MPY_DIR)/%=%) $(MPY_CROSS_FLAGS) $<
119119

120120
# to build frozen_mpy.c from all .mpy files
121+
# You need to define MPY_TOOL_LONGINT_IMPL in mpconfigport.mk
122+
# if the default will not work (mpz is the default).
121123
$(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generated.h
122124
$(STEPECHO) "Creating $@"
123-
$(Q)$(PYTHON) $(MPY_TOOL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(FROZEN_MPY_MPY_FILES) > $@
125+
$(Q)$(PYTHON) $(MPY_TOOL) $(MPY_TOOL_LONGINT_IMPL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(FROZEN_MPY_MPY_FILES) > $@
124126
endif
125127

126128
ifneq ($(PROG),)

0 commit comments

Comments
 (0)