Skip to content

zephyr: Use cmake ExternalProject to build libmicropython.a. #6392

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

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
-v "$(pwd)":/micropython
-e ZEPHYR_SDK_INSTALL_DIR=/opt/sdk/zephyr-sdk-0.11.3
-e ZEPHYR_TOOLCHAIN_VARIANT=zephyr
-e ZEPHYR_BASE=/zephyrproject/zephyr
-w /micropython/ports/zephyr
zephyrprojectrtos/ci:v0.11.8
- docker ps -a
Expand All @@ -58,12 +59,12 @@ jobs:
- docker exec -w /zephyrproject zephyr-ci west update
- docker exec -w /zephyrproject zephyr-ci west zephyr-export
script:
- docker exec zephyr-ci bash -c "make clean; ./make-minimal ${MAKEOPTS}"
- docker exec zephyr-ci bash -c "make clean; ./make-minimal ${MAKEOPTS} BOARD=frdm_k64f"
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS}"
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS} BOARD=frdm_k64f"
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS} BOARD=mimxrt1050_evk"
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS} BOARD=reel_board"
- docker exec zephyr-ci west build -b qemu_x86 -- -DCONF_FILE=prj_minimal.conf
- docker exec zephyr-ci west build -b frdm_k64f -- -DCONF_FILE=prj_minimal.conf
- docker exec zephyr-ci west build -b qemu_x86
- docker exec zephyr-ci west build -b frdm_k64f
- docker exec zephyr-ci west build -b mimxrt1050_evk
- docker exec zephyr-ci west build -b reel_board

# unix port on OSX (first in list because the build VM takes a long time to start)
- stage: test
Expand Down
125 changes: 111 additions & 14 deletions ports/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,121 @@
# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
# Copyright 2020 NXP
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

cmake_minimum_required(VERSION 3.13.1)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(NONE)

target_sources(app PRIVATE src/zephyr_start.c src/zephyr_getchar.c)
project(micropython)

add_library(libmicropython STATIC IMPORTED)
set_target_properties(libmicropython PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libmicropython.a)
target_link_libraries(app PUBLIC libmicropython)
set(micropython_zephyr_dir ${CMAKE_CURRENT_SOURCE_DIR})
set(micropython_top_dir ${micropython_zephyr_dir}/../..)
set(micropython_build_dir ${CMAKE_CURRENT_BINARY_DIR}/micropython)
set(micropython_lib ${micropython_build_dir}/libmicropython.a)
set(micropython_configport_h ${micropython_build_dir}/mpconfigport.h)

# Get all the Zephyr include directories and cflags, and append them with what
# we need to build MicroPython
zephyr_get_include_directories_for_lang_as_string(C includes)
zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
zephyr_get_compile_definitions_for_lang_as_string(C definitions)
zephyr_get_compile_options_for_lang_as_string(C options)

add_custom_target(
outputexports
COMMAND echo CC="${CMAKE_C_COMPILER}"
COMMAND echo AR="${CMAKE_AR}"
COMMAND echo Z_CFLAGS=${system_includes} ${includes} ${definitions} ${options}
VERBATIM
USES_TERMINAL
)
set(micropython_cflags
"${system_includes} ${includes} ${definitions} ${options} \
-I${micropython_build_dir} -I${micropython_zephyr_dir} -I${micropython_top_dir} \
-std=gnu99 -fomit-frame-pointer -DNDEBUG"
)

# If we're calling make recursively, use the same make version as the top-level.
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(submake "$(MAKE)")
else()
set(submake "make")
endif()

# Construct a list of Zephyr port sources, relative to the top-level
# MicroPython directory.
list(APPEND micropython_zephyr_src_list
main.c help.c moduos.c modusocket.c modutime.c modzephyr.c modzsensor.c
modmachine.c machine_i2c.c machine_pin.c uart_core.c zephyr_storage.c
)
list(TRANSFORM micropython_zephyr_src_list PREPEND ports/zephyr/)

# Construct a list of MicroPython lib sources used by the Zephyr port, relative
# to the top-level MicroPython directory.
list(APPEND micropython_lib_src_list
timeutils/timeutils.c utils/mpirq.c utils/stdout_helpers.c utils/printf.c
utils/pyexec.c utils/interrupt_char.c mp-readline/readline.c
)
list(TRANSFORM micropython_lib_src_list PREPEND lib/)

# Combine the lists of sources into one string and substitute it into a
# generated Makefile in the build directory. The MicroPython lib target will
# process them for QSTR generation and build them.
list(APPEND micropython_src_list ${micropython_zephyr_src_list} ${micropython_lib_src_list})
list(JOIN micropython_src_list " \\\n\t" micropython_src)
configure_file(${micropython_zephyr_dir}/Makefile.in ${micropython_build_dir}/Makefile @ONLY)

# Copy the MicroPython configuration file set in Kconfig (usually
# mpconfigport.h, but could also be mpconfigport_minimal.h or some other
# user-defined file) into the build directory. This allows building
# libmicropython.a outside of the Zephyr port source directory, which is useful
# when building for multiple boards or regressing with the Zephyr sanitycheck
# script.
configure_file(${CONFIG_MICROPY_CONFIGFILE} ${micropython_configport_h} @ONLY)

# Use the generated Makefile to build libmicropython.a
include(ExternalProject)
ExternalProject_Add(
micropython_project
PREFIX ${micropython_build_dir}
SOURCE_DIR ${micropython_zephyr_dir}
BINARY_DIR ${micropython_build_dir}
CONFIGURE_COMMAND ""
BUILD_COMMAND
${submake}
CC=${CMAKE_C_COMPILER}
AR=${CMAKE_AR}
BUILD=${micropython_build_dir}
MP_CONFIGFILE=<${micropython_configport_h}>
FROZEN_DIR=${CONFIG_MICROPY_FROZEN_DIR}
MICROPY_HEAP_SIZE=${CONFIG_MICROPY_HEAP_SIZE}
MICROPY_VFS_FAT=$<BOOL:${CONFIG_MICROPY_VFS_FAT}>
MICROPY_VFS_LFS1=$<BOOL:${CONFIG_MICROPY_VFS_LFS1}>
MICROPY_VFS_LFS2=$<BOOL:${CONFIG_MICROPY_VFS_LFS2}>
Z_CFLAGS=${micropython_cflags}
DEPENDS zephyr_generated_headers
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${micropython_lib}
)

# Create a wrapper CMake library that our application can link with
add_library(micropython_lib STATIC IMPORTED GLOBAL)
add_dependencies(micropython_lib micropython_project)
set_target_properties(micropython_lib PROPERTIES IMPORTED_LOCATION ${micropython_lib})
set_target_properties(micropython_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${micropython_top_dir})
set_target_properties(micropython_lib PROPERTIES ADDITIONAL_CLEAN_FILES ${micropython_lib})

# Build the final application
target_sources(app PRIVATE src/zephyr_start.c src/zephyr_getchar.c)
target_link_libraries(app PUBLIC micropython_lib)
3 changes: 0 additions & 3 deletions ports/zephyr/Kbuild

This file was deleted.

49 changes: 49 additions & 0 deletions ports/zephyr/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
# Copyright 2020 NXP
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

menu "MicroPython Options"

config MICROPY_CONFIGFILE
string "Configuration file"
default "mpconfigport_minimal.h"

config MICROPY_HEAP_SIZE
int "Heap size"
default 16384

config MICROPY_FROZEN_DIR
string "Frozen directory"

config MICROPY_VFS_FAT
bool "FatFS file system"

config MICROPY_VFS_LFS1
bool "LittleFs version 1 file system"

config MICROPY_VFS_LFS2
bool "LittleFs version 2 file system"

endmenu # MicroPython Options

source "Kconfig.zephyr"
115 changes: 0 additions & 115 deletions ports/zephyr/Makefile

This file was deleted.

40 changes: 40 additions & 0 deletions ports/zephyr/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
# Copyright 2020 NXP
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

all: lib

include @micropython_top_dir@/py/mkenv.mk
include $(TOP)/py/py.mk

SRC_C = \
@micropython_src@ \
$(SRC_MOD)

SRC_QSTR += $(SRC_C)

OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))

CFLAGS = $(Z_CFLAGS) $(CFLAGS_MOD) $(CFLAGS_EXTRA) $(INC)

include $(TOP)/py/mkrules.mk
Loading
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