diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b13b6e4219..4d11739a55 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,8 @@ jobs: python-version: 3.5 - name: Install deps run: | - sudo apt-get install -y gettext librsvg2-bin + sudo apt-get install -y eatmydata + sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64 pip install requests sh click setuptools cpp-coveralls Sphinx sphinx-rtd-theme recommonmark sphinxcontrib-svg2pdfconverter polib pyyaml - name: Versions run: | @@ -66,6 +67,54 @@ jobs: run: python3 -u ci_new_boards_check.py working-directory: tools + - name: Build mpy-cross.static-raspbian + run: make -C mpy-cross -j2 -f Makefile.static-raspbian + - uses: actions/upload-artifact@v1.0.0 + with: + name: mpy-cross.static-raspbian + path: mpy-cross/mpy-cross.static-raspbian + + - name: Build mpy-cross.static + run: make -C mpy-cross -j2 -f Makefile.static + - uses: actions/upload-artifact@v1.0.0 + with: + name: mpy-cross.static-amd64-linux + path: mpy-cross/mpy-cross.static + + - name: Build mpy-cross.static-mingw + run: make -C mpy-cross -j2 -f Makefile.static-mingw + - uses: actions/upload-artifact@v1.0.0 + with: + name: mpy-cross.static-x64-windows + path: mpy-cross/mpy-cross.static.exe + + mpy-cross-mac: + runs-on: macos-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Install deps + run: | + brew link --force gettext + - name: Versions + run: | + gcc --version + python3 --version + msgfmt --version + - uses: actions/checkout@v1 + with: + submodules: true + - name: CircuitPython version + run: git describe --dirty --always --tags + - name: Build mpy-cross + run: make -C mpy-cross -j2 + - uses: actions/upload-artifact@v1.0.0 + with: + name: mpy-cross-macos-catalina + path: mpy-cross/mpy-cross + build-arm: runs-on: ubuntu-16.04 needs: test diff --git a/mpy-cross/.gitignore b/mpy-cross/.gitignore index 82a0a7efaa..0681b685fa 100644 --- a/mpy-cross/.gitignore +++ b/mpy-cross/.gitignore @@ -1 +1,6 @@ -mpy-cross +/build-* +/mpy-cross +/mpy-cross.static +/mpy-cross.static.exe +/mpy-cross.static-raspbian +/pitools diff --git a/mpy-cross/Makefile b/mpy-cross/Makefile index 42dbace984..072304faa0 100644 --- a/mpy-cross/Makefile +++ b/mpy-cross/Makefile @@ -11,84 +11,4 @@ override undefine BUILD override undefine PROG endif -include ../py/mkenv.mk - -# define main target - -ifeq ($(OS),Windows_NT) -# Detect a MINGW32 build, and change the name of the final executable. -PROG = mpy-cross.exe -else -PROG = mpy-cross -endif - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# OS name, for simple autoconfig -UNAME_S := $(shell uname -s) - -# include py core make definitions -include $(TOP)/py/py.mk - -INC += -I. -INC += -I$(TOP) -INC += -I$(BUILD) - -# compiler settings -CWARN = -Wall -Werror -CWARN += -Wpointer-arith -Wuninitialized -CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) -CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables - -# Build a static executable. -# Useful for Windows builds, etc., that must run on multiple operating system versions. -ifdef STATIC_BUILD -CFLAGS += -static -static-libgcc -static-libstdc++ -endif - - -# Debugging/Optimization -ifdef DEBUG -CFLAGS += -g -COPT = -O0 -else -COPT = -Os #-DNDEBUG -endif - -# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed. -# The unix port of MicroPython on OSX must be compiled with clang, -# while cross-compile ports require gcc, so we test here for OSX and -# if necessary override the value of 'CC' set in py/mkenv.mk -ifeq ($(UNAME_S),Darwin) -CC = clang -# Use clang syntax for map file -LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip -else -# Use gcc syntax for map file -LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections -endif -LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA) - -ifdef STATIC_BUILD -LDFLAGS += -static -static-libgcc -static-libstdc++ -endif - -# source files -SRC_C = \ - main.c \ - gccollect.c \ - supervisor/stub/safe_mode.c \ - supervisor/stub/stack.c \ - supervisor/shared/translate.c - -# Add fmode when compiling with mingw gcc -COMPILER_TARGET := $(shell $(CC) -dumpmachine) -ifneq (,$(findstring mingw,$(COMPILER_TARGET))) - SRC_C += ports/windows/fmode.c -endif - -OBJ = $(PY_O) -OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) - -include $(TOP)/py/mkrules.mk +include mpy-cross.mk diff --git a/mpy-cross/Makefile.static b/mpy-cross/Makefile.static new file mode 100644 index 0000000000..ca0925f758 --- /dev/null +++ b/mpy-cross/Makefile.static @@ -0,0 +1,5 @@ +PROG=mpy-cross.static +BUILD=build-static +STATIC_BUILD=1 + +include mpy-cross.mk diff --git a/mpy-cross/Makefile.static-mingw b/mpy-cross/Makefile.static-mingw new file mode 100644 index 0000000000..a176e80e6e --- /dev/null +++ b/mpy-cross/Makefile.static-mingw @@ -0,0 +1,6 @@ +PROG=mpy-cross.static.exe +CROSS_COMPILE = x86_64-w64-mingw32- +BUILD=build-static-mingw +STATIC_BUILD=1 + +include mpy-cross.mk diff --git a/mpy-cross/Makefile.static-raspbian b/mpy-cross/Makefile.static-raspbian new file mode 100644 index 0000000000..9129f555e7 --- /dev/null +++ b/mpy-cross/Makefile.static-raspbian @@ -0,0 +1,8 @@ +PROG=mpy-cross.static-raspbian +BUILD=build-static-raspbian +STATIC_BUILD=1 + +CROSS_COMPILE = pitools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- +include mpy-cross.mk + +$(shell [ -d pitools ] || git clone --progress --verbose https://github.com/raspberrypi/tools.git --depth=1 pitools) diff --git a/mpy-cross/fmode.c b/mpy-cross/fmode.c new file mode 100644 index 0000000000..33ba24ed1f --- /dev/null +++ b/mpy-cross/fmode.c @@ -0,0 +1,49 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2016 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. + */ + +#include "fmode.h" +#include "py/mpconfig.h" +#include +#include + +// Workaround for setting file translation mode: we must distinguish toolsets +// since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect +STATIC int set_fmode_impl(int mode) { +#ifndef _MSC_VER + _fmode = mode; + return 0; +#else + return _set_fmode(mode); +#endif +} + +void set_fmode_binary(void) { + set_fmode_impl(O_BINARY); +} + +void set_fmode_text(void) { + set_fmode_impl(O_TEXT); +} diff --git a/mpy-cross/fmode.h b/mpy-cross/fmode.h new file mode 100644 index 0000000000..c661c84d0c --- /dev/null +++ b/mpy-cross/fmode.h @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013-2016 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. + */ +#ifndef MICROPY_INCLUDED_WINDOWS_FMODE_H +#define MICROPY_INCLUDED_WINDOWS_FMODE_H + +// Treat files opened by open() as binary. No line ending translation is done. +void set_fmode_binary(void); + +// Treat files opened by open() as text. +// When reading from the file \r\n will be converted to \n. +// When writing to the file \n will be converted into \r\n. +void set_fmode_text(void); + +#endif // MICROPY_INCLUDED_WINDOWS_FMODE_H diff --git a/mpy-cross/main.c b/mpy-cross/main.c index d819f74f12..7c232385b8 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -35,7 +35,7 @@ #include "py/gc.h" #include "py/stackctrl.h" #ifdef _WIN32 -#include "ports/windows/fmode.h" +#include "fmode.h" #endif // Command line options, with their defaults @@ -284,3 +284,7 @@ void nlr_jump_fail(void *val) { printf("FATAL: uncaught NLR %p\n", val); exit(1); } + +void serial_write(const char* text) { + printf("%s", text); +} diff --git a/mpy-cross/mpy-cross.mk b/mpy-cross/mpy-cross.mk new file mode 100644 index 0000000000..de96305cbf --- /dev/null +++ b/mpy-cross/mpy-cross.mk @@ -0,0 +1,81 @@ +include ../py/mkenv.mk + +# define main target + +ifeq ($(OS),Windows_NT) +# Detect a MINGW32 build, and change the name of the final executable. +PROG ?= mpy-cross.exe +else +PROG ?= mpy-cross +endif + +# qstr definitions (must come before including py.mk) +QSTR_DEFS = qstrdefsport.h + +# OS name, for simple autoconfig +UNAME_S := $(shell uname -s) + +# include py core make definitions +include $(TOP)/py/py.mk + +INC += -I. +INC += -I$(TOP) +INC += -I$(BUILD) + +# compiler settings +CWARN = -Wall -Werror +CWARN += -Wpointer-arith -Wuninitialized +CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) +CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables + +# Build a static executable. +# Useful for Windows builds, etc., that must run on multiple operating system versions. +ifdef STATIC_BUILD +CFLAGS += -static -static-libgcc -static-libstdc++ +endif + + +# Debugging/Optimization +ifdef DEBUG +CFLAGS += -g +COPT = -O0 +else +COPT = -Os #-DNDEBUG +endif + +# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed. +# The unix port of MicroPython on OSX must be compiled with clang, +# while cross-compile ports require gcc, so we test here for OSX and +# if necessary override the value of 'CC' set in py/mkenv.mk +ifeq ($(UNAME_S),Darwin) +CC = clang +# Use clang syntax for map file +LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip +else +# Use gcc syntax for map file +LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections +endif +LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA) + +ifdef STATIC_BUILD +LDFLAGS += -static -static-libgcc -static-libstdc++ +endif + +# source files +SRC_C = \ + main.c \ + gccollect.c \ + supervisor/stub/safe_mode.c \ + supervisor/stub/stack.c \ + supervisor/shared/translate.c + +# Add fmode when compiling with mingw gcc +COMPILER_TARGET := $(shell $(CC) -dumpmachine) +ifneq (,$(findstring mingw,$(COMPILER_TARGET))) + SRC_C += fmode.c +endif + +OBJ = $(PY_O) +OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) + +include $(TOP)/py/mkrules.mk diff --git a/py/sequence.c b/py/sequence.c index a750e5bac4..0e668ea2a1 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -34,6 +34,11 @@ #define SWAP(type, var1, var2) { type t = var2; var2 = var1; var1 = t; } +#if __GNUC__ < 5 +// n.b. does not actually detect overflow! +#define __builtin_mul_overflow(a, b, x) (*(x) = (a) * (b), false) +#endif + // Detect when a multiply causes an overflow. size_t mp_seq_multiply_len(size_t item_sz, size_t len) { size_t new_len;