Skip to content

Commit

Permalink
test kuiper workflow
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 18, 2024
1 parent 8f23f1c commit d4c5770
Show file tree
Hide file tree
Showing 18 changed files with 1,106 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/kuiperbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Kuiper Scopy Build

on: [push, pull_request]

env:
BUILD_HOST: ubuntu-20.04
USERNAME: github-actions

jobs:

build_scopy1_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/scopy1-kuiper:latest

- name: Create Scopy AppImage
shell: bash
run: |
cd $GITHUB_WORKSPACE
sudo apt update
./CI/kuiper/create_sysroot.sh install_packages install_qemu
./CI/kuiper/kuiper_build_process.sh generate_ci_envs
docker run \
--mount type=bind,source="$GITHUB_WORKSPACE",target=/home/runner/scopy \
--env-file $GITHUB_WORKSPACE/CI/kuiper/gh-actions.envs \
cristianbindea/scopy2-kuiper:latest \
/bin/bash -c 'cd $HOME && \
sudo chown -R runner:runner scopy && \
cd $HOME/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 }}
path: ${{ github.workspace }}/Scopy-armhf.AppImage
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ android*.sh
*.apk
*.aab
!CI/android/*
CI/kuiper/staging
CI/kuiper/scopy.AppDir
html/
build_arm64-v8a/
12 changes: 12 additions & 0 deletions CI/kuiper/AppRun
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/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

ldd $HERE/usr/bin/scopy

exec $HERE/usr/bin/scopy
75 changes: 75 additions & 0 deletions CI/kuiper/build_qt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

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

install_packages(){
sudo apt install -y build-essential cmake unzip gfortran gcc git bison \
python gperf pkg-config gdb-multiarch g++ flex texinfo gawk openssl \
pigz libncurses-dev autoconf automake tar figlet libclang-dev
}

# Download and extract QT Source (QT 5.15.2)
download_qt(){
mkdir -p ${STAGING_AREA}
pushd ${STAGING_AREA}
if [ ! -d qt-everywhere-src ];then
wget --progress=dot:giga ${QT_DOWNLOAD_LINK}
tar -xf qt-everywhere-src-*.tar.xz && rm qt-everywhere-src-*.tar.xz && mv qt-everywhere-src-* qt-everywhere-src # unzip and rename
cd qt-everywhere-src
patch -p1 < $SRC_DIR/CI/kuiper/qt_patch.patch # Patch QT Source
else
echo "QT already downloaded"
fi
popd
}

download_crosscompiler(){
mkdir -p ${STAGING_AREA}
pushd ${STAGING_AREA}
if [ ! -d cross-pi-gcc ];then
wget --progress=dot:giga ${CROSSCOMPILER_DOWNLOAD_LINK}
tar -xf cross-gcc-*.tar.gz && rm cross-gcc-*.tar.gz && mv cross-pi-* cross-pi-gcc # unzip and rename
else
echo "Crosscompiler already downloaded"
fi
popd
}

build_qt5.15.2(){
mkdir -p $STAGING_AREA/build-qt5.15.2 && cd $STAGING_AREA/build-qt5.15.2
../qt-everywhere-src/configure \
-v \
-release \
-opensource \
-confirm-license \
-sysroot $SYSROOT \
-prefix $QT_SYSTEM_LOCATION \
-extprefix $QT_BUILD_LOCATION \
-eglfs \
-opengl es2 \
-device linux-rasp-pi4-v3d-g++ \
-device-option CROSS_COMPILE=$CROSS_COMPILER/bin/arm-linux-gnueabihf- \
-skip qtscript \
-skip qtwayland \
-skip qtwebengine \
-nomake tests \
-make libs \
-pkg-config \
-no-use-gold-linker \
-recheck \
-xcb \
-xcb-xlib \
-bundled-xcb-xinput \
-qt-pcre \
-qpa eglfs \
-L$SYSROOT/usr/lib/arm-linux-gnueabihf -I$SYSROOT/usr/include/arm-linux-gnueabihf

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

for arg in $@; do
$arg
done
89 changes: 89 additions & 0 deletions CI/kuiper/cmake_toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
cmake_minimum_required(VERSION 3.18)

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
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 ${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)

set(PKG_CONFIG_EXECUTABLE "${CMAKE_SYSROOT}/usr/bin/arm-linux-gnueabihf-pkg-config" CACHE PATH "PKG_CONFIG_EXECUTABLE"
FORCE
)
set(ENV{PKG_CONFIG_ALLOW_CROSS} 1)
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
set(RPI_PKG_CONFIG_LIBDIR "${CMAKE_SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig:${RPI_PKG_CONFIG_LIBDIR}")
set(RPI_PKG_CONFIG_LIBDIR "${CMAKE_SYSROOT}/usr/share/pkgconfig:${RPI_PKG_CONFIG_LIBDIR}")
set(RPI_PKG_CONFIG_LIBDIR "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${RPI_PKG_CONFIG_LIBDIR}")
set(RPI_PKG_CONFIG_LIBDIR "${CMAKE_SYSROOT}/usr/local/lib/pkgconfig:${RPI_PKG_CONFIG_LIBDIR}")
set(ENV{PKG_CONFIG_LIBDIR} "${RPI_PKG_CONFIG_LIBDIR}")
set(ENV{PKG_CONFIG} "${CMAKE_SYSROOT}/usr/bin/arm-linux-gnueabihf-pkg-config")

set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${CMAKE_SYSROOT}/include:")
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${CMAKE_SYSROOT}/usr/include:")
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${CMAKE_SYSROOT}/usr/include/arm-linux-gnueabihf:")
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${CMAKE_SYSROOT}/usr/share/include:")

set(ENV{PKG_CONFIG_SYSROOT_DIR} "${CMAKE_SYSROOT}")
set(ENV{LD_LIBRARY_PATH} "${CMAKE_SYSROOT}/usr/lib/arm-linux-gnueabihf:$ENV{LD_LIBRARY_PATH}")

set(CMAKE_LIBRARY_PATH "${CMAKE_SYSROOT}/usr/lib")
set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH} ${CMAKE_SYSROOT}/usr/lib/arm-linux-gnueabihf")
set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH} ${CMAKE_SYSROOT}/usr/local/lib")
set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH} ${CMAKE_SYSROOT}/usr/local/lib/arm-linux-gnueabihf")

set(CMAKE_AR ${TOOLCHAIN_BIN}/arm-linux-gnueabihf-ar)
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN}/arm-linux-gnueabihf-gcc)
set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN}/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN}/arm-linux-gnueabihf-g++)
set(CMAKE_LINKER ${TOOLCHAIN_BIN}/arm-linux-gnueabihf-ld)
set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN}/arm-linux-gnueabihf-objcopy)
set(CMAKE_RANLIB ${TOOLCHAIN_BIN}/arm-linux-gnueabihf-ranlib)
set(CMAKE_SIZE ${TOOLCHAIN_BIN}/arm-linux-gnueabihf-size)
set(CMAKE_STRIP ${TOOLCHAIN_BIN}/arm-linux-gnueabihf-strip)

set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=vfp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SYSROOT}/include")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SYSROOT}/usr/include")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SYSROOT}/usr/include/arm-linux-gnueabihf")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SYSROOT}/usr/share/include")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "-fexceptions -frtti ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "-Os -g")
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})

#[[
# Debug Mode
set(PKG_CONFIG_ARGN "--debug")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--verbose ")
]]

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"
"/usr/lib/arm-linux-gnueabihf"
"/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)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
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
68 changes: 68 additions & 0 deletions CI/kuiper/create_sysroot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

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

IMAGE_FILE=2023-12-13-ADI-Kuiper-full.img

install_packages(){
sudo apt -y install git wget unzip python3 python
}

download_kuiper(){
mkdir -p ${STAGING_AREA}
pushd ${STAGING_AREA}
wget --progress=dot:giga ${KUIPER_DOWNLOAD_LINK}
unzip image*.zip
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

# with file ${IMAGE_FILE} we can see the start sector (4218880) and the length (19947520) of the second partition contained in the Kuiper image
# using this info we can directly mount that partition
sudo mount -v -o loop,offset=$((512*4218880)),sizelimit=$((512*19947520)) ${STAGING_AREA}/${IMAGE_FILE} /mnt/kuiper

mkdir -p ${SYSROOT}
sudo cp -arp /mnt/kuiper/* ${SYSROOT}
sudo cp /etc/resolv.conf ${SYSROOT}/etc/resolv.conf
sudo umount /mnt/kuiper
sudo rm -rf /mnt/kuiper
rm -rf ${STAGING_AREA:?}/${IMAGE_FILE}
rm -rf ${STAGING_AREA}/image*.zip
}


# execute chroot inside the sysroot folder and install/remove packages using apt
configure_sysroot(){
cat $SRC_DIR/CI/kuiper/inside_chroot.sh | sudo chroot ${SYSROOT}
}

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
sudo ./sysroot-relativelinks.py ${SYSROOT}
popd
}

for arg in $@; do
$arg
done

Loading

0 comments on commit d4c5770

Please sign in to comment.