diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2c287d6..f07d8f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,7 +55,7 @@ jobs: manylinux2014-x64, manylinux2014-x86, windows-static-x64, windows-static-x64-posix, windows-static-x86, windows-armv7, windows-shared-x64, windows-shared-x64-posix, windows-shared-x86, windows-arm64, - linux-riscv64, linux-riscv32, linux-m68k-uclibc, linux-xtensa-uclibc] + linux-riscv64, linux-riscv32, linux-m68k-uclibc, linux-xtensa-uclibc, linux-x64-tinycc] steps: - uses: actions/checkout@v2 - uses: actions/download-artifact@v2 diff --git a/Makefile b/Makefile index 053b441..a3e3b61 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ BIN = ./bin # These images are built using the "build implicit rule" STANDARD_IMAGES = android-arm android-arm64 android-x86 android-x86_64 \ linux-x86 linux-x64 linux-x64-clang linux-arm64 linux-arm64-musl linux-arm64-full \ - linux-armv5 linux-armv5-musl linux-m68k-uclibc linux-s390x \ + linux-armv5 linux-armv5-musl linux-m68k-uclibc linux-s390x linux-x64-tinycc \ linux-armv6 linux-armv6-lts linux-armv6-musl \ linux-armv7l-musl linux-armv7 linux-armv7a \ linux-mips linux-ppc64le linux-riscv64 linux-riscv32 linux-xtensa-uclibc \ @@ -32,7 +32,7 @@ GEN_IMAGES = android-arm android-arm64 \ linux-armv7 linux-armv7a linux-armv7l-musl \ linux-armv6 linux-armv6-lts linux-armv6-musl \ linux-armv5 linux-armv5-musl linux-ppc64le linux-s390x \ - linux-riscv64 linux-riscv32 linux-m68k-uclibc linux-xtensa-uclibc + linux-riscv64 linux-riscv32 linux-m68k-uclibc linux-x64-tinycc linux-xtensa-uclibc GEN_IMAGE_DOCKERFILES = $(addsuffix /Dockerfile,$(GEN_IMAGES)) diff --git a/README.md b/README.md index d7765e3..4df8b51 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,14 @@ Cross compiling toolchains in Docker images. - Most images also contain an emulator for the target system. - Clean separation of build tools, source code, and build artifacts. - Commands in the container are run as the calling user, so that any created files have the expected ownership, (i.e. not root). -- Make variables **CC**, **CXX**, **LD** etc) are set to point to the appropriate tools in the container. +- Make variables **CC**, **CXX**, **LD**, **AS** etc) are set to point to the appropriate tools in the container. - Recent [CMake](https://cmake.org) and ninja are precompiled. - [Conan.io](https://www.conan.io) can be used as a package manager. - Toolchain files configured for CMake. - Current directory is mounted as the container\'s workdir, `/work`. - Works with the [Docker for Mac](https://docs.docker.com/docker-for-mac/) and [Docker for Windows](https://docs.docker.com/docker-for-windows/). - Support using alternative container executor by setting **OCI_EXE** environment variable. By default, it searches for [docker](https://www.docker.com) and [podman](https://podman.io) executable. +- [crosstool-ng](https://github.com/crosstool-ng/crosstool-ng) and [buildroot](https://github.com/buildroot/buildroot) configuration files. ## Examples @@ -40,26 +41,32 @@ This image does not need to be run manually. Instead, there is a helper script t To install the helper script, run one of the images with no arguments, and redirect the output to a file: - docker run --rm CROSS_COMPILER_IMAGE_NAME > ./dockcross - chmod +x ./dockcross - mv ./dockcross ~/bin/ +```bash +docker run --rm CROSS_COMPILER_IMAGE_NAME > ./dockcross +chmod +x ./dockcross +mv ./dockcross ~/bin/ +``` Where **CROSS_COMPILER_IMAGE_NAME** is the name of the cross-compiler toolchain Docker instance, e.g: **dockcross/linux-armv7**. -Only 64-bit x86_64 images are provided; a 64-bit x86_64 host system is required. +Only 64-bit x86_64 images are provided, a 64-bit x86_64 host system is required. ## Usage For the impatient, here\'s how to compile a hello world for armv7: - cd ~/src/dockcross - docker run --rm dockcross/linux-armv7 > ./dockcross-linux-armv7 - chmod +x ./dockcross-linux-armv7 - ./dockcross-linux-armv7 bash -c '$CC test/C/hello.c -o hello_arm' +```bash +cd ~/src/dockcross +docker run --rm dockcross/linux-armv7 > ./dockcross-linux-armv7 +chmod +x ./dockcross-linux-armv7 +./dockcross-linux-armv7 bash -c '$CC test/C/hello.c -o hello_arm' +``` Note how invoking any toolchain command (make, gcc, etc.) is just a matter of prepending the **dockcross** script on the commandline: - ./dockcross-linux-armv7 [command] [args...] +```bash +./dockcross-linux-armv7 [command] [args...] +``` The dockcross script will execute the given command-line inside the container, along with all arguments passed after the command. Commands that evaluate environmental variables in the image, like **$CC** or **$CXX** above, should be executed in [bash -c]. The present working directory is mounted within the image, which can be used to make source code available in the Docker container. @@ -73,6 +80,7 @@ The dockcross script will execute the given command-line inside the container, a | dockcross/android-x86 | x86 | Clang | Android | | dockcross/android-x86_64 | x86_64 | Clang | Android | | dockcross/linux-arm64 | ARMv8 | GCC | Linux | +| dockcross/linux-arm64-full | ARMv8 | GCC | Linux | | dockcross/linux-arm64-musl | ARMv8 | GCC + musl | Linux | | dockcross/linux-armv5 | ARMv5 | GCC | Linux | | dockcross/linux-armv5-musl | ARMv5 | GCC + musl | Linux | @@ -142,6 +150,12 @@ The Android NDK standalone toolchain for the x86_64 architecture. Cross compiler for the 64-bit ARM platform on Linux, also known as AArch64. +### dockcross/linux-arm64-full + +![Docker Image Size (tag)](https://img.shields.io/docker/image-size/dockcross/linux-arm64-full/latest) ![Docker Pulls](https://img.shields.io/docker/pulls/dockcross/linux-arm64-full) + +Cross compiler for the 64-bit ARM platform on Linux, with cross-libs: SDL2, OpenSSL, Boost, OpenCV and Qt5 (minimal). + ### dockcross/linux-arm64-musl ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/dockcross/linux-arm64-musl/latest) ![Docker Pulls](https://img.shields.io/docker/pulls/dockcross/linux-arm64-musl) @@ -363,12 +377,13 @@ cross-compiler Docker image or the dockcross script itself. To easily download all images, the convenience target `display_images` could be used: - - curl https://raw.githubusercontent.com/dockcross/dockcross/master/Makefile -o dockcross-Makefile - for image in $(make -f dockcross-Makefile display_images); do - echo "Pulling dockcross/$image" - docker pull dockcross/$image - done +```bash +curl https://raw.githubusercontent.com/dockcross/dockcross/master/Makefile -o dockcross-Makefile +for image in $(make -f dockcross-Makefile display_images); do + echo "Pulling dockcross/$image" + docker pull dockcross/$image +done +``` ## Install all dockcross scripts @@ -376,16 +391,18 @@ To automatically install in `~/bin` the dockcross scripts for each images already downloaded, the convenience target `display_images` could be used: - curl https://raw.githubusercontent.com/dockcross/dockcross/master/Makefile -o dockcross-Makefile - for image in $(make -f dockcross-Makefile display_images); do - if [[ $(docker images -q dockcross/$image) == "" ]]; then - echo "~/bin/dockcross-$image skipping: image not found locally" - continue - fi - echo "~/bin/dockcross-$image ok" - docker run dockcross/$image > ~/bin/dockcross-$image && \ - chmod u+x ~/bin/dockcross-$image - done +```bash +curl https://raw.githubusercontent.com/dockcross/dockcross/master/Makefile -o dockcross-Makefile +for image in $(make -f dockcross-Makefile display_images); do + if [[ $(docker images -q dockcross/$image) == "" ]]; then + echo "~/bin/dockcross-$image skipping: image not found locally" + continue + fi + echo "~/bin/dockcross-$image ok" + docker run dockcross/$image > ~/bin/dockcross-$image && \ + chmod u+x ~/bin/dockcross-$image +done +``` ## Dockcross configuration @@ -430,17 +447,21 @@ In order to extend Dockcross images with your own commands, one must: An example Dockerfile would be: - FROM dockcross/linux-armv7 +``` +FROM dockcross/linux-armv7 - ENV DEFAULT_DOCKCROSS_IMAGE my_cool_image - RUN apt-get install nano +ENV DEFAULT_DOCKCROSS_IMAGE my_cool_image +RUN apt-get install nano +``` And then in the shell: - docker build -t my_cool_image . ## Builds the dockcross image. - docker run my_cool_image > linux-armv7 ## Creates a helper script named linux-armv7. - chmod +x linux-armv7 ## Gives the script execution permission. - ./linux-armv7 bash ## Runs the helper script with the argument "bash", which starts an interactive container using your extended image. +``` +docker build -t my_cool_image . ## Builds the dockcross image. +docker run my_cool_image > linux-armv7 ## Creates a helper script named linux-armv7. +chmod +x linux-armv7 ## Gives the script execution permission. +./linux-armv7 bash ## Runs the helper script with the argument "bash", which starts an interactive container using your extended image. +``` ## What is the difference between **dockcross** and **dockbuild** ? diff --git a/linux-x64-tinycc/Dockerfile.in b/linux-x64-tinycc/Dockerfile.in new file mode 100644 index 0000000..469b0f4 --- /dev/null +++ b/linux-x64-tinycc/Dockerfile.in @@ -0,0 +1,31 @@ +FROM dockcross/base:latest +MAINTAINER Matt McCormick "matt.mccormick@kitware.com" + +RUN git clone --recurse-submodules https://repo.or.cz/tinycc.git \ + && cd tinycc \ + && ./configure --cpu=x86_64 \ + && make -j$(nproc) \ + && make test \ + && make install + +ENV PATH="/usr/local/bin:${PATH}" +# Test if compiler work +RUN tcc -v + +ENV CROSS_TRIPLE x86_64-linux-gnu +ENV CROSS_ROOT /usr/bin +ENV AS=/usr/bin/${CROSS_TRIPLE}-as \ + AR=/usr/bin/${CROSS_TRIPLE}-ar \ + CC=/usr/local/bin/tcc \ + CPP=/usr/bin/${CROSS_TRIPLE}-cpp \ + CXX=/usr/bin/${CROSS_TRIPLE}-g++ \ + LD=/usr/bin/${CROSS_TRIPLE}-ld \ + FC=/usr/bin/${CROSS_TRIPLE}-gfortran + + +COPY ${CROSS_TRIPLE}-noop.sh /usr/bin/${CROSS_TRIPLE}-noop + +COPY Toolchain.cmake /usr/lib/${CROSS_TRIPLE}/ +ENV CMAKE_TOOLCHAIN_FILE /usr/lib/${CROSS_TRIPLE}/Toolchain.cmake + +#include "common.label-and-env" diff --git a/linux-x64-tinycc/Toolchain.cmake b/linux-x64-tinycc/Toolchain.cmake new file mode 100644 index 0000000..9866b79 --- /dev/null +++ b/linux-x64-tinycc/Toolchain.cmake @@ -0,0 +1,12 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR x86_64) + +set(cross_triple "x86_64-linux-gnu") + +set(CMAKE_C_COMPILER $ENV{CC}) +set(CMAKE_CXX_COMPILER $ENV{CXX}) +set(CMAKE_Fortran_COMPILER $ENV{FC}) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) + +set(CMAKE_CROSSCOMPILING_EMULATOR /usr/bin/${cross_triple}-noop) diff --git a/linux-x64-tinycc/x86_64-linux-gnu-noop.sh b/linux-x64-tinycc/x86_64-linux-gnu-noop.sh new file mode 100755 index 0000000..311cb8c --- /dev/null +++ b/linux-x64-tinycc/x86_64-linux-gnu-noop.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exec "$@" diff --git a/tools/dockcross-builder.sh b/tools/dockcross-cmake-builder.sh similarity index 100% rename from tools/dockcross-builder.sh rename to tools/dockcross-cmake-builder.sh diff --git a/tools/dockcross-make-builder.sh b/tools/dockcross-make-builder.sh new file mode 100755 index 0000000..2f45d81 --- /dev/null +++ b/tools/dockcross-make-builder.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if (( $# >= 1 )); then + image=$1 + build_file=build-${image%:*} + shift 1 + + make_arg=$* + echo "make arg: $make_arg" + + #echo "Pulling dockcross/$image" + #docker pull dockcross/"$image" + + echo "Make script dockcross-$image" + docker run --rm dockcross/"$image" > ./dockcross-"$image" + chmod +x ./dockcross-"$image" + + echo "Build $build_file" + ./dockcross-"$image" bash -c 'make CXX=${CXX} CC=${CC} AR=${AR} AS=${AS} LD=${LD} CPP=${CPP} FC=${FC} '"$make_arg" +else + echo "Usage: ${0##*/} " + exit 1 +fi