Skip to content

Build static binaries of mpy-cross for desktop linux, desktop windows, mac, and raspbian #2551

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 8 commits into from
Jan 29, 2020
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
51 changes: 50 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
with:
name: mpy-cross-macos-catalina
path: mpy-cross/mpy-cross

build-arm:
runs-on: ubuntu-16.04
needs: test
Expand Down
7 changes: 6 additions & 1 deletion mpy-cross/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
mpy-cross
/build-*
/mpy-cross
/mpy-cross.static
/mpy-cross.static.exe
/mpy-cross.static-raspbian
/pitools
82 changes: 1 addition & 81 deletions mpy-cross/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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,[email protected] -Wl,-dead_strip
else
# Use gcc syntax for map file
LDFLAGS_ARCH = -Wl,[email protected],--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
5 changes: 5 additions & 0 deletions mpy-cross/Makefile.static
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PROG=mpy-cross.static
BUILD=build-static
STATIC_BUILD=1

include mpy-cross.mk
6 changes: 6 additions & 0 deletions mpy-cross/Makefile.static-mingw
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions mpy-cross/Makefile.static-raspbian
Original file line number Diff line number Diff line change
@@ -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)
49 changes: 49 additions & 0 deletions mpy-cross/fmode.c
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 (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 <fcntl.h>
#include <stdlib.h>

// 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);
}
37 changes: 37 additions & 0 deletions mpy-cross/fmode.h
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion mpy-cross/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
81 changes: 81 additions & 0 deletions mpy-cross/mpy-cross.mk
Original file line number Diff line number Diff line change
@@ -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,[email protected] -Wl,-dead_strip
else
# Use gcc syntax for map file
LDFLAGS_ARCH = -Wl,[email protected],--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
5 changes: 5 additions & 0 deletions py/sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down