Skip to content

py/mkrules.mk: Add MICROPY_PREVIEW_VERSION_2_X. #12645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ports_unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ jobs:
if: failure()
run: tests/run-tests.py --print-failures

standard_v2:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: source tools/ci.sh && ci_unix_standard_v2_build
- name: Run main test suite
run: source tools/ci.sh && ci_unix_standard_v2_run_tests
- name: Print failures
if: failure()
run: tests/run-tests.py --print-failures

coverage:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions docs/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ implementation and the best practices to use them.
asm_thumb2_index.rst
filesystem.rst
pyboard.py.rst
micropython2_migration.rst
74 changes: 74 additions & 0 deletions docs/reference/micropython2_migration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
.. _micropython2_migration:

MicroPython 2.0 Migration Guide
===============================

MicroPython 2.0 is the (currently in development, not yet available) next major
release of MicroPython.

After maintaining API compatibility for almost a decade with the ``1.x`` series, in
order to unblock some project-wide improvements MicroPython 2.0 will introduce a
small number of breaking API changes that will require some programs to be
updated. This guide explains how to update your Python code to accommodate these
changes.

This document is a work-in-progress. As more work is done on MicroPython 2.0,
more items will be added to the lists below.

**Note:** There are currently no MicroPython 2.0 firmware builds available for
download. You can build it yourself by enabling the ``MICROPY_PREVIEW_VERSION_2``
config option. As it gets closer to being ready for release, builds will be
provided for both ``1.x.y`` and ``2.0.0-preview``.

Hardware and peripherals
------------------------

Overview
~~~~~~~~

The goal is to improve consistency in the :mod:`machine` APIs across different
ports, making it easier to write code, documentation, and tutorials that work on
any supported microcontroller.

This means that some ports' APIs need to change to match other ports.

Changes
~~~~~~~

*None yet*

OS & filesystem
---------------

Overview
~~~~~~~~

The primary goal is to support the ability to execute :term:`.mpy files <.mpy
file>` directly from the filesystem without first copying them into RAM. This
improves code deployment time and reduces memory overhead and fragmentation.

Additionally, a further goal is to support a more flexible way of configuring
partitions, filesystem types, and options like USB mass storage.

Changes
~~~~~~~

*None yet*

CPython compatibility
---------------------

Overview
~~~~~~~~

The goal is to improve compatibility with CPython by removing MicroPython
extensions from CPython APIs. In most cases this means moving existing
MicroPython-specific functions or classes to new modules.

This makes it easier to write code that works on both CPython and MicroPython,
which is useful for development and testing.

Changes
~~~~~~~

*None yet*
4 changes: 4 additions & 0 deletions ports/esp32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ ifdef BOARD_VARIANT
IDFPY_FLAGS += -D MICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
endif

ifdef MICROPY_PREVIEW_VERSION_2
IDFPY_FLAGS += -D MICROPY_PREVIEW_VERSION_2=1
endif

HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"

define RUN_IDF_PY
Expand Down
4 changes: 4 additions & 0 deletions ports/rp2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ ifdef BOARD_VARIANT
CMAKE_ARGS += -DMICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
endif

ifdef MICROPY_PREVIEW_VERSION_2
CMAKE_ARGS += -DMICROPY_PREVIEW_VERSION_2=1
endif

HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"

all:
Expand Down
10 changes: 10 additions & 0 deletions py/mkrules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ set(MICROPY_ROOT_POINTERS_SPLIT "${MICROPY_GENHDR_DIR}/root_pointers.split")
set(MICROPY_ROOT_POINTERS_COLLECTED "${MICROPY_GENHDR_DIR}/root_pointers.collected")
set(MICROPY_ROOT_POINTERS "${MICROPY_GENHDR_DIR}/root_pointers.h")

if(NOT MICROPY_PREVIEW_VERSION_2)
set(MICROPY_PREVIEW_VERSION_2 0)
endif()

# Need to do this before extracting MICROPY_CPP_DEF below. Rest of frozen
# manifest handling is at the end of this file.
if(MICROPY_FROZEN_MANIFEST)
Expand All @@ -24,6 +28,12 @@ if(MICROPY_FROZEN_MANIFEST)
)
endif()

if(MICROPY_PREVIEW_VERSION_2)
target_compile_definitions(${MICROPY_TARGET} PUBLIC
MICROPY_PREVIEW_VERSION_2=\(1\)
)
endif()

# Provide defaults for preprocessor flags if not already defined
if(NOT MICROPY_CPP_FLAGS)
get_target_property(MICROPY_CPP_INC ${MICROPY_TARGET} INCLUDE_DIRECTORIES)
Expand Down
7 changes: 7 additions & 0 deletions py/mkrules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ THIS_MAKEFILE = $(lastword $(MAKEFILE_LIST))
include $(dir $(THIS_MAKEFILE))mkenv.mk
endif

# Enable in-progress/breaking changes that are slated for MicroPython 2.x.
MICROPY_PREVIEW_VERSION_2 ?= 0

ifeq ($(MICROPY_PREVIEW_VERSION_2),1)
CFLAGS += -DMICROPY_PREVIEW_VERSION_2=1
endif

HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
HELP_MPY_LIB_SUBMODULE ?= "\033[1;31mError: micropython-lib submodule is not initialized.\033[0m Run 'make submodules'"

Expand Down
40 changes: 29 additions & 11 deletions py/modsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,57 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = {
}
};
STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE);
#if MICROPY_PERSISTENT_CODE_LOAD
#define SYS_IMPLEMENTATION_ELEMS \
MP_ROM_QSTR(MP_QSTR_micropython), \
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
MP_ROM_PTR(&mp_sys_implementation_machine_obj), \
MP_ROM_INT(MPY_FILE_HEADER_INT)
#else
#define SYS_IMPLEMENTATION_ELEMS \
#define SYS_IMPLEMENTATION_ELEMS_BASE \
MP_ROM_QSTR(MP_QSTR_micropython), \
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
MP_ROM_PTR(&mp_sys_implementation_machine_obj)

#if MICROPY_PERSISTENT_CODE_LOAD
#define SYS_IMPLEMENTATION_ELEMS__MPY \
, MP_ROM_INT(MPY_FILE_HEADER_INT)
#else
#define SYS_IMPLEMENTATION_ELEMS__MPY
#endif

#if MICROPY_PY_ATTRTUPLE
#if MICROPY_PREVIEW_VERSION_2
#define SYS_IMPLEMENTATION_ELEMS__V2 \
, MP_ROM_TRUE
#else
#define SYS_IMPLEMENTATION_ELEMS__V2
#endif

STATIC const qstr impl_fields[] = {
MP_QSTR_name,
MP_QSTR_version,
MP_QSTR__machine,
#if MICROPY_PERSISTENT_CODE_LOAD
MP_QSTR__mpy,
#endif
#if MICROPY_PREVIEW_VERSION_2
MP_QSTR__v2,
#endif
};
STATIC MP_DEFINE_ATTRTUPLE(
mp_sys_implementation_obj,
impl_fields,
3 + MICROPY_PERSISTENT_CODE_LOAD,
SYS_IMPLEMENTATION_ELEMS
3 + MICROPY_PERSISTENT_CODE_LOAD + MICROPY_PREVIEW_VERSION_2,
SYS_IMPLEMENTATION_ELEMS_BASE
SYS_IMPLEMENTATION_ELEMS__MPY
SYS_IMPLEMENTATION_ELEMS__V2
);
#else
STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = {
{&mp_type_tuple},
3 + MICROPY_PERSISTENT_CODE_LOAD,
// Do not include SYS_IMPLEMENTATION_ELEMS__V2 because
// SYS_IMPLEMENTATION_ELEMS__MPY may be empty if
// MICROPY_PERSISTENT_CODE_LOAD is disabled, which means they'll share
// the same index. Cannot query _v2 if MICROPY_PY_ATTRTUPLE is
// disabled.
{
SYS_IMPLEMENTATION_ELEMS
SYS_IMPLEMENTATION_ELEMS_BASE
SYS_IMPLEMENTATION_ELEMS__MPY
}
};
#endif
Expand Down
10 changes: 10 additions & 0 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
#define MICROPY_VERSION_STRING MICROPY_VERSION_STRING_BASE
#endif

// If this is enabled, then in-progress/breaking changes slated for the 2.x
// release will be enabled.
#ifndef MICROPY_PREVIEW_VERSION_2
#define MICROPY_PREVIEW_VERSION_2 (0)
#endif

// This file contains default configuration settings for MicroPython.
// You can override any of the options below using mpconfigport.h file
// located in a directory of your port.
Expand Down Expand Up @@ -1828,8 +1834,12 @@ typedef double mp_float_t;

// String used for the banner, and sys.version additional information
#ifndef MICROPY_BANNER_NAME_AND_VERSION
#if MICROPY_PREVIEW_VERSION_2
#define MICROPY_BANNER_NAME_AND_VERSION "MicroPython (with v2.0 preview) " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
#else
#define MICROPY_BANNER_NAME_AND_VERSION "MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
#endif
#endif

// String used for the second part of the banner, and sys.implementation._machine
#ifndef MICROPY_BANNER_MACHINE
Expand Down
9 changes: 9 additions & 0 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,15 @@ function ci_unix_standard_run_tests {
ci_unix_run_tests_full_helper standard
}

function ci_unix_standard_v2_build {
ci_unix_build_helper VARIANT=standard MICROPY_PREVIEW_VERSION_2=1
ci_unix_build_ffi_lib_helper gcc
}

function ci_unix_standard_v2_run_tests {
ci_unix_run_tests_full_helper standard
}

function ci_unix_coverage_setup {
sudo pip3 install setuptools
sudo pip3 install pyelftools
Expand Down