From 33427146e176fe4e6ca6d24044fcd32be1894eb1 Mon Sep 17 00:00:00 2001 From: "H. Utku Maden" Date: Sat, 8 Jul 2023 13:17:14 +0300 Subject: [PATCH] Design a docker container for cross compiling native dependencies. --- .gitignore | 3 ++- Dockerfile | 59 +++++++++++++++++++++++++++++++++++++++++ cmake/linux-arm.cmake | 13 +++++++++ cmake/linux-arm64.cmake | 13 +++++++++ cmake/linux-x64.cmake | 9 +++++++ cmake/linux-x86.cmake | 14 ++++++++++ cmake/win-x64.cmake | 14 ++++++++++ cmake/win-x86.cmake | 14 ++++++++++ compose.yaml | 13 +++++++++ sh/bashrc.sh | 5 ++++ sh/build_native.sh | 3 +++ sh/init.sh | 15 +++++++++++ sh/quik_build_native.sh | 38 ++++++++++++++++++++++++++ 13 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 cmake/linux-arm.cmake create mode 100644 cmake/linux-arm64.cmake create mode 100644 cmake/linux-x64.cmake create mode 100644 cmake/linux-x86.cmake create mode 100644 cmake/win-x64.cmake create mode 100644 cmake/win-x86.cmake create mode 100644 compose.yaml create mode 100755 sh/bashrc.sh create mode 100755 sh/build_native.sh create mode 100755 sh/init.sh create mode 100755 sh/quik_build_native.sh diff --git a/.gitignore b/.gitignore index 775a559..83df60d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ obj/ riderModule.iml /_ReSharper.Caches/ .idea -.vscode \ No newline at end of file +.vscode +nuget_repo diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eafcc94 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +# This is going to create an environment for you to cross compile all the +# packages needed to build this project. +# +# As always, debian > ubuntu <3 +FROM debian:stable-slim +WORKDIR /root + +# Download and Install dependencies. + # Install WGET + RUN apt-get update + RUN apt-get install -y sudo wget + + # Add the .NET package repository to the repository listing. + RUN wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + RUN dpkg -i packages-microsoft-prod.deb + RUN rm packages-microsoft-prod.deb + + # APT dependencies. + RUN apt-get update + RUN apt-get install -y \ + build-essential \ + bzip2 \ + cmake \ + clang \ + cpio \ + dotnet-sdk-6.0 \ + gcc-arm-linux-gnueabihf \ + gcc-aarch64-linux-gnu \ + gcc-i686-linux-gnu \ + git \ + libssl-dev \ + libxml2-dev \ + lzma-dev \ + mingw-w64 \ + nuget \ + patch \ + python3 \ + xz-utils \ + zlib1g-dev + + # Clone osxcross + # Let's do this later. + # RUN git clone https://github.com/tpoechtrager/osxcross.git osxcross + +# Setup interactive shell. + # Setup sudo. Remove password prompt for group "wheel". + # RUN echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/quik_sudo_conf + + # Create a default user and switch. + RUN adduser --comment "" --disabled-password quik + USER quik + WORKDIR /home/quik + + # Copy bashrc + RUN cp /etc/bash.bashrc ~/.bashrc + RUN echo source $HOME/src/sh/bashrc.sh >> ~/.bashrc + +# Execute an interactive shell. +CMD bash diff --git a/cmake/linux-arm.cmake b/cmake/linux-arm.cmake new file mode 100644 index 0000000..0d97ba8 --- /dev/null +++ b/cmake/linux-arm.cmake @@ -0,0 +1,13 @@ +# QUIK Toolchain file for Linux-arm systems. +# Copyright (C) 2023 + +set(CMAKE_SYSTEM_NAME Linux) + +set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) +set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) + +set(CMAKE_FIND_ROOT_PATH "/usr/arm-linux-gnueabihf") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file diff --git a/cmake/linux-arm64.cmake b/cmake/linux-arm64.cmake new file mode 100644 index 0000000..54a3c36 --- /dev/null +++ b/cmake/linux-arm64.cmake @@ -0,0 +1,13 @@ +# QUIK Toolchain file for Linux-arm64 (aarch64) systems. +# Copyright (C) 2023 + +set(CMAKE_SYSTEM_NAME Linux) + +set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) +set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) + +set(CMAKE_FIND_ROOT_PATH "/usr/aarch64-linux-gnu") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file diff --git a/cmake/linux-x64.cmake b/cmake/linux-x64.cmake new file mode 100644 index 0000000..1366483 --- /dev/null +++ b/cmake/linux-x64.cmake @@ -0,0 +1,9 @@ +# QUIK Toolchain file for Linux-x64 (amd64) systems. +# Copyright (C) 2023 + +set(CMAKE_SYSTEM_NAME Linux) + +set(CMAKE_C_COMPILER gcc) +set(CMAKE_CXX_COMPILER g++) + +add_compile_options(-m64) diff --git a/cmake/linux-x86.cmake b/cmake/linux-x86.cmake new file mode 100644 index 0000000..2f2a27b --- /dev/null +++ b/cmake/linux-x86.cmake @@ -0,0 +1,14 @@ +# QUIK Toolchain file for Linux-x86 (i386) systems. +# Copyright (C) 2023 + +set(CMAKE_SYSTEM_NAME Linux) + +set(CMAKE_C_COMPILER i686-linux-gnu-gcc) +set(CMAKE_CXX_COMPILER i686-linux-gnu-g++) + +add_compile_options(-m32 -march=i686) + +set(CMAKE_FIND_ROOT_PATH "/usr/i686-linux-gnu") +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/win-x64.cmake b/cmake/win-x64.cmake new file mode 100644 index 0000000..c48bc29 --- /dev/null +++ b/cmake/win-x64.cmake @@ -0,0 +1,14 @@ +# QUIK Toolchain file for Windows-x64 systems. +# Copyright (C) 2023 + +set(CMAKE_SYSTEM_NAME Windows) + +set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) + +set(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32") +add_compile_options(-m64) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file diff --git a/cmake/win-x86.cmake b/cmake/win-x86.cmake new file mode 100644 index 0000000..92dd74b --- /dev/null +++ b/cmake/win-x86.cmake @@ -0,0 +1,14 @@ +# QUIK Toolchain file for Windows-x86 systems. +# Copyright (C) 2023 + +set(CMAKE_SYSTEM_NAME Windows) + +set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) + +set(CMAKE_FIND_ROOT_PATH "/usr/i686-w64-mingw32") +add_compile_options(-m32) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..6683ac5 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,13 @@ +services: + cmdline: + image: quik/quik + user: quik + working_dir: /home/quik + volumes: + - src:/home/quik/src +volumes: + src: + driver_opts: + type: none + device: ${PWD} + o: bind \ No newline at end of file diff --git a/sh/bashrc.sh b/sh/bashrc.sh new file mode 100755 index 0000000..7bafa63 --- /dev/null +++ b/sh/bashrc.sh @@ -0,0 +1,5 @@ +source $HOME/src/sh/init.sh +echo QUIK Project Copyright \(C\) 2023 +echo +echo This is an interactive shell for QUIK build image. +echo SuperUser \(su/sudo\) commands are enabled without a password. Beware. diff --git a/sh/build_native.sh b/sh/build_native.sh new file mode 100755 index 0000000..d8ec71e --- /dev/null +++ b/sh/build_native.sh @@ -0,0 +1,3 @@ +#!/bin/bash +source $(dirname "$0")/quik_build_native.sh +quik_build_native "Quik.StbImage.redist" "linux-arm linux-arm64 linux-x64 linux-x86 win-x64 win-x86" \ No newline at end of file diff --git a/sh/init.sh b/sh/init.sh new file mode 100755 index 0000000..79deabc --- /dev/null +++ b/sh/init.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Change to source directory +cd $HOME/src + +export QUIK_SRC=$PWD +export QNUGET_LOCAL=QuikLocal +export QNUGET_LOCAL_PATH=$QUIK_SRC/nuget_repo +# export QNUGET_REMOTE=nuget + +# Create nuget repository. +mkdir -p $QUIK_SRC/nuget_repo +nuget sources Add -Name $QNUGET_LOCAL -Source $QNUGET_LOCAL_PATH -NonInteractive + +source sh/quik_build_native.sh \ No newline at end of file diff --git a/sh/quik_build_native.sh b/sh/quik_build_native.sh new file mode 100755 index 0000000..ba22f43 --- /dev/null +++ b/sh/quik_build_native.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# $1 Source path of the project. +# $2 Target architecture list. + +quik_build_native () { + SRC=$1 + NAME=$(dirname $SRC) + ARCHS=$2 + + cd $SRC + + for ARCH in $ARCHS; do + # Output directory. + PREFIX=runtimes/$ARCH/native + # Build directory. + BUILD=out/$ARCH + # Cmake toolchain file. + TOOLCHAIN=../cmake/$ARCH.cmake + + # Create directories. + mkdir -p $PREFIX $BUILD + # Configure CMAKE. + cmake -B $BUILD -S . \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=$PREFIX \ + -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN + + # Build and install. + make -C $BUILD all + make -C $BUILD install + done + + mkdir bin + nuget pack -OutputDirectory bin + nuget push $(find bin/*.nupkg) -Source $QNUGET_LOCAL -NonInteractive +} +