diff options
-rwxr-xr-x | .travis/build-and-run-docker-test-containers.sh | 13 | ||||
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/docker/Dockerfile.testing.cpp.debian_buster | 10 | ||||
-rwxr-xr-x | tests/docker/build_flatc.run.sh | 15 | ||||
-rwxr-xr-x | tests/docker/cpp_test.run.sh | 20 |
5 files changed, 59 insertions, 4 deletions
diff --git a/.travis/build-and-run-docker-test-containers.sh b/.travis/build-and-run-docker-test-containers.sh index e6039bf6..d377ba8d 100755 --- a/.travis/build-and-run-docker-test-containers.sh +++ b/.travis/build-and-run-docker-test-containers.sh @@ -15,10 +15,15 @@ # limitations under the License. set -e -# build flatc on debian once to speed up the test loop below -docker build -t build_flatc_debian_stretch -f tests/docker/Dockerfile.testing.build_flatc_debian_stretch . -BUILD_CONTAINER_ID=$(docker create --read-only build_flatc_debian_stretch) -docker cp ${BUILD_CONTAINER_ID}:/code/flatc flatc_debian_stretch +docker build -t build_cpp_image -f tests/docker/Dockerfile.testing.cpp.debian_buster . +# Run tests with sanitizers (--cap-add SYS_PTRACE), both GCC and Clang. +cpp_test_args="--cap-add SYS_PTRACE build_cpp_image sh ./tests/docker/cpp_test.run.sh Debug" +docker run --rm $cpp_test_args +docker run --rm --env CC=/usr/bin/clang --env CXX=/usr/bin/clang++ $cpp_test_args +# Build flatc on debian once to speed up the test loop below. +docker run --name flatc_container build_cpp_image sh ./tests/docker/build_flatc.run.sh Debug +# All dependent dockers refer to 'flatc_debian_stretch'. +docker cp flatc_container:/flatbuffers/flatc flatc_debian_stretch for f in $(ls tests/docker/languages | sort) do diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b02d45c..e7e99809 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library" ON) option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler" ON) +option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag" + OFF) option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON) option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF) option(FLATBUFFERS_BUILD_SHAREDLIB @@ -295,6 +297,9 @@ if(FLATBUFFERS_BUILD_FLATC) # Make flatc.exe not depend on runtime dlls for easy distribution. target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>) endif() + if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC) + target_link_libraries(flatc PRIVATE -static) + endif() endif() if(FLATBUFFERS_BUILD_FLATHASH) diff --git a/tests/docker/Dockerfile.testing.cpp.debian_buster b/tests/docker/Dockerfile.testing.cpp.debian_buster new file mode 100644 index 00000000..7b0cce2d --- /dev/null +++ b/tests/docker/Dockerfile.testing.cpp.debian_buster @@ -0,0 +1,10 @@ +FROM debian:10.1-slim as base +RUN apt -qq update >/dev/null +RUN apt -qq install -y cmake make build-essential >/dev/null +RUN apt -qq install -y autoconf git libtool >/dev/null +RUN apt -qq install -y clang >/dev/null +FROM base +# Travis machines have 2 cores. Can be redefined with 'run --env PAR_JOBS=N'. +ENV JOBS=2 +WORKDIR /flatbuffers +ADD . . diff --git a/tests/docker/build_flatc.run.sh b/tests/docker/build_flatc.run.sh new file mode 100755 index 00000000..c8885b19 --- /dev/null +++ b/tests/docker/build_flatc.run.sh @@ -0,0 +1,15 @@ +set -e + +JOBS=${JOBS:-1} +config=$1 +echo "" +echo "Build 'flatc' compiler for '$config'" + +cmake . -DCMAKE_BUILD_TYPE=$config \ + -DFLATBUFFERS_BUILD_FLATC=1 -DFLATBUFFERS_STATIC_FLATC=1 \ + -DFLATBUFFERS_BUILD_TESTS=0 -DFLATBUFFERS_INSTALL=0 +cmake --build . --target flatc --clean-first -- -j$JOBS + +echo "Check generated code" +.travis/check-generate-code.sh +echo "Done" diff --git a/tests/docker/cpp_test.run.sh b/tests/docker/cpp_test.run.sh new file mode 100755 index 00000000..fa3b0fb1 --- /dev/null +++ b/tests/docker/cpp_test.run.sh @@ -0,0 +1,20 @@ +set -e + +JOBS=${JOBS:-1} +export UBSAN_OPTIONS=halt_on_error=1 +export ASAN_OPTIONS=halt_on_error=1 +export MAKEFLAGS="-j$JOBS" + +config=$1 +echo "" +echo "Build Flatbuffers project for '$config' with jobs=$JOBS" + +cmake . -DCMAKE_BUILD_TYPE=$config \ + -DFLATBUFFERS_BUILD_TESTS=ON -DFLATBUFFERS_CODE_SANITIZE=ON +cmake --build . --target all --clean-first -- -j$JOBS +ctest --extra-verbose --output-on-failure -j$JOBS + +echo "Check generated code" +.travis/check-generate-code.sh + +echo "C++ tests done" |