Skip to content

Commit 5b6b4eb

Browse files
authored
Merge pull request #2551 from jepler/build-mpy-cross-static-linux-win64
Build static binaries of mpy-cross for desktop linux, desktop windows, mac, and raspbian
2 parents 7d4f9fc + 0b7551f commit 5b6b4eb

File tree

11 files changed

+253
-84
lines changed

11 files changed

+253
-84
lines changed

.github/workflows/build.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ jobs:
2222
python-version: 3.5
2323
- name: Install deps
2424
run: |
25-
sudo apt-get install -y gettext librsvg2-bin
25+
sudo apt-get install -y eatmydata
26+
sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64
2627
pip install requests sh click setuptools cpp-coveralls Sphinx sphinx-rtd-theme recommonmark sphinxcontrib-svg2pdfconverter polib pyyaml
2728
- name: Versions
2829
run: |
@@ -66,6 +67,54 @@ jobs:
6667
run: python3 -u ci_new_boards_check.py
6768
working-directory: tools
6869

70+
- name: Build mpy-cross.static-raspbian
71+
run: make -C mpy-cross -j2 -f Makefile.static-raspbian
72+
- uses: actions/[email protected]
73+
with:
74+
name: mpy-cross.static-raspbian
75+
path: mpy-cross/mpy-cross.static-raspbian
76+
77+
- name: Build mpy-cross.static
78+
run: make -C mpy-cross -j2 -f Makefile.static
79+
- uses: actions/[email protected]
80+
with:
81+
name: mpy-cross.static-amd64-linux
82+
path: mpy-cross/mpy-cross.static
83+
84+
- name: Build mpy-cross.static-mingw
85+
run: make -C mpy-cross -j2 -f Makefile.static-mingw
86+
- uses: actions/[email protected]
87+
with:
88+
name: mpy-cross.static-x64-windows
89+
path: mpy-cross/mpy-cross.static.exe
90+
91+
mpy-cross-mac:
92+
runs-on: macos-latest
93+
steps:
94+
- name: Dump GitHub context
95+
env:
96+
GITHUB_CONTEXT: ${{ toJson(github) }}
97+
run: echo "$GITHUB_CONTEXT"
98+
- name: Install deps
99+
run: |
100+
brew link --force gettext
101+
- name: Versions
102+
run: |
103+
gcc --version
104+
python3 --version
105+
msgfmt --version
106+
- uses: actions/checkout@v1
107+
with:
108+
submodules: true
109+
- name: CircuitPython version
110+
run: git describe --dirty --always --tags
111+
- name: Build mpy-cross
112+
run: make -C mpy-cross -j2
113+
- uses: actions/[email protected]
114+
with:
115+
name: mpy-cross-macos-catalina
116+
path: mpy-cross/mpy-cross
117+
69118
build-arm:
70119
runs-on: ubuntu-16.04
71120
needs: test

mpy-cross/.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
mpy-cross
1+
/build-*
2+
/mpy-cross
3+
/mpy-cross.static
4+
/mpy-cross.static.exe
5+
/mpy-cross.static-raspbian
6+
/pitools

mpy-cross/Makefile

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -11,84 +11,4 @@ override undefine BUILD
1111
override undefine PROG
1212
endif
1313

14-
include ../py/mkenv.mk
15-
16-
# define main target
17-
18-
ifeq ($(OS),Windows_NT)
19-
# Detect a MINGW32 build, and change the name of the final executable.
20-
PROG = mpy-cross.exe
21-
else
22-
PROG = mpy-cross
23-
endif
24-
25-
# qstr definitions (must come before including py.mk)
26-
QSTR_DEFS = qstrdefsport.h
27-
28-
# OS name, for simple autoconfig
29-
UNAME_S := $(shell uname -s)
30-
31-
# include py core make definitions
32-
include $(TOP)/py/py.mk
33-
34-
INC += -I.
35-
INC += -I$(TOP)
36-
INC += -I$(BUILD)
37-
38-
# compiler settings
39-
CWARN = -Wall -Werror
40-
CWARN += -Wpointer-arith -Wuninitialized
41-
CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
42-
CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables
43-
44-
# Build a static executable.
45-
# Useful for Windows builds, etc., that must run on multiple operating system versions.
46-
ifdef STATIC_BUILD
47-
CFLAGS += -static -static-libgcc -static-libstdc++
48-
endif
49-
50-
51-
# Debugging/Optimization
52-
ifdef DEBUG
53-
CFLAGS += -g
54-
COPT = -O0
55-
else
56-
COPT = -Os #-DNDEBUG
57-
endif
58-
59-
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
60-
# The unix port of MicroPython on OSX must be compiled with clang,
61-
# while cross-compile ports require gcc, so we test here for OSX and
62-
# if necessary override the value of 'CC' set in py/mkenv.mk
63-
ifeq ($(UNAME_S),Darwin)
64-
CC = clang
65-
# Use clang syntax for map file
66-
LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
67-
else
68-
# Use gcc syntax for map file
69-
LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections
70-
endif
71-
LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
72-
73-
ifdef STATIC_BUILD
74-
LDFLAGS += -static -static-libgcc -static-libstdc++
75-
endif
76-
77-
# source files
78-
SRC_C = \
79-
main.c \
80-
gccollect.c \
81-
supervisor/stub/safe_mode.c \
82-
supervisor/stub/stack.c \
83-
supervisor/shared/translate.c
84-
85-
# Add fmode when compiling with mingw gcc
86-
COMPILER_TARGET := $(shell $(CC) -dumpmachine)
87-
ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
88-
SRC_C += ports/windows/fmode.c
89-
endif
90-
91-
OBJ = $(PY_O)
92-
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
93-
94-
include $(TOP)/py/mkrules.mk
14+
include mpy-cross.mk

mpy-cross/Makefile.static

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PROG=mpy-cross.static
2+
BUILD=build-static
3+
STATIC_BUILD=1
4+
5+
include mpy-cross.mk

mpy-cross/Makefile.static-mingw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PROG=mpy-cross.static.exe
2+
CROSS_COMPILE = x86_64-w64-mingw32-
3+
BUILD=build-static-mingw
4+
STATIC_BUILD=1
5+
6+
include mpy-cross.mk

mpy-cross/Makefile.static-raspbian

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PROG=mpy-cross.static-raspbian
2+
BUILD=build-static-raspbian
3+
STATIC_BUILD=1
4+
5+
CROSS_COMPILE = pitools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-
6+
include mpy-cross.mk
7+
8+
$(shell [ -d pitools ] || git clone --progress --verbose https://github.com/raspberrypi/tools.git --depth=1 pitools)

mpy-cross/fmode.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-2016 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "fmode.h"
28+
#include "py/mpconfig.h"
29+
#include <fcntl.h>
30+
#include <stdlib.h>
31+
32+
// Workaround for setting file translation mode: we must distinguish toolsets
33+
// since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect
34+
STATIC int set_fmode_impl(int mode) {
35+
#ifndef _MSC_VER
36+
_fmode = mode;
37+
return 0;
38+
#else
39+
return _set_fmode(mode);
40+
#endif
41+
}
42+
43+
void set_fmode_binary(void) {
44+
set_fmode_impl(O_BINARY);
45+
}
46+
47+
void set_fmode_text(void) {
48+
set_fmode_impl(O_TEXT);
49+
}

mpy-cross/fmode.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-2016 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#ifndef MICROPY_INCLUDED_WINDOWS_FMODE_H
27+
#define MICROPY_INCLUDED_WINDOWS_FMODE_H
28+
29+
// Treat files opened by open() as binary. No line ending translation is done.
30+
void set_fmode_binary(void);
31+
32+
// Treat files opened by open() as text.
33+
// When reading from the file \r\n will be converted to \n.
34+
// When writing to the file \n will be converted into \r\n.
35+
void set_fmode_text(void);
36+
37+
#endif // MICROPY_INCLUDED_WINDOWS_FMODE_H

mpy-cross/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "py/gc.h"
3636
#include "py/stackctrl.h"
3737
#ifdef _WIN32
38-
#include "ports/windows/fmode.h"
38+
#include "fmode.h"
3939
#endif
4040

4141
// Command line options, with their defaults
@@ -284,3 +284,7 @@ void nlr_jump_fail(void *val) {
284284
printf("FATAL: uncaught NLR %p\n", val);
285285
exit(1);
286286
}
287+
288+
void serial_write(const char* text) {
289+
printf("%s", text);
290+
}

mpy-cross/mpy-cross.mk

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
include ../py/mkenv.mk
2+
3+
# define main target
4+
5+
ifeq ($(OS),Windows_NT)
6+
# Detect a MINGW32 build, and change the name of the final executable.
7+
PROG ?= mpy-cross.exe
8+
else
9+
PROG ?= mpy-cross
10+
endif
11+
12+
# qstr definitions (must come before including py.mk)
13+
QSTR_DEFS = qstrdefsport.h
14+
15+
# OS name, for simple autoconfig
16+
UNAME_S := $(shell uname -s)
17+
18+
# include py core make definitions
19+
include $(TOP)/py/py.mk
20+
21+
INC += -I.
22+
INC += -I$(TOP)
23+
INC += -I$(BUILD)
24+
25+
# compiler settings
26+
CWARN = -Wall -Werror
27+
CWARN += -Wpointer-arith -Wuninitialized
28+
CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
29+
CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables
30+
31+
# Build a static executable.
32+
# Useful for Windows builds, etc., that must run on multiple operating system versions.
33+
ifdef STATIC_BUILD
34+
CFLAGS += -static -static-libgcc -static-libstdc++
35+
endif
36+
37+
38+
# Debugging/Optimization
39+
ifdef DEBUG
40+
CFLAGS += -g
41+
COPT = -O0
42+
else
43+
COPT = -Os #-DNDEBUG
44+
endif
45+
46+
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
47+
# The unix port of MicroPython on OSX must be compiled with clang,
48+
# while cross-compile ports require gcc, so we test here for OSX and
49+
# if necessary override the value of 'CC' set in py/mkenv.mk
50+
ifeq ($(UNAME_S),Darwin)
51+
CC = clang
52+
# Use clang syntax for map file
53+
LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
54+
else
55+
# Use gcc syntax for map file
56+
LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections
57+
endif
58+
LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
59+
60+
ifdef STATIC_BUILD
61+
LDFLAGS += -static -static-libgcc -static-libstdc++
62+
endif
63+
64+
# source files
65+
SRC_C = \
66+
main.c \
67+
gccollect.c \
68+
supervisor/stub/safe_mode.c \
69+
supervisor/stub/stack.c \
70+
supervisor/shared/translate.c
71+
72+
# Add fmode when compiling with mingw gcc
73+
COMPILER_TARGET := $(shell $(CC) -dumpmachine)
74+
ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
75+
SRC_C += fmode.c
76+
endif
77+
78+
OBJ = $(PY_O)
79+
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
80+
81+
include $(TOP)/py/mkrules.mk

py/sequence.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434

3535
#define SWAP(type, var1, var2) { type t = var2; var2 = var1; var1 = t; }
3636

37+
#if __GNUC__ < 5
38+
// n.b. does not actually detect overflow!
39+
#define __builtin_mul_overflow(a, b, x) (*(x) = (a) * (b), false)
40+
#endif
41+
3742
// Detect when a multiply causes an overflow.
3843
size_t mp_seq_multiply_len(size_t item_sz, size_t len) {
3944
size_t new_len;

0 commit comments

Comments
 (0)