Skip to content

Commit

Permalink
ci/kuiper: workflow that build Scopy for Kuiper
Browse files Browse the repository at this point in the history
Signed-off-by: Bindea Cristian <[email protected]>
  • Loading branch information
bindea-cristian committed Apr 9, 2024
1 parent 70c36aa commit 9061130
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 105 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/kuiperbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Kuiper Scopy Build

on: [push, pull_request]

env:
BUILD_HOST: ubuntu-20.04
USERNAME: runner

jobs:

build_scopy_for_kuiper:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
with:
set-safe-directory: 'true'

- name: Pull the Docker Image
run: docker pull cristianbindea/scopy2-kuiper:latest

- name: Build Scopy
shell: bash
run: |
sudo chown -R 1000:1000 $GITHUB_WORKSPACE
docker run \
--mount type=bind,source="$GITHUB_WORKSPACE",target=/home/runner/scopy \
cristianbindea/scopy2-kuiper:latest /bin/bash -c 'id && cd /home/runner/scopy && ./ci/kuiper/kuiper_build_process.sh install_packages download_cmake download_crosscompiler move_sysroot build_scopy build_iio-emu create_appdir create_appimage move_appimage'
- name: Set short git commit SHA
shell: bash
run: echo "commit_sha=$(git rev-parse --short ${{ github.sha }})" >> "$GITHUB_ENV"

- uses: actions/upload-artifact@v4
with:
name: scopy-linux-armhf-${{ env.commit_sha }}.AppImage
path: ${{ github.workspace }}/Scopy-armhf.AppImage
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ build/*
.vscode/*
ci/ubuntu/staging
ci/macOS/staging
ci/kuiper/staging
ci/kuiper/docker/sysroot*
ci/kuiper/scopy.AppDir
windows/*
core/include/scopy-core_config.h
core/include/scopy-core_export.h
Expand Down
10 changes: 10 additions & 0 deletions ci/kuiper/AppRun
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e
SELF=$(readlink -f "$0")
HERE=${SELF%/*}

export QT_PLUGIN_PATH=$HERE/usr/plugins
export QT_QPA_PLATFORM_PLUGIN_PATH=$HERE/usr/plugins/platforms
export LD_LIBRARY_PATH=$HERE/usr/lib

exec $HERE/usr/bin/scopy
Binary file added ci/kuiper/AppRun-armhf
Binary file not shown.
4 changes: 2 additions & 2 deletions ci/kuiper/build_qt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install_packages(){
pigz libncurses-dev autoconf automake tar figlet libclang-dev
}

#Download and extract QT Source (QT 5.15.2)
# Download and extract QT Source (QT 5.15.2)
download_qt(){
mkdir -p ${STAGING_AREA}
pushd ${STAGING_AREA}
Expand Down Expand Up @@ -67,7 +67,7 @@ build_qt5.15.2(){
-L$SYSROOT/usr/lib/arm-linux-gnueabihf -I$SYSROOT/usr/include/arm-linux-gnueabihf

make -j14
sudo make install #installs to $QT_BUILD_LOCATION
sudo make install # installs to $QT_BUILD_LOCATION
}

for arg in $@; do
Expand Down
6 changes: 4 additions & 2 deletions ci/kuiper/cmake_toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)
# In this case the variables CMAKE_SYSROOT and STAGING_AREA are defined as parameters to the cmake command
set(TOOLCHAIN_FILE ${STAGING_AREA}/cross-pi-gcc)
set(TOOLCHAIN_BIN ${TOOLCHAIN_FILE}/bin)
set(CMAKE_PREFIX_PATH "${CMAKE_SYSROOT}/usr/local/qt5.15")
set(CMAKE_PREFIX_PATH ${QT_LOCATION})
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SYSROOT}/usr/lib/arm-linux-gnueabihf")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SYSROOT}/lib")
set(CMAKE_VERBOSE ON)
Expand Down Expand Up @@ -45,6 +45,8 @@ set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG" )
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,-O1 -Wl,--hash-style=gnu -mthumb -lpthread -pthread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_SYSROOT}/usr/lib/arm-linux-gnueabihf")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_SYSROOT}/usr/lib")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_SYSROOT}/usr/local/lib")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${QT_LOCATION}/lib")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${TOOLCHAIN_FILE}/arm-linux-gnueabihf/lib")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${TOOLCHAIN_FILE}/arm-linux-gnueabihf/libc/lib")
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
Expand All @@ -56,7 +58,7 @@ set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) # Perform compiler test with static library
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN" "$ORIGIN/../lib" "/lib/arm-linux-gnueabihf" "/lib")
set(CMAKE_INSTALL_RPATH "$ORIGIN" "$ORIGIN/../lib" "/lib/arm-linux-gnueabihf" "/lib" "/usr/local/qt5.15/lib")
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
Expand Down
43 changes: 43 additions & 0 deletions ci/kuiper/copy-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e
SRC_DIR=$(git rev-parse --show-toplevel)
source $SRC_DIR/ci/kuiper/kuiper_build_config.sh

BINARY=$1
LOCATION=$2


if [ ! -f "${SRC_DIR}"/ci/kuiper/ldd-mod ]; then
sed 's|.*RTLDLIST=.*|RTLDLIST="/usr/arm-linux-gnueabihf/lib/ld-2.31.so /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3"|' /usr/bin/ldd | tee "${SRC_DIR}"/ci/kuiper/ldd-mod
chmod +x "${SRC_DIR}"/ci/kuiper/ldd-mod
fi

export LD_LIBRARY_PATH="${APP_DIR}/usr/lib:${SYSROOT}/lib:${SYSROOT}/lib/arm-linux-gnueabihf:${SYSROOT}/usr/arm-linux-gnueabihf/lib:${SYSROOT}/usr/local/qt5.15/lib:${SYSROOT}/usr/local/lib:${SRC_DIR}/build"
LIBS_ARRAY=()
run_ldd(){

if [ ! -z "$(${SRC_DIR}/ci/kuiper/ldd-mod $1 | grep "not found")" ]; then
echo "--- LIB NOT FOUND"
${SRC_DIR}/ci/kuiper/ldd-mod $1
exit 1
fi

for library in $("${SRC_DIR}"/ci/kuiper/ldd-mod "$1" | cut -d '>' -f 2 | awk '{print $1}')
do
# check if the library exists at that path and if it was processed already
if [ -f "${library}" ] && ! [[ "${LIBS_ARRAY[*]}" =~ "${library}" ]]; then
LIBS_ARRAY+=("${library}")
echo "---NEW: ${library}"
if [ ! -f "${LOCATION}"/"${library##*/}" ]; then
cp --verbose "${library}" "${LOCATION}"
[ -L "${library}" ] && cp --verbose "$(realpath "${library}")" "${LOCATION}"
fi
run_ldd "${library}"
fi
done
}

for arg in $BINARY; do
run_ldd "${arg}"
done
44 changes: 44 additions & 0 deletions ci/kuiper/create_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -ex
SRC_DIR=$(git rev-parse --show-toplevel)
source $SRC_DIR/ci/kuiper/kuiper_build_config.sh

# install docker
install_packages(){
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get -y install containerd.io docker-ce docker-ce-cli docker-buildx-plugin
}

create_sysroot(){
$SRC_DIR/ci/kuiper/create_sysroot.sh \
install_packages \
download_kuiper \
install_qemu \
extract_sysroot \
configure_sysroot
}

# archive the sysroot and move it next to Dockerfile in order to copy the tar in the docker image
tar_and_move_sysroot(){
pushd $STAGING_AREA
sudo tar -czvf "${SYSROOT_TAR##*/}" sysroot
sudo mv $SYSROOT_TAR $SYSROOT_DOCKER
popd
}

create_image(){
pushd ${SRC_DIR}/ci/kuiper/docker
sudo docker build --load --tag cristianbindea/scopy2-kuiper .
# sudo DOCKER_BUILDKIT=0 docker build --tag cristianbindea/scopy2-kuiper . # build the image using old backend
popd
}

install_packages
create_sysroot
tar_and_move_sysroot
create_image
27 changes: 22 additions & 5 deletions ci/kuiper/create_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ download_kuiper(){
popd
}

# install qemu needed for the sysroot configuration
install_qemu(){
sudo apt -y install qemu qemu-system qemu-user-static qemu-user
}

# mount the Kuiper image and copy the entire rootfs partition
extract_sysroot(){
sudo mkdir -p /mnt/kuiper

Expand All @@ -35,13 +37,18 @@ extract_sysroot(){
sudo umount /mnt/kuiper
sudo rm -rf /mnt/kuiper
rm -rf ${STAGING_AREA:?}/${IMAGE_FILE}
rm ${STAGING_AREA}/image*.zip
rm -rf ${STAGING_AREA}/image*.zip
}


# execute chroot inside the sysroot folder and install/remove packages using apt
configure_sysroot(){
cat << EOF | sudo chroot ${SYSROOT}
export DEBIAN_FRONTEND=noninteractive
ln -snf /usr/share/zoneinfo/Europe/Bucharest /etc/localtime && echo "Europe/Bucharest" > /etc/timezone
echo "LC_ALL=en_US.UTF-8" | tee -a /etc/environment
echo "LANG=en_US.UTF-8" | tee -a /etc/locale.conf
locale-gen en_US.UTF-8
sed -i 's/#deb-src/deb-src/' /etc/apt/sources.list
Expand Down Expand Up @@ -73,15 +80,15 @@ rm -rf /usr/lib/arm-linux-gnueabihf/libad9361.so* \
/usr/lib/libad9166.so* \
/usr/lib/pkgconfig/libad9166.pc
apt -y build-dep qt5-qmake libqt5gui5 libqt5webengine-data libqt5webkit5
apt -y build-dep qtbase5-dev || true
apt -y install build-essential gcc g++ gdb-multiarch cmake autoconf automake bison flex git wget pkg-config figlet gawk unzip libsndfile1-dev \
libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0 gdbserver \
libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0 gdbserver libspeechd-dev perl \
libgl1-mesa-dev libxcb-composite0-dev libxcb-cursor-dev libxcb-damage0-dev libxcb-xv0-dev \
libxcb-dpms0-dev libxcb-dri2-0-dev libxcb-ewmh-dev libxcb-imdkit-dev libxcb-xvmc0-dev \
libxcb-present-dev libxcb-record0-dev libxcb-res0-dev libxcb-xrm-dev libx11-xcb-dev libxcb-glx0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-xkb-dev libxkbcommon-x11-dev \
libxcb-screensaver0-dev libxcb-util0-dev libxcb-xf86dri0-dev libxcb-xtest0-dev
apt -y install libunwind-dev libsndfile1-dev mesa-utils* mesa-common-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev python libopenal-dev
apt install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
apt -y install libunwind-dev libsndfile1-dev mesa-utils* mesa-common-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev python libopenal-dev || true
apt -y install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev || true
wget https://raw.githubusercontent.com/abhiTronix/raspberry-pi-cross-compilers/master/utils/SSymlinker
sed -i 's/sudo//g' SSymlinker
Expand All @@ -94,7 +101,17 @@ chmod +x SSymlinker
./SSymlinker -s /usr/lib/arm-linux-gnueabihf/crt1.o -d /usr/lib/crt1.o
./SSymlinker -s /usr/lib/arm-linux-gnueabihf/crti.o -d /usr/lib/crti.o
EOF
}

move_and_extract_sysroot(){
if [ -f $HOME/sysroot.tar.gz ]; then
mkdir -p $STAGING_AREA
sudo tar -xf $HOME/sysroot.tar.gz --directory $STAGING_AREA
rm $HOME/sysroot.tar.gz
fi
}

fix_relativelinks(){
pushd ${STAGING_AREA}
wget $SYSROOT_RELATIVE_LINKS
chmod +x sysroot-relativelinks.py
Expand Down
59 changes: 59 additions & 0 deletions ci/kuiper/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM --platform=linux/amd64 ubuntu:20.04 AS start
SHELL ["/bin/bash", "-c"]
ARG USER=runner
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Bucharest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y apt-utils sudo git wget flex bison pkg-config make python3 pip vim
RUN groupadd -g 1000 -r $USER && \
useradd -u 1000 -g 1000 --create-home -r $USER

#Change password
RUN echo "$USER:$USER" | chpasswd

#Make sudo passwordless
RUN echo "${USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-$USER && \
usermod -aG sudo $USER && \
usermod -aG plugdev $USER

USER $USER
WORKDIR /home/${USER}



FROM start AS sysroot_builder
ARG USER=runner
ENV DEBIAN_FRONTEND=noninteractive
COPY sysroot.tar.gz /home/${USER}
RUN git clone https://github.com/analogdevicesinc/scopy -b kuiper-worflow
WORKDIR /home/${USER}/scopy
RUN ./ci/kuiper/create_sysroot.sh \
install_packages \
move_and_extract_sysroot \
fix_relativelinks
RUN ./ci/kuiper/build_qt.sh \
install_packages \
download_qt \
download_crosscompiler \
build_qt5.15.2
RUN ./ci/kuiper/kuiper_build_process.sh \
install_packages \
download_cmake \
download_crosscompiler \
clone \
build_deps



FROM start
ARG USER=runner
ENV DEBIAN_FRONTEND=noninteractive
RUN mkdir -p /home/${USER}/sysroot
COPY --from=sysroot_builder /home/${USER}/scopy/ci/kuiper/staging/sysroot/usr /home/${USER}/sysroot/usr
COPY --from=sysroot_builder /home/${USER}/scopy/ci/kuiper/staging/sysroot/share /home/${USER}/sysroot/share
COPY --from=sysroot_builder /home/${USER}/scopy/ci/kuiper/staging/sysroot/include /home/${USER}/sysroot/include
WORKDIR /home/${USER}/sysroot
RUN ln -s usr/bin bin && ln -s usr/lib lib && ln -s usr/sbin sbin
WORKDIR /home/${USER}
9 changes: 5 additions & 4 deletions ci/kuiper/kuiper_build_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ IIOEMU_BRANCH=master

STAGING_AREA=$SRC_DIR/ci/kuiper/staging
SYSROOT=$STAGING_AREA/sysroot
SYSROOT_DOCKER=$SRC_DIR/ci/kuiper/docker/sysroot
SYSROOT_TAR=$STAGING_AREA/sysroot.tar.gz
SYSROOT_DOCKER=$SRC_DIR/ci/kuiper/docker/sysroot.tar.gz
TOOLCHAIN=$STAGING_AREA/cross-pi-gcc
TOOLCHAIN_BIN=$TOOLCHAIN/bin
TOOLCHAIN_HOST="arm-linux-gnueabihf"
Expand All @@ -36,6 +37,7 @@ RUNTIME_ARMHF=$SRC_DIR/ci/kuiper/runtime-armhf

CMAKE_OPTS=(\
-DCMAKE_SYSROOT="$SYSROOT" \
-DQT_LOCATION="$QT_LOCATION" \
-DSTAGING_AREA="$STAGING_AREA" \
-DCMAKE_INSTALL_PREFIX="$SYSROOT" \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" \
Expand All @@ -45,9 +47,8 @@ CMAKE_OPTS=(\

CMAKE="$CMAKE_BIN ${CMAKE_OPTS[*]}"

QT_BUILD_LOCATION=$SYSROOT/usr/local/qt5.15
QT_SYSTEM_LOCATION=/usr/local/qt5.15

QT_BUILD_LOCATION=$QT_LOCATION # the location where Qt will be installed in the system
QT_SYSTEM_LOCATION=/usr/local/qt5.15 # the Qt location relative to the sysroot folder
CROSS_COMPILER=$STAGING_AREA/cross-pi-gcc

CROSSCOMPILER_DOWNLOAD_LINK=https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/Raspberry%20Pi%20GCC%20Cross-Compiler%20Toolchains/Bullseye/GCC%2010.2.0/Raspberry%20Pi%203A%2B%2C%203B%2B%2C%204/cross-gcc-10.2.0-pi_3%2B.tar.gz
Expand Down
Loading

0 comments on commit 9061130

Please sign in to comment.