Skip to content

Commit f3ad4f6

Browse files
committed
zephyr: Use cmake ExternalProject to build libmicropython.a.
Rework the zephyr port's build infrastructure to build libmicropython.a with a cmake ExternalProject, instead of invoking cmake from a Makefile (which was an awkward thing to do because cmake typically generates Makefiles). This change makes it possible to build the zephyr port like most other zephyr applications using west or cmake directly. It simplifies building with extra cmake arguments, such as specifying an alternate conf file or adding an Arduino shield. It also enables building the zephyr port anywhere in the host file system, which will allow regressing across multiple boards with the zephyr sanitycheck script. To build with west: $ west build -b frdm_k64f ~/micropython/ports/zephyr To build with cmake: $ mkdir build && cd build $ cmake -DBOARD=frdm_k64f ~/micropython/ports/zephyr $ make To build the minimal configuration: $ west build -b frdm_k64f -- -DCONF_FILE=prj_minimal.conf To build with a zephyr-supported Arduino shield: $ west build -b frdm_k64f -- -DSHIELD=frdm_kw41z Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
1 parent 6835ca0 commit f3ad4f6

File tree

8 files changed

+242
-180
lines changed

8 files changed

+242
-180
lines changed

.travis.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
-v "$(pwd)":/micropython
5151
-e ZEPHYR_SDK_INSTALL_DIR=/opt/sdk/zephyr-sdk-0.11.3
5252
-e ZEPHYR_TOOLCHAIN_VARIANT=zephyr
53+
-e ZEPHYR_BASE=/zephyrproject/zephyr
5354
-w /micropython/ports/zephyr
5455
zephyrprojectrtos/ci:v0.11.8
5556
- docker ps -a
@@ -58,12 +59,12 @@ jobs:
5859
- docker exec -w /zephyrproject zephyr-ci west update
5960
- docker exec -w /zephyrproject zephyr-ci west zephyr-export
6061
script:
61-
- docker exec zephyr-ci bash -c "make clean; ./make-minimal ${MAKEOPTS}"
62-
- docker exec zephyr-ci bash -c "make clean; ./make-minimal ${MAKEOPTS} BOARD=frdm_k64f"
63-
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS}"
64-
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS} BOARD=frdm_k64f"
65-
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS} BOARD=mimxrt1050_evk"
66-
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS} BOARD=reel_board"
62+
- docker exec zephyr-ci west build -b qemu_x86 -- -DCONF_FILE=prj_minimal.conf
63+
- docker exec zephyr-ci west build -b frdm_k64f -- -DCONF_FILE=prj_minimal.conf
64+
- docker exec zephyr-ci west build -b qemu_x86
65+
- docker exec zephyr-ci west build -b frdm_k64f
66+
- docker exec zephyr-ci west build -b mimxrt1050_evk
67+
- docker exec zephyr-ci west build -b reel_board
6768

6869
# unix port on OSX (first in list because the build VM takes a long time to start)
6970
- stage: test

ports/zephyr/CMakeLists.txt

Lines changed: 111 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,121 @@
1+
# This file is part of the MicroPython project, http://micropython.org/
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright 2020 NXP
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
125
cmake_minimum_required(VERSION 3.13.1)
226

327
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
4-
project(NONE)
5-
6-
target_sources(app PRIVATE src/zephyr_start.c src/zephyr_getchar.c)
28+
project(micropython)
729

8-
add_library(libmicropython STATIC IMPORTED)
9-
set_target_properties(libmicropython PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libmicropython.a)
10-
target_link_libraries(app PUBLIC libmicropython)
30+
set(micropython_zephyr_dir ${CMAKE_CURRENT_SOURCE_DIR})
31+
set(micropython_top_dir ${micropython_zephyr_dir}/../..)
32+
set(micropython_build_dir ${CMAKE_CURRENT_BINARY_DIR}/micropython)
33+
set(micropython_lib ${micropython_build_dir}/libmicropython.a)
34+
set(micropython_configport_h ${micropython_build_dir}/mpconfigport.h)
1135

36+
# Get all the Zephyr include directories and cflags, and append them with what
37+
# we need to build MicroPython
1238
zephyr_get_include_directories_for_lang_as_string(C includes)
1339
zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
1440
zephyr_get_compile_definitions_for_lang_as_string(C definitions)
1541
zephyr_get_compile_options_for_lang_as_string(C options)
1642

17-
add_custom_target(
18-
outputexports
19-
COMMAND echo CC="${CMAKE_C_COMPILER}"
20-
COMMAND echo AR="${CMAKE_AR}"
21-
COMMAND echo Z_CFLAGS=${system_includes} ${includes} ${definitions} ${options}
22-
VERBATIM
23-
USES_TERMINAL
24-
)
43+
set(micropython_cflags
44+
"${system_includes} ${includes} ${definitions} ${options} \
45+
-I${micropython_build_dir} -I${micropython_zephyr_dir} -I${micropython_top_dir} \
46+
-std=gnu99 -fomit-frame-pointer -DNDEBUG"
47+
)
48+
49+
# If we're calling make recursively, use the same make version as the top-level.
50+
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
51+
set(submake "$(MAKE)")
52+
else()
53+
set(submake "make")
54+
endif()
55+
56+
# Construct a list of Zephyr port sources, relative to the top-level
57+
# MicroPython directory.
58+
list(APPEND micropython_zephyr_src_list
59+
main.c help.c moduos.c modusocket.c modutime.c modzephyr.c modzsensor.c
60+
modmachine.c machine_i2c.c machine_pin.c uart_core.c zephyr_storage.c
61+
)
62+
list(TRANSFORM micropython_zephyr_src_list PREPEND ports/zephyr/)
63+
64+
# Construct a list of MicroPython lib sources used by the Zephyr port, relative
65+
# to the top-level MicroPython directory.
66+
list(APPEND micropython_lib_src_list
67+
timeutils/timeutils.c utils/mpirq.c utils/stdout_helpers.c utils/printf.c
68+
utils/pyexec.c utils/interrupt_char.c mp-readline/readline.c
69+
)
70+
list(TRANSFORM micropython_lib_src_list PREPEND lib/)
71+
72+
# Combine the lists of sources into one string and substitute it into a
73+
# generated Makefile in the build directory. The MicroPython lib target will
74+
# process them for QSTR generation and build them.
75+
list(APPEND micropython_src_list ${micropython_zephyr_src_list} ${micropython_lib_src_list})
76+
list(JOIN micropython_src_list " \\\n\t" micropython_src)
77+
configure_file(${micropython_zephyr_dir}/Makefile.in ${micropython_build_dir}/Makefile @ONLY)
78+
79+
# Copy the MicroPython configuration file set in Kconfig (usually
80+
# mpconfigport.h, but could also be mpconfigport_minimal.h or some other
81+
# user-defined file) into the build directory. This allows building
82+
# libmicropython.a outside of the Zephyr port source directory, which is useful
83+
# when building for multiple boards or regressing with the Zephyr sanitycheck
84+
# script.
85+
configure_file(${CONFIG_MICROPY_CONFIGFILE} ${micropython_configport_h} @ONLY)
86+
87+
# Use the generated Makefile to build libmicropython.a
88+
include(ExternalProject)
89+
ExternalProject_Add(
90+
micropython_project
91+
PREFIX ${micropython_build_dir}
92+
SOURCE_DIR ${micropython_zephyr_dir}
93+
BINARY_DIR ${micropython_build_dir}
94+
CONFIGURE_COMMAND ""
95+
BUILD_COMMAND
96+
${submake}
97+
CC=${CMAKE_C_COMPILER}
98+
AR=${CMAKE_AR}
99+
BUILD=${micropython_build_dir}
100+
MP_CONFIGFILE=<${micropython_configport_h}>
101+
FROZEN_DIR=${CONFIG_MICROPY_FROZEN_DIR}
102+
MICROPY_HEAP_SIZE=${CONFIG_MICROPY_HEAP_SIZE}
103+
MICROPY_VFS_FAT=$<BOOL:${CONFIG_MICROPY_VFS_FAT}>
104+
MICROPY_VFS_LFS1=$<BOOL:${CONFIG_MICROPY_VFS_LFS1}>
105+
MICROPY_VFS_LFS2=$<BOOL:${CONFIG_MICROPY_VFS_LFS2}>
106+
Z_CFLAGS=${micropython_cflags}
107+
DEPENDS zephyr_generated_headers
108+
INSTALL_COMMAND ""
109+
BUILD_BYPRODUCTS ${micropython_lib}
110+
)
111+
112+
# Create a wrapper CMake library that our application can link with
113+
add_library(micropython_lib STATIC IMPORTED GLOBAL)
114+
add_dependencies(micropython_lib micropython_project)
115+
set_target_properties(micropython_lib PROPERTIES IMPORTED_LOCATION ${micropython_lib})
116+
set_target_properties(micropython_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${micropython_top_dir})
117+
set_target_properties(micropython_lib PROPERTIES ADDITIONAL_CLEAN_FILES ${micropython_lib})
118+
119+
# Build the final application
120+
target_sources(app PRIVATE src/zephyr_start.c src/zephyr_getchar.c)
121+
target_link_libraries(app PUBLIC micropython_lib)

ports/zephyr/Kconfig

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This file is part of the MicroPython project, http://micropython.org/
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright 2020 NXP
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
25+
menu "MicroPython Options"
26+
27+
config MICROPY_CONFIGFILE
28+
string "Configuration file"
29+
default "mpconfigport_minimal.h"
30+
31+
config MICROPY_HEAP_SIZE
32+
int "Heap size"
33+
default 16384
34+
35+
config MICROPY_FROZEN_DIR
36+
string "Frozen directory"
37+
38+
config MICROPY_VFS_FAT
39+
bool "FatFS file system"
40+
41+
config MICROPY_VFS_LFS1
42+
bool "LittleFs version 1 file system"
43+
44+
config MICROPY_VFS_LFS2
45+
bool "LittleFs version 2 file system"
46+
47+
endmenu # MicroPython Options
48+
49+
source "Kconfig.zephyr"

ports/zephyr/Makefile

Lines changed: 0 additions & 115 deletions
This file was deleted.

ports/zephyr/Makefile.in

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This file is part of the MicroPython project, http://micropython.org/
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright 2020 NXP
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
25+
all: lib
26+
27+
include @micropython_top_dir@/py/mkenv.mk
28+
include $(TOP)/py/py.mk
29+
30+
SRC_C = \
31+
@micropython_src@ \
32+
$(SRC_MOD)
33+
34+
SRC_QSTR += $(SRC_C)
35+
36+
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
37+
38+
CFLAGS = $(Z_CFLAGS) $(CFLAGS_MOD) $(CFLAGS_EXTRA) $(INC)
39+
40+
include $(TOP)/py/mkrules.mk

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy