Added support and documentation for cross-compiling code.

For now only added configuration for the raspberry Zero W 1.1.
This commit is contained in:
Bart Beumer 2026-04-19 20:59:49 +00:00
parent 9dde8eaf8e
commit 26a7f60786
10 changed files with 82 additions and 31 deletions

View File

View File

@ -0,0 +1,45 @@
# 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 <PATH TO WORKSPACE>:/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 \
--profile:build=default \
--profile:host=/x-tools/armv6-rpi-linux-gnueabihf/conan.profile
cmake --preset conan-debug .
cmake --build ./build-cross
cmake --install ./build-cross --prefix=/workspace/build-cross-install
````
* 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

@ -0,0 +1,24 @@
#!/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

@ -40,6 +40,18 @@ os.chdir('/crosstool')
runcmd("su crosstoolng -c 'ct-ng source'")
runcmd("su crosstoolng -c 'ct-ng build'")
runcmd("cp -rv " + cross_destdir + "/* " + cross_destination_path + "/")
# 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,17 +0,0 @@
# Creating cross-compilers
This folder contains configuration, scripts and docker images that are used for creating cross-compilers. The intended use case is to build C and C++ software for various platforms. Docker is being used to provide a common environment and isolating the build process.
## How to use:
1. Clone the repository to a location of your liking.
2. Create a docker image containing crosstool-ng.
``cd support/create-cross-compiler``
``docker build -t <docker image name> -f create-cross-compiler.Dockerfile .``
3. Use the docker image to create the cross comiler.
* 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,13 +0,0 @@
#!/bin/sh
mkdir -p ../../build-tools/x-tools
docker build \
-t bmr-create-cross-compiler \
-f create-cross-compiler.Dockerfile .
docker run -ti \
-e CROSS_TARGET_INFO_PATH=/extern-config \
-e CROSS_TARGET_DST_PATH=/extern-dst \
-v ./armv6-rpi-linux:/extern-config \
-v ../../build-tools/x-tools:/extern-dst bmr-create-cross-compiler