From 488f281ec747883473d73e0890738248ce039b45 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 28 Aug 2017 11:26:36 -0400 Subject: [PATCH] chore: build armhf on GNU/Linux (#1482) This commit makes use of the `resin/armv7hf-debian` Docker image to test and generate armhf builds. We needed to add a slash before `build` in `.gitignore` given that git was refusing to include any changes on `scripts/build` otherwise. Signed-off-by: Juan Cruz Viotti --- Makefile | 132 +++++++++++------------ scripts/build/architecture-convert.sh | 20 +++- scripts/build/docker/Dockerfile-armv7hf | 52 +++++++++ scripts/build/docker/Dockerfile-i686 | 3 + scripts/build/docker/Dockerfile-x86_64 | 3 + scripts/build/docker/Dockerfile.template | 5 + scripts/build/docker/compile-template.js | 4 + scripts/build/docker/run-command.sh | 13 +-- 8 files changed, 152 insertions(+), 80 deletions(-) create mode 100644 scripts/build/docker/Dockerfile-armv7hf diff --git a/Makefile b/Makefile index dfc803f0..c5f78267 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,72 @@ endif BUILD_TEMPORARY_DIRECTORY = $(BUILD_DIRECTORY)/.tmp +# --------------------------------------------------------------------- +# Operating system and architecture detection +# --------------------------------------------------------------------- + +# http://stackoverflow.com/a/12099167 +ifeq ($(OS),Windows_NT) + PLATFORM = win32 + + ifeq ($(PROCESSOR_ARCHITEW6432),AMD64) + HOST_ARCH = x64 + else + ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) + HOST_ARCH = x64 + endif + ifeq ($(PROCESSOR_ARCHITECTURE),x86) + HOST_ARCH = x86 + endif + endif +else + ifeq ($(shell uname -s),Linux) + PLATFORM = linux + + ifeq ($(shell uname -m),x86_64) + HOST_ARCH = x64 + endif + ifneq ($(filter %86,$(shell uname -m)),) + HOST_ARCH = x86 + endif + ifeq ($(shell uname -m),armv7l) + HOST_ARCH = armv7hf + endif + endif + ifeq ($(shell uname -s),Darwin) + PLATFORM = darwin + + ifeq ($(shell uname -m),x86_64) + HOST_ARCH = x64 + endif + endif +endif + +ifndef PLATFORM +$(error We couldn't detect your host platform) +endif +ifndef HOST_ARCH +$(error We couldn't detect your host architecture) +endif + +# Default to host architecture. You can override by doing: +# +# make TARGET_ARCH= +# +TARGET_ARCH ?= $(HOST_ARCH) + +# Support x86 builds from x64 in GNU/Linux +# See https://github.com/addaleax/lzma-native/issues/27 +ifeq ($(PLATFORM),linux) + ifneq ($(HOST_ARCH),$(TARGET_ARCH)) + ifeq ($(TARGET_ARCH),x86) + export CFLAGS += -m32 + else +$(error Can't build $(TARGET_ARCH) binaries on a $(HOST_ARCH) host) + endif + endif +endif + # --------------------------------------------------------------------- # Application configuration # --------------------------------------------------------------------- @@ -71,72 +137,6 @@ ifndef APPLICATION_VERSION $(error Invalid release type: $(RELEASE_TYPE)) endif -# --------------------------------------------------------------------- -# Operating system and architecture detection -# --------------------------------------------------------------------- - -# http://stackoverflow.com/a/12099167 -ifeq ($(OS),Windows_NT) - PLATFORM = win32 - - ifeq ($(PROCESSOR_ARCHITEW6432),AMD64) - HOST_ARCH = x64 - else - ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) - HOST_ARCH = x64 - endif - ifeq ($(PROCESSOR_ARCHITECTURE),x86) - HOST_ARCH = x86 - endif - endif -else - ifeq ($(shell uname -s),Linux) - PLATFORM = linux - - ifeq ($(shell uname -m),x86_64) - HOST_ARCH = x64 - endif - ifneq ($(filter %86,$(shell uname -m)),) - HOST_ARCH = x86 - endif - ifeq ($(shell uname -m),armv7l) - HOST_ARCH = armv7l - endif - endif - ifeq ($(shell uname -s),Darwin) - PLATFORM = darwin - - ifeq ($(shell uname -m),x86_64) - HOST_ARCH = x64 - endif - endif -endif - -ifndef PLATFORM -$(error We couldn't detect your host platform) -endif -ifndef HOST_ARCH -$(error We couldn't detect your host architecture) -endif - -# Default to host architecture. You can override by doing: -# -# make TARGET_ARCH= -# -TARGET_ARCH ?= $(HOST_ARCH) - -# Support x86 builds from x64 in GNU/Linux -# See https://github.com/addaleax/lzma-native/issues/27 -ifeq ($(PLATFORM),linux) - ifneq ($(HOST_ARCH),$(TARGET_ARCH)) - ifeq ($(TARGET_ARCH),x86) - export CFLAGS += -m32 - else -$(error Can't build $(TARGET_ARCH) binaries on a $(HOST_ARCH) host) - endif - endif -endif - # --------------------------------------------------------------------- # Code signing # --------------------------------------------------------------------- diff --git a/scripts/build/architecture-convert.sh b/scripts/build/architecture-convert.sh index 70a4492d..493f62af 100755 --- a/scripts/build/architecture-convert.sh +++ b/scripts/build/architecture-convert.sh @@ -25,7 +25,7 @@ function usage() { echo "Options" echo "" echo " -r " - echo " -t " + echo " -t " exit 1 } @@ -51,7 +51,7 @@ if [ "$ARGV_TYPE" == "node" ]; then RESULT=ia32 elif [ "$ARGV_ARCHITECTURE" == "x64" ]; then RESULT=x64 - elif [ "$ARGV_ARCHITECTURE" == "armv7l" ]; then + elif [ "$ARGV_ARCHITECTURE" == "armv7hf" ]; then RESULT=arm fi elif [ "$ARGV_TYPE" == "electron-builder" ]; then @@ -59,7 +59,7 @@ elif [ "$ARGV_TYPE" == "electron-builder" ]; then RESULT=ia32 elif [ "$ARGV_ARCHITECTURE" == "x64" ]; then RESULT=x64 - elif [ "$ARGV_ARCHITECTURE" == "armv7l" ]; then + elif [ "$ARGV_ARCHITECTURE" == "armv7hf" ]; then RESULT=armv7l fi elif [ "$ARGV_TYPE" == "debian" ]; then @@ -67,7 +67,7 @@ elif [ "$ARGV_TYPE" == "debian" ]; then RESULT=i386 elif [ "$ARGV_ARCHITECTURE" == "x64" ]; then RESULT=amd64 - elif [ "$ARGV_ARCHITECTURE" == "armv7l" ]; then + elif [ "$ARGV_ARCHITECTURE" == "armv7hf" ]; then RESULT=armhf fi elif [ "$ARGV_TYPE" == "redhat" ]; then @@ -75,12 +75,24 @@ elif [ "$ARGV_TYPE" == "redhat" ]; then RESULT=i686 elif [ "$ARGV_ARCHITECTURE" == "x64" ]; then RESULT='x86_64' + elif [ "$ARGV_ARCHITECTURE" == "armv7hf" ]; then + RESULT=armhfp fi elif [ "$ARGV_TYPE" == "appimage" ]; then if [ "$ARGV_ARCHITECTURE" == "x86" ]; then RESULT=i386 elif [ "$ARGV_ARCHITECTURE" == "x64" ]; then RESULT='x86_64' + elif [ "$ARGV_ARCHITECTURE" == "armv7hf" ]; then + RESULT=armhf + fi +elif [ "$ARGV_TYPE" == "docker" ]; then + if [ "$ARGV_ARCHITECTURE" == "x64" ]; then + RESULT=x86_64 + elif [ "$ARGV_ARCHITECTURE" == "x86" ]; then + RESULT=i686 + elif [ "$ARGV_ARCHITECTURE" == "armv7hf" ]; then + RESULT=armv7hf fi else echo "Unsupported architecture type: $ARGV_TYPE" 1>&2 diff --git a/scripts/build/docker/Dockerfile-armv7hf b/scripts/build/docker/Dockerfile-armv7hf new file mode 100644 index 00000000..dc53408c --- /dev/null +++ b/scripts/build/docker/Dockerfile-armv7hf @@ -0,0 +1,52 @@ +FROM resin/armv7hf-debian:jessie + +# Setup APT sources + + + +RUN echo "deb http://ftp.debian.org/debian jessie-backports main" >> /etc/apt/sources.list + + +# Install dependencies +RUN apt-get update \ + && apt-get install -y \ + build-essential \ + curl \ + fuse \ + git \ + graphicsmagick \ + icnsutils \ + jq \ + libasound2 \ + libgconf-2-4 \ + libgtk2.0-0 \ + libx11-xcb1 \ + libnss3 \ + libxss1 \ + libxtst6 \ + libyaml-dev \ + python \ + python-pip \ + python-dev \ + python-software-properties \ + unzip \ + xorriso \ + xvfb \ + xz-utils \ + zip \ + rpm + + + +# NodeJS +RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \ + && apt-get install -y nodejs + +# See https://github.com/mapbox/node-pre-gyp/issues/165 +RUN npm config set unsafe-perm=true + +RUN npm config set spin=false + +# Python +COPY requirements.txt requirements.txt +RUN pip install --quiet -r requirements.txt diff --git a/scripts/build/docker/Dockerfile-i686 b/scripts/build/docker/Dockerfile-i686 index 2aba29a9..8adfc84e 100644 --- a/scripts/build/docker/Dockerfile-i686 +++ b/scripts/build/docker/Dockerfile-i686 @@ -7,6 +7,7 @@ RUN sed s,ubuntu\.stu\.edu\.tw,archive.ubuntu.com, /etc/apt/sources.list > /tmp/ + # Install dependencies RUN apt-get update \ && apt-get install -y \ @@ -36,11 +37,13 @@ RUN apt-get update \ zip \ rpm + # Install a C++11 compiler RUN add-apt-repository ppa:ubuntu-toolchain-r/test \ && apt-get update && apt-get install -y gcc-4.8 g++-4.8 \ && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50 + # NodeJS RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \ && apt-get install -y nodejs diff --git a/scripts/build/docker/Dockerfile-x86_64 b/scripts/build/docker/Dockerfile-x86_64 index 215b38ec..d4803409 100644 --- a/scripts/build/docker/Dockerfile-x86_64 +++ b/scripts/build/docker/Dockerfile-x86_64 @@ -6,6 +6,7 @@ FROM ubuntu:12.04 RUN echo "deb http://archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse" >> /etc/apt/sources.list + # Install dependencies RUN apt-get update \ && apt-get install -y \ @@ -35,11 +36,13 @@ RUN apt-get update \ zip \ rpm + # Install a C++11 compiler RUN add-apt-repository ppa:ubuntu-toolchain-r/test \ && apt-get update && apt-get install -y gcc-4.8 g++-4.8 \ && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50 + # NodeJS RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \ && apt-get install -y nodejs diff --git a/scripts/build/docker/Dockerfile.template b/scripts/build/docker/Dockerfile.template index 69de5ec2..327b6de0 100644 --- a/scripts/build/docker/Dockerfile.template +++ b/scripts/build/docker/Dockerfile.template @@ -8,6 +8,9 @@ RUN sed s,ubuntu\.stu\.edu\.tw,archive.ubuntu.com, /etc/apt/sources.list > /tmp/ <% if (architecture == 'x86_64') { %> RUN echo "deb http://archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse" >> /etc/apt/sources.list <% } %> +<% if (architecture == 'armv7hf') { %> +RUN echo "deb http://ftp.debian.org/debian jessie-backports main" >> /etc/apt/sources.list +<% } %> # Install dependencies RUN apt-get update \ @@ -38,10 +41,12 @@ RUN apt-get update \ zip \ rpm +<% if (architecture != 'armv7hf') { %> # Install a C++11 compiler RUN add-apt-repository ppa:ubuntu-toolchain-r/test \ && apt-get update && apt-get install -y gcc-4.8 g++-4.8 \ && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50 +<% } %> # NodeJS RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \ diff --git a/scripts/build/docker/compile-template.js b/scripts/build/docker/compile-template.js index abd92967..0c72735b 100644 --- a/scripts/build/docker/compile-template.js +++ b/scripts/build/docker/compile-template.js @@ -36,6 +36,10 @@ _.each([ { architecture: 'x86_64', image: 'ubuntu:12.04' + }, + { + architecture: 'armv7hf', + image: 'resin/armv7hf-debian:jessie' } ], (options) => { const result = _.template(template)(options) diff --git a/scripts/build/docker/run-command.sh b/scripts/build/docker/run-command.sh index dec3d0a0..84937c50 100755 --- a/scripts/build/docker/run-command.sh +++ b/scripts/build/docker/run-command.sh @@ -54,16 +54,9 @@ then usage fi -if [ "$ARGV_ARCHITECTURE" == "x64" ]; then - DOCKERFILE="$HERE/Dockerfile-x86_64" -elif [ "$ARGV_ARCHITECTURE" == "x86" ]; then - DOCKERFILE="$HERE/Dockerfile-i686" -else - echo "Unsupported architecture: $ARGV_ARCHITECTURE" 1>&2 - exit 1 -fi - -IMAGE_ID="etcher-build-$ARGV_ARCHITECTURE" +DOCKER_ARCHITECTURE=$(./scripts/build/architecture-convert.sh -r "$ARGV_ARCHITECTURE" -t docker) +DOCKERFILE="$HERE/Dockerfile-$DOCKER_ARCHITECTURE" +IMAGE_ID="etcher-build-$DOCKER_ARCHITECTURE" docker build -f "$DOCKERFILE" -t "$IMAGE_ID" "$ARGV_SOURCE_CODE_DIRECTORY"