diff --git a/linux-x86/Dockerfile b/linux-x86/Dockerfile index 191bfab..c343852 100644 --- a/linux-x86/Dockerfile +++ b/linux-x86/Dockerfile @@ -4,18 +4,31 @@ MAINTAINER Matt McCormick "matt.mccormick@kitware.com" RUN dpkg --add-architecture i386 && \ apt-get update && apt-get -y install \ gcc-multilib \ - g++-multilib + g++-multilib \ + libc6:i386 \ + libstdc++6:i386 ENV CROSS_TRIPLE i686-linux-gnu ENV CROSS_ROOT /usr/${CROSS_TRIPLE} ENV PATH ${PATH}:${CROSS_ROOT}/bin RUN mkdir -p ${CROSS_ROOT}/bin COPY ${CROSS_TRIPLE}.sh ${CROSS_ROOT}/bin/${CROSS_TRIPLE}.sh +COPY ${CROSS_TRIPLE}-as.sh ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-as.sh RUN cd ${CROSS_ROOT}/bin && \ chmod +x ${CROSS_TRIPLE}.sh && \ ln -s /usr/bin/x86_64-linux-gnu-gcc && \ ln -s /usr/bin/x86_64-linux-gnu-g++ && \ + ln -s /usr/bin/x86_64-linux-gnu-as && \ ln -s ${CROSS_TRIPLE}.sh ${CROSS_TRIPLE}-gcc && \ - ln -s ${CROSS_TRIPLE}.sh ${CROSS_TRIPLE}-g++ -ENV CC=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-gcc \ + ln -s ${CROSS_TRIPLE}.sh ${CROSS_TRIPLE}-g++ && \ + ln -s ${CROSS_TRIPLE}-as.sh ${CROSS_TRIPLE}-as && \ + ln -s /usr/bin/x86_64-linux-gnu-ar ${CROSS_TRIPLE}-ar +ENV AS=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-as \ + AR=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-ar \ + CC=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-gcc \ CXX=${CROSS_ROOT}/bin/${CROSS_TRIPLE}-g++ + +# Note: Toolchain file support is currently in debian Experimental: +# https://wiki.debian.org/CrossToolchains#In_jessie_.28Debian_8.29 +COPY Toolchain.cmake /usr/lib/${CROSS_TRIPLE}/ +ENV CMAKE_TOOLCHAIN_FILE /usr/lib/${CROSS_TRIPLE}/Toolchain.cmake diff --git a/linux-x86/Toolchain.cmake b/linux-x86/Toolchain.cmake new file mode 100644 index 0000000..0d4a74a --- /dev/null +++ b/linux-x86/Toolchain.cmake @@ -0,0 +1,20 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR i686) + +# Setting these is not needed because the -m32 flag is already +# associated with the ${cross_triple}-gcc wrapper script. +#set(CMAKE_CXX_COMPILER_ARG1 "-m32") +#set(CMAKE_C_COMPILER_ARG1 "-m32") + +set(cross_triple "i686-linux-gnu") + +set(CMAKE_C_COMPILER /usr/${cross_triple}/bin/${cross_triple}-gcc) +set(CMAKE_CXX_COMPILER /usr/${cross_triple}/bin/${cross_triple}-g++) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_AR /usr/${cross_triple}/bin/${cross_triple}-ar) + +# Prevent 64-bit libraries from being discovered +set(CMAKE_IGNORE_PATH /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/lib/) + +set(CMAKE_CROSSCOMPILING_EMULATOR sh -c) diff --git a/linux-x86/i686-linux-gnu-as.sh b/linux-x86/i686-linux-gnu-as.sh new file mode 100644 index 0000000..8fc21ef --- /dev/null +++ b/linux-x86/i686-linux-gnu-as.sh @@ -0,0 +1,2 @@ +#!/bin/bash +exec ${0/${CROSS_TRIPLE}-/x86_64-linux-gnu-} --32 "$@" diff --git a/test/run.py b/test/run.py index 29069ec..ec5940f 100755 --- a/test/run.py +++ b/test/run.py @@ -76,7 +76,7 @@ def test_cmake_build_system(build_dir, language, source, emulator, linker_flags, def test_source(source, language, build_system, emulator, linker_flags, - exe_suffix): + exe_suffix, debug): result = 0 cwd = os.getcwd() build_dir = tempfile.mkdtemp() @@ -100,13 +100,18 @@ def test_source(source, language, build_system, emulator, linker_flags, result += subprocess.call(cmd, shell=True) os.chdir(cwd) - shutil.rmtree(build_dir) + if not debug: + print('Deleting temporary build directory ' + build_dir) + shutil.rmtree(build_dir) + else: + print('Keeping temporary build directory ' + build_dir) + sys.stdout.flush() return result def test_build_system(test_dir, language, build_system, emulator, linker_flags, - exe_suffix): + exe_suffix, debug): print('\n\n--------------------------------------------------------') print('Testing ' + build_system + ' build system with the ' + language + ' language\n') @@ -114,12 +119,12 @@ def test_build_system(test_dir, language, build_system, emulator, linker_flags, result = 0 for source in glob.glob(os.path.join(test_dir, language, '*')): result += test_source(source, language, build_system, emulator, - linker_flags, exe_suffix) + linker_flags, exe_suffix, debug) return result def test_language(test_dir, language, build_systems, emulator, linker_flags, - exe_suffix): + exe_suffix, debug): result = 0 for build_system in build_systems: result += test_build_system(test_dir, @@ -127,12 +132,13 @@ def test_language(test_dir, language, build_systems, emulator, linker_flags, build_system, emulator, linker_flags, - exe_suffix) + exe_suffix, + debug) return result def run_tests(test_dir, languages=('C', 'C++'), build_systems=('None', 'CMake'), - emulator=None, linker_flags=None, exe_suffix=''): + emulator=None, linker_flags=None, exe_suffix='', debug=False): """Run the tests found in test_dir where each directory corresponds to an entry in languages. Every source within a language directory is built. The output executable is also run with the emulator if provided.""" @@ -143,7 +149,8 @@ def run_tests(test_dir, languages=('C', 'C++'), build_systems=('None', 'CMake'), build_systems, emulator, linker_flags, - exe_suffix) + exe_suffix, + debug) return result @@ -160,6 +167,8 @@ if __name__ == '__main__': help='Extra compilation linker flags') parser.add_argument('--exe-suffix', '-s', default='', help='Suffix for generated executables') + parser.add_argument('--debug', '-d', action='store_true', + help='Do not remove temporary build directory') args = parser.parse_args() test_dir = os.path.dirname(os.path.abspath(__file__)) @@ -169,4 +178,5 @@ if __name__ == '__main__': build_systems=args.build_systems, emulator=args.emulator, linker_flags=args.linker_flags, - exe_suffix=args.exe_suffix) != 0) + exe_suffix=args.exe_suffix, + debug=args.debug) != 0)