Skip to content

Commit 50fcb01

Browse files
committed
ci: build binaries for all platforms
1 parent d23b9c8 commit 50fcb01

File tree

4 files changed

+157
-42
lines changed

4 files changed

+157
-42
lines changed

.travis.yml

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,77 @@
1-
language: cpp
2-
addons:
3-
apt:
4-
sources:
5-
- ubuntu-toolchain-r-test
6-
packages:
7-
- g++-4.8
1+
language: c
2+
sudo: required
3+
services:
4+
- docker
5+
6+
matrix:
7+
include:
8+
- env:
9+
- TARGET_OS=linux64
10+
- DOCKER_IMAGE=multiarch/crossbuild
11+
- CROSS_TRIPLE=x86_64-linux-gnu
12+
- BUILD_DIR=/workdir
13+
- env:
14+
- TARGET_OS=linux32
15+
# multiarch/crossbuild doesn't come with 32-bit compilers, use a different image
16+
- DOCKER_IMAGE=dockcross/linux-x86
17+
- CROSS_TRIPLE=i686-linux-gnu
18+
- BUILD_DIR=/work
19+
- env:
20+
- TARGET_OS=linux-armhf
21+
- DOCKER_IMAGE=multiarch/crossbuild
22+
- CROSS_TRIPLE=arm-linux-gnueabihf
23+
- BUILD_DIR=/workdir
24+
- EXTRA_ARGS="-e SKIP_TESTS=1"
25+
- env:
26+
- TARGET_OS=win32
27+
- DOCKER_IMAGE=multiarch/crossbuild
28+
- CROSS_TRIPLE=i686-w64-mingw32
29+
- BUILD_DIR=/workdir
30+
# multiarch/crossbuild doesn't come with 'zip',
31+
# so we build a tgz archive in the container, and re-package it later in the script.
32+
- EXTRA_ARGS='-e ARCHIVE=tar -e SKIP_TESTS=1'
33+
- env:
34+
- TARGET_OS=osx
35+
- DOCKER_IMAGE=multiarch/crossbuild
36+
- CROSS_TRIPLE=x86_64-apple-darwin
37+
- BUILD_DIR=/workdir
38+
- EXTRA_ARGS="-e SKIP_TESTS=1 -e CXX=c++"
39+
40+
841
script:
9-
- git submodule update --init --recursive
10-
- export CXX="g++-4.8" CC="gcc-4.8"
11-
# Build default configuration
12-
- make dist
13-
# Build configuration with SPIFFS_USE_MAGIC_LENGTH=0 (legacy version)
14-
- make clean
15-
- make dist BUILD_CONFIG_NAME="-no_magic_length" CPPFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0 -DSPIFFS_ALIGNED_OBJECT_INDEX_TABLES=1"
42+
- export VER=$(git describe)
43+
- echo ${VER}
44+
45+
- >-
46+
docker run --rm
47+
-v ${PWD}:${BUILD_DIR}
48+
-e TARGET_OS=${TARGET_OS}
49+
-e CROSS_TRIPLE=${CROSS_TRIPLE}
50+
${EXTRA_ARGS}
51+
${DOCKER_IMAGE}
52+
./build_all_configs.sh
53+
54+
# Diagnostics
55+
- ls -l
56+
57+
# for windows, prepare zip archives
58+
- |
59+
if [ $TARGET_OS = "win32" ]; then
60+
for dirname in $(ls -d mkspiffs-*/); do
61+
name=${dirname%/}
62+
zip -r $name.zip $dirname
63+
rm -f $name.tar.gz
64+
done
65+
fi
66+
67+
# Prepare files with sizes and sha256 hashes
68+
- |
69+
for name in $(ls -1 mkspiffs-*-${TARGET_OS}.*); do
70+
DIST_SIZE=$(wc -c <${name} 2>/dev/null | tr -d ' ')
71+
DIST_SHA256=$(shasum -a 256 ${name} | cut -d ' ' -f1)
72+
echo ${name} ${DIST_SIZE} ${DIST_SHA256}
73+
echo ${name} ${DIST_SIZE} ${DIST_SHA256} >${name}.sha256.txt
74+
done
1675
1776
notifications:
1877
email:
@@ -26,7 +85,7 @@ deploy:
2685
api_key:
2786
secure: "AdgaAHsU3xkyKqcZu6Yp3njmWTXFm/Ggsq9n6cC9byHTDdcQ6UqdX1gPzud53YkSDbUjst5vok0i9xywH2pFWVt6G+FAD5uI/h1IiacQQ9rjnDef++nz+KkZtsPUhAD8LOdKPvJ7TmNNnkN35VFqyQETr/18bdzGC0tEZQK2BFQQrdz6cOGeez1ADYal0LAVHHcfolnwZb9jCT51nPEpSMlhxwSNNFncG2Y8MLDT2Q1y0xR3iI6aSSkMxqWCYYIdEC12rffwyRbC2P+JXp+AXNayLuKjCFnWB/QIyvrvoXtwbAEfW1pZzrWZAI5fI6zQaKKjixhf3Kr1f7y/xSPSdsPemdakRgANRTZW0R6wiXxUsTEjVGV6fWqUKT9pm335k8vWq2i+6exSrIVmYyxz4J3u6+Mgdbij5hI1NLVLq+It0KUVt99IOWaTOy01y6a0m1AprYYPgyw7fwlgChMPsLcaRrq1gtjtJr7wQKLaIlfYdEB4b0DtE/fx+b78mMQqXS/WvwSUGkJ5C2poLX2zdUxFe3phjeL3P0Daa0gLDQ2tCf/VmvPy20//b7MaO10URoeeV16fs+2BFzLjh38kzLRrPaRcBcwQFlzI1P+4mWPRDMuKvBn6i0sodFEzlUQMFSa8xyVtE5wIDLqepeG/9roW8woKIAmwG1k1YtM3XeE="
2887
file_glob: true
29-
file: mkspiffs-$TRAVIS_TAG-*linux64.tar.gz
88+
file: mkspiffs-*-$TARGET_OS.*
3089
on:
3190
repo: igrr/mkspiffs
3291
tags: true

Makefile

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,58 @@
1+
# OS detection. Not used in CI builds
2+
ifndef TARGET_OS
13
ifeq ($(OS),Windows_NT)
2-
TARGET_OS := WINDOWS
3-
DIST_SUFFIX := windows
4-
ARCHIVE_CMD := 7z a
5-
ARCHIVE_EXTENSION := zip
6-
TARGET := mkspiffs.exe
7-
TARGET_CFLAGS := -mno-ms-bitfields
8-
TARGET_LDFLAGS := -Wl,-static -static-libgcc
9-
CC=gcc
10-
CXX=g++
4+
TARGET_OS := win32
115
else
126
UNAME_S := $(shell uname -s)
137
ifeq ($(UNAME_S),Linux)
14-
TARGET_OS := LINUX
15-
UNAME_P := $(shell uname -p)
16-
ifeq ($(UNAME_P),x86_64)
17-
DIST_SUFFIX ?= linux64
8+
UNAME_M := $(shell uname -m)
9+
ifeq ($(UNAME_M),x86_64)
10+
TARGET_OS := linux64
11+
endif
12+
ifeq ($(UNAME_M),i686)
13+
TARGET_OS := linux32
1814
endif
19-
ifneq ($(filter %86,$(UNAME_P)),)
20-
DIST_SUFFIX ?= linux32
15+
ifeq ($(UNAME_M),armv6l)
16+
TARGET_OS := linux-armhf
2117
endif
2218
endif
2319
ifeq ($(UNAME_S),Darwin)
24-
TARGET_OS := OSX
25-
DIST_SUFFIX := osx
26-
CC=clang
27-
CXX=clang++
28-
TARGET_CFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64
29-
TARGET_CXXFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64 -stdlib=libc++
30-
TARGET_LDFLAGS = -arch i386 -arch x86_64 -stdlib=libc++
20+
TARGET_OS := osx
3121
endif
22+
ifeq ($(UNAME_S),FreeBSD)
23+
TARGET_OS := freebsd
24+
endif
25+
endif
26+
endif # TARGET_OS
27+
28+
# OS-specific settings and build flags
29+
ifeq ($(TARGET_OS),win32)
30+
ARCHIVE ?= zip
31+
TARGET := mkspiffs.exe
32+
TARGET_CFLAGS = -mno-ms-bitfields
33+
TARGET_LDFLAGS = -Wl,-static -static-libgcc -static-libstdc++
34+
else
35+
ARCHIVE ?= tar
36+
TARGET := mkspiffs
37+
endif
38+
39+
ifeq ($(TARGET_OS),osx)
40+
TARGET_CFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64
41+
TARGET_CXXFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64 -stdlib=libc++
42+
TARGET_LDFLAGS = -mmacosx-version-min=10.7 -arch i386 -arch x86_64 -stdlib=libc++
43+
endif
44+
45+
# Packaging into archive (for 'dist' target)
46+
ifeq ($(ARCHIVE), zip)
47+
ARCHIVE_CMD := zip -r
48+
ARCHIVE_EXTENSION := zip
49+
endif
50+
ifeq ($(ARCHIVE), tar)
3251
ARCHIVE_CMD := tar czf
3352
ARCHIVE_EXTENSION := tar.gz
34-
TARGET := mkspiffs
3553
endif
3654

55+
3756
VERSION ?= $(shell git describe --always)
3857
SPIFFS_VERSION := $(shell git -C spiffs describe --tags || echo "unknown")
3958
BUILD_CONFIG_NAME ?= -generic
@@ -47,12 +66,14 @@ OBJ := main.o \
4766

4867
INCLUDES := -Itclap -Iinclude -Ispiffs/src -I.
4968

69+
# clang doesn't seem to handle -D "ARG=\"foo bar\"" correctly, so replace spaces with \x20:
70+
BUILD_CONFIG_STR := $(shell echo $(CPPFLAGS) | sed 's- -\\\\x20-')
71+
5072
override CPPFLAGS := \
5173
$(INCLUDES) \
52-
-D $(TARGET_OS) \
5374
-D VERSION=\"$(VERSION)\" \
5475
-D SPIFFS_VERSION=\"$(SPIFFS_VERSION)\" \
55-
-D "BUILD_CONFIG=\"$(CPPFLAGS)\"" \
76+
-D BUILD_CONFIG=\"$(BUILD_CONFIG_STR)\" \
5677
-D BUILD_CONFIG_NAME=\"$(BUILD_CONFIG_NAME)\" \
5778
-D __NO_INLINE__ \
5879
$(CPPFLAGS)
@@ -61,15 +82,19 @@ override CFLAGS := -std=gnu99 -Os -Wall $(TARGET_CFLAGS) $(CFLAGS)
6182
override CXXFLAGS := -std=gnu++11 -Os -Wall $(TARGET_CXXFLAGS) $(CXXFLAGS)
6283
override LDFLAGS := $(TARGET_LDFLAGS) $(LDFLAGS)
6384

64-
DIST_NAME := mkspiffs-$(VERSION)$(BUILD_CONFIG_NAME)-$(DIST_SUFFIX)
85+
DIST_NAME := mkspiffs-$(VERSION)$(BUILD_CONFIG_NAME)-$(TARGET_OS)
6586
DIST_DIR := $(DIST_NAME)
6687
DIST_ARCHIVE := $(DIST_NAME).$(ARCHIVE_EXTENSION)
6788

6889
.PHONY: all clean dist
6990

7091
all: $(TARGET)
7192

72-
dist: test $(DIST_ARCHIVE)
93+
dist: $(DIST_ARCHIVE)
94+
95+
ifndef SKIP_TESTS
96+
dist: test
97+
endif
7398

7499
$(DIST_ARCHIVE): $(TARGET) $(DIST_DIR)
75100
cp $(TARGET) $(DIST_DIR)/

build_all_configs.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
#
3+
# Script used in CI to build all configurations of mkspiffs
4+
#
5+
6+
set -e
7+
8+
# Generic (default options)
9+
make dist
10+
11+
# Arduino ESP8266
12+
make clean
13+
make dist BUILD_CONFIG_NAME="-arduino-esp8266" \
14+
CPPFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0 -DSPIFFS_ALIGNED_OBJECT_INDEX_TABLES=1"
15+
16+
# Build configuration for arduino-esp32
17+
make clean
18+
make dist BUILD_CONFIG_NAME="-arduino-esp32" \
19+
CFLAGS="-DSPIFFS_OBJ_META_LEN=4"
20+
21+
# Build configuration for ESP-IDF (esp32)
22+
make clean
23+
make dist BUILD_CONFIG_NAME="-esp-idf" \
24+
CFLAGS="-DSPIFFS_OBJ_META_LEN=4"
25+
26+
27+

main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include "tclap/CmdLine.h"
2222
#include "tclap/UnlabeledValueArg.h"
2323

24+
#ifdef _WIN32
25+
#include <direct.h>
26+
#endif
27+
2428
static std::vector<uint8_t> s_flashmem;
2529

2630
static std::string s_dirName;

0 commit comments

Comments
 (0)