Compare commits

..

No commits in common. "feature/cross-compile" and "master" have entirely different histories.

10 changed files with 2 additions and 1236 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
/build*
/build
# ---> C++
# Prerequisites

View File

@ -10,7 +10,7 @@ class BmrConan(ConanFile):
def configure(self):
self.options["boost"].without_cobalt = True
if self.settings.arch == "armv7" or self.settings.arch == "armv6":
if self.settings.arch == "armv7":
self.options["libpng"].neon = False

View File

@ -1,47 +0,0 @@
# Creating cross-compilers
This folder contains configuration, scripts and docker images used in the creation of cross-compilers and a cross-compilation environment. The intended use case is that these scripts can be used to very easilly create an environment where we can build software for different platforms. Docker is being used to create a contained reproducable environment.
For these scripts and instructions to work you only need docker and the bare minimum of shell scripting support.
## How to use:
1. Have this repository available on your local machine
2. Build the cross compiler & create a cross build environment.
``cd scripts/create-cross-compiler``
``./create-armv6-rpi-linux-gnueabihf.sh``
The resulting cross compiler is stored in the "build-tools" folder. There will also be a docker image created that can be used in the process of building.
3. Do some cross compiling
````
docker run -ti \
-v ../../:/workspace \
bmr-cross-compiler
````
How to build the software:
````
cd /workspace
conan remote remove conancenter
conan remote add conan-upload https://artifacts.4beumer.nl/repository/conan-bmrdev/
conan remote add conan-remote https://artifacts.4beumer.nl/repository/conan-center-proxy/
conan build . -of build-cross \
-s compiler.cppstd=23 \
-s build_type=Debug \
--build=missing \
-pr:b=/x-tools/armv6-rpi-linux-gnueabihf/conan.profile \
-pr:h=default
cmake --preset conan-debug .
cmake --preset conan-debug .
cmake --build ./build-cross
````
* Configuration needs to be provided. (environment variable: CROSS_TARGET_INFO_PATH).
* Destination location needs to be provided (environment variable: CROSS_TARGET_DST_PATH).
* Use docker volume functionality to link directories to the docker container.
``docker run -ti -e CROSS_TARGET_INFO_PATH=/config -e CROSS_TARGET_DST_PATH=/dst -v ./armv6-rpi-linux:/config -v ./dst:/dst <docker image name>``

View File

@ -1,89 +0,0 @@
FROM alpine:3.22.2
# Install packages needed in both building and running.
RUN apk update && \
apk add --no-cache \
libstdc++
# Install tools required for building.
RUN mkdir -p /root/.local/bin
ENV PATH="${PATH}:/root/.local/bin"
RUN apk add --no-cache \
autoconf \
bash \
binutils \
build-base \
cmake \
clang \
clang-extra-tools \
gdb \
git \
libtool \
linux-headers \
ninja \
m4 \
perl \
python3 \
pipx
# Install tools we need for building the cross compiler.
RUN apk add --no-cache \
gpg \
gpg-agent \
automake \
flex \
make \
texinfo \
xz \
help2man \
gawk \
bison \
ncurses-dev \
rsync \
wget
RUN mkdir -p /workspace
WORKDIR /workspace
# Download crosstool-ng that we use to build the cross compiler.
RUN <<EOF
gpg --keyserver pgp.surfnet.nl --recv-keys 721B0FB1CDC8318AEBB888B809F6DD5F1F30EF2E
wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.28.0.tar.bz2.sig
wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.28.0.tar.bz2
gpg --verify crosstool-ng-1.28.0.tar.bz2.sig
tar -xjf crosstool-ng-1.28.0.tar.bz2
mv /workspace/crosstool-ng-1.28.0 /crosstool
EOF
# - Add a user that we need for building (crosstool-ng requires non-root user for that).
# - Add some directories we need in the future for building.
# - Build crosstool-ng, which in it's turn will be used to build the cross compiler.
ENV CROSS_DESTDIR=/x-tools
WORKDIR /crosstool
RUN <<EOF
adduser -D crosstoolng
mkdir -p /home/crosstoolng/src
mkdir -p $CROSS_DESTDIR
./bootstrap
./configure
make DESTDIR=$CROSS_DESTDIR
make install
chown -R crosstoolng:crosstoolng /crosstool
chown -R crosstoolng:crosstoolng $CROSS_DESTDIR
chown -R crosstoolng:crosstoolng /home/crosstoolng
EOF
# We now have crosstool-ng built and ready to be used for building the cross-compiler that we actually want. To
# do that we need to feed some configuration
WORKDIR /workspace
ADD --chmod=544 ./scripts/create-cross-compiler.py .
ADD --chmod=544 ./scripts/entrypoint.sh .
ENTRYPOINT ["./entrypoint.sh"]

View File

@ -1,12 +0,0 @@
[settings]
os=Linux
arch=armv6
compiler=gcc
build_type=Release
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=14
[buildenv]
CC=/x-tools/armv6-rpi-linux-gnueabihf/bin/armv6-rpi-linux-gnueabihf-gcc
CXX=/x-tools/armv6-rpi-linux-gnueabihf/bin/armv6-rpi-linux-gnueabihf-g++
LD=/x-tools/armv6-rpi-linux-gnueabihf/bin/armv6-rpi-linux-gnueabihf-ld

View File

@ -1,25 +0,0 @@
#!/bin/sh
# Prepare a directory that will contain the cross compiler
mkdir -p ../../build-tools/x-tools
# Build docker image responsible for building the cross compiler
docker build \
-t bmr-build-cross-compiler \
-f build-cross-compiler.Dockerfile .
# Perform building of cross compiler
docker run -ti \
-e CROSS_TARGET_INFO_PATH=/extern-config \
-e CROSS_TARGET_DST_PATH=/extern-dst \
-v ./configurations/armv6-rpi-linux-gnueabihf:/extern-config \
-v ../../build-tools/x-tools:/extern-dst \
bmr-build-cross-compiler
# Build docker image to be used for cross compiling
docker build \
-t bmr-cross-compiler \
--build-arg CROSS_COMPILER=armv6-rpi-linux-gnueabihf \
-f cross-compiler.Dockerfile ../..

View File

@ -1,57 +0,0 @@
#! /usr/bin/python
import argparse
import json
import os
import shutil
import subprocess
import sys
def runcmd(command):
print('RUN ' + command)
process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
for line in iter(process.stdout.readline, b''): # b'' indicates EOF
print(line.decode('utf-8'), end='')
def load_environment(filename):
with open(filename) as f:
return json.load(f)
parser = argparse.ArgumentParser()
parser.add_argument('--cross-target-info-path', dest='target_info')
parser.add_argument('--cross-destination-path', dest='dst')
args = parser.parse_args()
cross_target_info_path = args.target_info
cross_destination_path = args.dst
ctng_config = cross_target_info_path + '/ct-ng.config'
cross_destdir = os.environ['CROSS_DESTDIR']
if not os.path.isdir(cross_destdir):
raise Exception("ERROR... expected internal destination for ct-ng does not exist")
if not os.path.isdir(cross_target_info_path):
raise Exception("Supplied configuration info path is not a directory")
if not os.path.isfile(ctng_config):
raise Exception("No crosstool ng configuration file found (ct-ng.config)")
shutil.copy(ctng_config, '/crosstool/.config')
os.chdir('/crosstool')
runcmd("su crosstoolng -c 'ct-ng source'")
runcmd("su crosstoolng -c 'ct-ng build'")
# Determine directory of the cross compiler built, then copy the conan profile into it.
cross_compiler_built = None
if True:
entries = os.listdir(cross_destdir)
if len(entries) == 1:
cross_compiler_built = entries[0]
if cross_compiler_built is None:
raise Exception("ERROR... Something went wrong determining where the cross compiler build result is stored.")
runcmd("cp -r " + cross_destdir + "/* " + cross_destination_path + "/")
runcmd("cp " + cross_target_info_path + '/conan.profile ' + cross_destination_path + '/' + cross_compiler_built + '/conan.profile')
sys.exit(0)

View File

@ -1,3 +0,0 @@
#!/bin/bash
./create-cross-compiler.py --cross-target-info-path=$CROSS_TARGET_INFO_PATH --cross-destination-path=$CROSS_TARGET_DST_PATH