Skip to content

Commit 67f059e

Browse files
stephenkyle-ARMeustas
authored andcommitted
Cross compilation support (google#709)
* build: add cross-compilation support to make Set CROSS_COMPILE when running make to use the selected cross compilation toolchain, such as arm-linux-gnueabihf, or aarch64-linux-gnu. Testing requires the presence of qemu - 'qemu-$(ARCH)' will be executed, where ARCH is the first part of the toolchain triplet. * build: add cross-compilation support to cmake If C_COMPILER/CXX_COMPILER/CC/CXX are found to have cross-compilation triplets in front of the compiler, then qemu will be used to execute the tests. * CI: add arm-linux-gnueabihf-gcc builder to Travis The version of qemu available in Ubuntu trusty (as provided by Travis) appears to have a bug in qemu-aarch64, which leads to the compatibility tests failing on some inputs, erroneously rejecting the input as corrupt. Once Travis supports xenial, we could add an aarch64-gnu-linux-gcc builder as well. * CI: propagate cmake errors out of .travis.sh Seems like even if cmake fails, the error isn't picked up by Travis.
1 parent 6eba239 commit 67f059e

8 files changed

+71
-11
lines changed

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ matrix:
7575
packages:
7676
- clang-3.5
7777

78+
###
79+
## testing arm via qemu on Linux
80+
###
81+
- os: linux
82+
env: BUILD_SYSTEM=cmake C_COMPILER=arm-linux-gnueabihf-gcc CXX_COMPILER=arm-linux-gnueabihf-g++
83+
addons:
84+
apt:
85+
sources:
86+
- ubuntu-toolchain-r-test
87+
packages:
88+
- qemu
89+
- gcc-arm-linux-gnueabihf
90+
- libc6-dev-armhf-cross
91+
7892
###
7993
## PGI Community Edition on Linux
8094
###

CMakeLists.txt

+28-4
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,37 @@ endif()
218218
# to run the tests...
219219
if(NOT BROTLI_DISABLE_TESTS)
220220
if(WIN32 AND NOT CMAKE_HOST_WIN32)
221-
find_program(BROTLI_WINE NAMES wine)
221+
find_program(BROTLI_WRAPPER NAMES wine)
222222

223-
if(NOT BROTLI_WINE)
223+
if(NOT BROTLI_WRAPPER)
224224
message(STATUS "wine not found, disabling tests")
225225
set(BROTLI_DISABLE_TESTS TRUE)
226226
endif()
227227
endif()
228228
endif()
229229

230+
# If our compiler is a cross-compiler that we know about (arm/aarch64),
231+
# then we need to use qemu to execute the tests.
232+
if(NOT BROTLI_DISABLE_TESTS)
233+
if ("${CMAKE_C_COMPILER}" MATCHES "^.*/arm-linux-gnueabihf-.*$")
234+
message(STATUS "Detected arm-linux-gnueabihf cross-compilation")
235+
set(BROTLI_WRAPPER "qemu-arm")
236+
set(BROTLI_WRAPPER_LD_PREFIX "/usr/arm-linux-gnueabihf")
237+
endif()
238+
239+
if ("${CMAKE_C_COMPILER}" MATCHES "^.*/arm-linux-gnueabi-.*$")
240+
message(STATUS "Detected arm-linux-gnueabi cross-compilation")
241+
set(BROTLI_WRAPPER "qemu-arm")
242+
set(BROTLI_WRAPPER_LD_PREFIX "/usr/arm-linux-gnueabi")
243+
endif()
244+
245+
if ("${CMAKE_C_COMPILER}" MATCHES "^.*/aarch64-linux-gnu-.*$")
246+
message(STATUS "Detected aarch64-linux-gnu cross-compilation")
247+
set(BROTLI_WRAPPER "qemu-aarch64")
248+
set(BROTLI_WRAPPER_LD_PREFIX "/usr/aarch64-linux-gnu")
249+
endif()
250+
endif()
251+
230252
if(NOT BROTLI_DISABLE_TESTS)
231253
include(CTest)
232254
enable_testing()
@@ -249,7 +271,8 @@ if(NOT BROTLI_DISABLE_TESTS)
249271
foreach(quality 1 6 9 11)
250272
add_test(NAME "${BROTLI_TEST_PREFIX}roundtrip/${INPUT}/${quality}"
251273
COMMAND "${CMAKE_COMMAND}"
252-
-DBROTLI_WRAPPER=${BROTLI_WINE}
274+
-DBROTLI_WRAPPER=${BROTLI_WRAPPER}
275+
-DBROTLI_WRAPPER_LD_PREFIX=${BROTLI_WRAPPER_LD_PREFIX}
253276
-DBROTLI_CLI=$<TARGET_FILE:brotli>
254277
-DQUALITY=${quality}
255278
-DINPUT=${INPUT_FILE}
@@ -266,7 +289,8 @@ if(NOT BROTLI_DISABLE_TESTS)
266289
foreach(INPUT ${COMPATIBILITY_INPUTS})
267290
add_test(NAME "${BROTLI_TEST_PREFIX}compatibility/${INPUT}"
268291
COMMAND "${CMAKE_COMMAND}"
269-
-DBROTLI_WRAPPER=${BROTLI_WINE}
292+
-DBROTLI_WRAPPER=${BROTLI_WRAPPER}
293+
-DBROTLI_WRAPPER_LD_PREFIX=${BROTLI_WRAPPER_LD_PREFIX}
270294
-DBROTLI_CLI=$<TARGET_FILE:brotli>
271295
-DINPUT=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT}
272296
-P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-compatibility-test.cmake)

Makefile

+14-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ ifeq ($(os), Darwin)
1515
CPPFLAGS += -DOS_MACOSX
1616
endif
1717

18+
ifneq ($(strip $(CROSS_COMPILE)), )
19+
CC=$(CROSS_COMPILE)-gcc
20+
ARCH=$(firstword $(subst -, ,$(CROSS_COMPILE)))
21+
BROTLI_WRAPPER="qemu-$(ARCH) -L /usr/$(CROSS_COMPILE)"
22+
endif
23+
24+
# The arm-linux-gnueabi compiler defaults to Armv5. Since we only support Armv7
25+
# and beyond, we need to select Armv7 explicitly with march.
26+
ifeq ($(ARCH), arm)
27+
CFLAGS += -march=armv7-a
28+
endif
29+
1830
all: test
1931
@:
2032

@@ -31,8 +43,8 @@ lib: $(LIBOBJECTS)
3143
ar -crs $(LIB_A) $(LIBOBJECTS)
3244

3345
test: $(EXECUTABLE)
34-
tests/compatibility_test.sh
35-
tests/roundtrip_test.sh
46+
tests/compatibility_test.sh $(BROTLI_WRAPPER)
47+
tests/roundtrip_test.sh $(BROTLI_WRAPPER)
3648

3749
clean:
3850
rm -rf $(BINDIR) $(LIB_A)

scripts/.travis.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ case "$1" in
4040
if [ "${CROSS_COMPILE}" = "yes" ]; then
4141
CMAKE_FLAGS="-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RC_COMPILER=${RC_COMPILER}"
4242
fi
43-
cmake ${CMAKE_FLAGS} -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DENABLE_SANITIZER="${SANITIZER}" -DCMAKE_C_FLAGS="${CFLAGS}" ..
44-
make VERBOSE=1
45-
ctest -V
43+
cmake ${CMAKE_FLAGS} -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DENABLE_SANITIZER="${SANITIZER}" -DCMAKE_C_FLAGS="${CFLAGS}" .. || exit 1
44+
make VERBOSE=1 || exit 1
45+
ctest -V || exit 1
4646
;;
4747
"python")
4848
python setup.py test

tests/compatibility_test.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
#
33
# Test that the brotli command-line tool can decompress old brotli-compressed
44
# files.
5+
#
6+
# The first argument may be a wrapper for brotli, such as 'qemu-arm'.
57

68
set -o errexit
79

8-
BROTLI=bin/brotli
10+
BROTLI_WRAPPER=$1
11+
BROTLI="${BROTLI_WRAPPER} bin/brotli"
912
TMP_DIR=bin/tmp
1013

1114
for file in tests/testdata/*.compressed*; do

tests/roundtrip_test.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env bash
22
#
33
# Roundtrip test for the brotli command-line tool.
4+
#
5+
# The first argument may be a wrapper for brotli, such as 'qemu-arm'.
46

57
set -o errexit
68

7-
BROTLI=bin/brotli
9+
BROTLI_WRAPPER=$1
10+
BROTLI="${BROTLI_WRAPPER} bin/brotli"
811
TMP_DIR=bin/tmp
912
INPUTS="""
1013
tests/testdata/alice29.txt

tests/run-compatibility-test.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ string(REGEX REPLACE "([a-zA-Z0-9\\.]+)\\.compressed(\\.[0-9]+)?$" "\\1" REFEREN
22
string(REGEX REPLACE "\\.compressed" "" OUTPUT_FILE "${INPUT}")
33
get_filename_component(OUTPUT_NAME "${OUTPUT_FILE}" NAME)
44

5+
set(ENV{QEMU_LD_PREFIX} "${BROTLI_WRAPPER_LD_PREFIX}")
6+
57
execute_process(
68
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
79
COMMAND ${BROTLI_WRAPPER} ${BROTLI_CLI} --force --decompress ${INPUT} --output=${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}.unbr

tests/run-roundtrip-test.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set(ENV{QEMU_LD_PREFIX} "${BROTLI_WRAPPER_LD_PREFIX}")
2+
13
execute_process(
24
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
35
COMMAND ${BROTLI_WRAPPER} ${BROTLI_CLI} --force --quality=${QUALITY} ${INPUT} --output=${OUTPUT}.br

0 commit comments

Comments
 (0)