Skip to content

unix: Add build variants (analogous to boards on baremetal). #5253

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 5 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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- make ${MAKEOPTS} -C mpy-cross
- make ${MAKEOPTS} -C ports/unix submodules
- make ${MAKEOPTS} -C ports/unix deplibs
- make ${MAKEOPTS} -C ports/unix coverage
- make ${MAKEOPTS} -C ports/unix VARIANT=coverage
# run the main test suite
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests)
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -d thread)
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:
- make ${MAKEOPTS} -C mpy-cross PYTHON=python2
- make ${MAKEOPTS} -C ports/unix submodules
- make ${MAKEOPTS} -C ports/unix PYTHON=python2 deplibs
- make ${MAKEOPTS} -C ports/unix PYTHON=python2 nanbox
- make ${MAKEOPTS} -C ports/unix PYTHON=python2 VARIANT=nanbox
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_nanbox ./run-tests)

# unix stackless
Expand Down
7 changes: 2 additions & 5 deletions ports/unix/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
micropython
micropython_fast
micropython_minimal
micropython_coverage
micropython_nanbox
micropython_freedos*
micropython_*
micropython-*
*.py
*.gcov
107 changes: 40 additions & 67 deletions ports/unix/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
-include mpconfigport.mk
# Select the variant to build for.
VARIANT ?= standard

# If the build directory is not given, make it reflect the variant name.
BUILD ?= build-$(VARIANT)

VARIANT_DIR ?= variants/$(VARIANT)
ifeq ($(wildcard $(VARIANT_DIR)/.),)
$(error Invalid VARIANT specified: $(VARIANT_DIR))
endif

include ../../py/mkenv.mk
-include mpconfigport.mk
include $(VARIANT_DIR)/mpconfigvariant.mk

# use FROZEN_MANIFEST for new projects, others are legacy
FROZEN_MANIFEST ?= manifest.py
FROZEN_DIR =
FROZEN_MPY_DIR =

# define main target
PROG = micropython
# This should be configured by the mpconfigvariant.mk
PROG ?= micropython

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
QSTR_GLOBAL_DEPENDENCIES = $(VARIANT_DIR)/mpconfigvariant.h

# OS name, for simple autoconfig
UNAME_S := $(shell uname -s)
Expand All @@ -27,7 +40,7 @@ INC += -I$(BUILD)
# compiler settings
CWARN = -Wall -Werror
CWARN += -Wpointer-arith -Wuninitialized
CFLAGS = $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
CFLAGS = $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EXTRA)

# Debugging/Optimization
ifdef DEBUG
Expand Down Expand Up @@ -156,7 +169,8 @@ SRC_C = \
alloc.c \
coverage.c \
fatfs_port.c \
$(SRC_MOD)
$(SRC_MOD) \
$(wildcard $(VARIANT_DIR)/*.c)

LIB_SRC_C = $(addprefix lib/,\
$(LIB_SRC_C_EXTRA) \
Expand Down Expand Up @@ -188,83 +202,42 @@ endif

include $(TOP)/py/mkrules.mk

.PHONY: test
.PHONY: test test_full

test: $(PROG) $(TOP)/tests/run-tests
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests

# install micropython in /usr/local/bin
TARGET = micropython
PREFIX = $(DESTDIR)/usr/local
BINDIR = $(PREFIX)/bin

install: micropython
install -d $(BINDIR)
install $(TARGET) $(BINDIR)/$(TARGET)
test_full: $(PROG) $(TOP)/tests/run-tests
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests -d thread
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --emit native
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --via-mpy -d basics float micropython
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --via-mpy --emit native -d basics float micropython
cat $(TOP)/tests/basics/0prelim.py | ./$(PROG) | grep -q 'abc'

# uninstall micropython
uninstall:
-rm $(BINDIR)/$(TARGET)
test_gcov: test_full
gcov -o $(BUILD)/py $(TOP)/py/*.c
gcov -o $(BUILD)/extmod $(TOP)/extmod/*.c

# build synthetically fast interpreter for benchmarking
# Maintain historical targets from pre-variant configurations.
fast:
$(MAKE) COPT="-O2 -DNDEBUG -fno-crossjumping" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_fast.h>"' BUILD=build-fast PROG=micropython_fast FROZEN_MANIFEST=
$(MAKE) VARIANT=fast

# build a minimal interpreter
minimal:
$(MAKE) COPT="-Os -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_minimal.h>"' \
BUILD=build-minimal PROG=micropython_minimal FROZEN_MANIFEST= \
MICROPY_PY_BTREE=0 MICROPY_PY_FFI=0 MICROPY_PY_SOCKET=0 MICROPY_PY_THREAD=0 \
MICROPY_PY_TERMIOS=0 MICROPY_PY_USSL=0 \
MICROPY_USE_READLINE=0
$(MAKE) VARIANT=minimal

# build interpreter with nan-boxing as object model
nanbox:
$(MAKE) \
CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_nanbox.h>"' \
BUILD=build-nanbox \
PROG=micropython_nanbox \
MICROPY_FORCE_32BIT=1
$(MAKE) VARIANT=nanbox

freedos:
$(MAKE) \
CC=i586-pc-msdosdjgpp-gcc \
STRIP=i586-pc-msdosdjgpp-strip \
SIZE=i586-pc-msdosdjgpp-size \
CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_freedos.h>" -DMICROPY_NLR_SETJMP -Dtgamma=gamma -DMICROPY_EMIT_X86=0 -DMICROPY_NO_ALLOCA=1 -DMICROPY_PY_USELECT_POSIX=0' \
BUILD=build-freedos \
PROG=micropython_freedos \
MICROPY_PY_SOCKET=0 \
MICROPY_PY_FFI=0 \
MICROPY_PY_JNI=0 \
MICROPY_PY_BTREE=0 \
MICROPY_PY_THREAD=0 \
MICROPY_PY_USSL=0

# build an interpreter for coverage testing and do the testing
$(MAKE) VARIANT=freedos

coverage:
$(MAKE) \
COPT="-O0" CFLAGS_EXTRA='$(CFLAGS_EXTRA) -DMP_CONFIGFILE="<mpconfigport_coverage.h>" \
-fprofile-arcs -ftest-coverage \
-Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wsign-compare \
-Wold-style-definition -Wpointer-arith -Wshadow -Wuninitialized -Wunused-parameter \
-DMICROPY_UNIX_COVERAGE' \
LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' \
MICROPY_VFS_FAT=1 MICROPY_VFS_LFS1=1 MICROPY_VFS_LFS2=1 \
FROZEN_MANIFEST=manifest_coverage.py \
BUILD=build-coverage PROG=micropython_coverage

coverage_test: coverage
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests -d thread
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --emit native
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --via-mpy -d basics float micropython
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --via-mpy --emit native -d basics float micropython
cat $(TOP)/tests/basics/0prelim.py | ./micropython_coverage | grep -q 'abc'
gcov -o build-coverage/py $(TOP)/py/*.c
gcov -o build-coverage/extmod $(TOP)/extmod/*.c
$(MAKE) VARIANT=coverage
coverage_test:
$(MAKE) VARIANT=coverage test_gcov

# Value of configure's --host= option (required for cross-compilation).
# Deduce it from CROSS_COMPILE by default, but can be overridden.
Expand Down
16 changes: 15 additions & 1 deletion ports/unix/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
* THE SOFTWARE.
*/

// options to control how MicroPython is built
// Options to control how MicroPython is built for this port,
// overriding defaults in py/mpconfig.h.

// Variant-specific definitions.
#include "mpconfigvariant.h"

// The minimal variant's config covers everything.
// If we're building the minimal variant, ignore the rest of this file.
#ifndef MICROPY_UNIX_MINIMAL

#define MICROPY_ALLOC_PATH_MAX (PATH_MAX)
#define MICROPY_PERSISTENT_CODE_LOAD (1)
Expand Down Expand Up @@ -64,7 +72,9 @@
#define MICROPY_ENABLE_SOURCE_LINE (1)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#ifndef MICROPY_STREAMS_NON_BLOCK
#define MICROPY_STREAMS_NON_BLOCK (1)
#endif
#define MICROPY_STREAMS_POSIX_API (1)
#define MICROPY_OPT_COMPUTED_GOTO (1)
#ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
Expand Down Expand Up @@ -97,11 +107,13 @@
#define MICROPY_PERSISTENT_CODE_SAVE (1)
#define MICROPY_COMP_CONST (0)
#endif
#ifndef MICROPY_PY_SYS_PLATFORM
#if defined(__APPLE__) && defined(__MACH__)
#define MICROPY_PY_SYS_PLATFORM "darwin"
#else
#define MICROPY_PY_SYS_PLATFORM "linux"
#endif
#endif
#define MICROPY_PY_SYS_MAXSIZE (1)
#define MICROPY_PY_SYS_STDFILES (1)
#define MICROPY_PY_SYS_EXC_INFO (1)
Expand Down Expand Up @@ -331,3 +343,5 @@ void mp_unix_mark_exec(void);
// For debugging purposes, make printf() available to any source file.
#include <stdio.h>
#endif

#endif // MICROPY_UNIX_MINIMAL
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
* THE SOFTWARE.
*/

// Default unix config while intended to be comprehensive, may still not enable
// all the features, this config should enable more (testable) options.
// This config enables almost all possible features such that it can be used
// for coverage testing.

#define MICROPY_VFS (1)
#define MICROPY_PY_UOS_VFS (1)

#include <mpconfigport.h>

#define MICROPY_OPT_MATH_FACTORIAL (1)
#define MICROPY_FLOAT_HIGH_QUALITY_HASH (1)
#define MICROPY_ENABLE_SCHEDULER (1)
Expand Down
17 changes: 17 additions & 0 deletions ports/unix/variants/coverage/mpconfigvariant.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PROG ?= micropython-coverage

COPT = -O0

CFLAGS_EXTRA += \
-fprofile-arcs -ftest-coverage \
-Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wsign-compare \
-Wold-style-definition -Wpointer-arith -Wshadow -Wuninitialized -Wunused-parameter \
-DMICROPY_UNIX_COVERAGE

LDFLAGS_EXTRA += -fprofile-arcs -ftest-coverage

FROZEN_MANIFEST = manifest_coverage.py

MICROPY_VFS_FAT = 1
MICROPY_VFS_LFS1 = 1
MICROPY_VFS_LFS2 = 1
27 changes: 27 additions & 0 deletions ports/unix/variants/dev/mpconfigvariant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Damien P. George
*
* 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.
*/

#define MICROPY_PY_SYS_SETTRACE (1)
1 change: 1 addition & 0 deletions ports/unix/variants/dev/mpconfigvariant.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROG ?= micropython-dev
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
// synthetic benchmarking, at the expense of features supported and memory
// usage. This config is not intended to be used in production.

#include <mpconfigport.h>
#define MICROPY_PY___FILE__ (0)
// 91 is a magic number proposed by @dpgeorge, which make pystone run ~ at tie
// with CPython 3.4.
#define MICROPY_MODULE_DICT_SIZE (91)

#include "variants/DEV/mpconfigvariant.h"
7 changes: 7 additions & 0 deletions ports/unix/variants/fast/mpconfigvariant.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# build synthetically fast interpreter for benchmarking

COPT = "-O2 -DNDEBUG -fno-crossjumping"

PROG = micropython-fast

FROZEN_MANIFEST =
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

// options to control how MicroPython is built

#include <mpconfigport.h>
#define MICROPY_PY_USELECT_POSIX (0)

#undef MICROPY_STREAMS_NON_BLOCK
#define MICROPY_STREAMS_NON_BLOCK (0)

#undef MICROPY_PY_SYS_PLATFORM
#define MICROPY_PY_SYS_PLATFORM "freedos"

// djgpp dirent struct does not have d_ino field
#undef _DIRENT_HAVE_D_INO

#define MICROPY_USE_INTERNAL_ERRNO (1)

#include "variants/DEV/mpconfigvariant.h"
20 changes: 20 additions & 0 deletions ports/unix/variants/freedos/mpconfigvariant.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CC = i586-pc-msdosdjgpp-gcc

STRIP = i586-pc-msdosdjgpp-strip

SIZE = i586-pc-msdosdjgpp-size

CFLAGS_EXTRA = \
-DMICROPY_NLR_SETJMP \
-Dtgamma=gamma \
-DMICROPY_EMIT_X86=0 \
-DMICROPY_NO_ALLOCA=1 \

PROG = micropython-freedos

MICROPY_PY_SOCKET = 0
MICROPY_PY_FFI = 0
MICROPY_PY_JNI = 0
MICROPY_PY_BTREE = 0
MICROPY_PY_THREAD = 0
MICROPY_PY_USSL = 0
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

// options to control how MicroPython is built

// Prevent the rest of the default mpconfigport.h being used.
#define MICROPY_UNIX_MINIMAL (1)

#define MICROPY_ALLOC_QSTR_CHUNK_INIT (64)
#define MICROPY_ALLOC_PARSE_RULE_INIT (8)
#define MICROPY_ALLOC_PARSE_RULE_INC (8)
Expand Down
14 changes: 14 additions & 0 deletions ports/unix/variants/minimal/mpconfigvariant.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# build a minimal interpreter
COPT = -Os -DNDEBUG

PROG = micropython-minimal

FROZEN_MANIFEST =

MICROPY_PY_BTREE = 0
MICROPY_PY_FFI = 0
MICROPY_PY_SOCKET = 0
MICROPY_PY_THREAD = 0
MICROPY_PY_TERMIOS = 0
MICROPY_PY_USSL = 0
MICROPY_USE_READLINE = 0
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
* THE SOFTWARE.
*/

// This config is mostly used to ensure that the nan-boxing object model
// continues to build (i.e. catches usage of mp_obj_t that don't work with
// this representation).

// select nan-boxing object model
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_D)

Expand All @@ -39,5 +43,3 @@ typedef int64_t mp_int_t;
typedef uint64_t mp_uint_t;
#define UINT_FMT "%llu"
#define INT_FMT "%lld"

#include <mpconfigport.h>
Loading