diff --git a/ci/windows/README.md b/ci/windows/README.md new file mode 100644 index 0000000000..48045ee692 --- /dev/null +++ b/ci/windows/README.md @@ -0,0 +1,19 @@ +# scopy-mingw-build-deps + +Script that build staging environment with dependencies to build scopy. MSYS2 - https://www.msys2.org/ is required for development. To initialize the development environment, from the mingw64 shell + +git clone https://github.com/analogdevicesinc/scopy-mingw-build-deps +cd scopy-mingw-build-deps +./init_staging x86_64 +source ./build.sh +install_tools +install_deps +build_deps + + +Dockerfile available in docker folder +To build docker image. +x86_64: + docker build --progress=plain --tag scopy-build:mingw64 --build-arg BUILD_TARGET=x86_64 --isolation=hyperv --memory=16GB . +i686: + docker build --progress=plain --tag scopy-build:mingw32 --build-arg BUILD_TARGET=i686 --isolation=hyperv --memory=16GB . diff --git a/ci/windows/build.sh b/ci/windows/build.sh new file mode 100755 index 0000000000..c6318a5828 --- /dev/null +++ b/ci/windows/build.sh @@ -0,0 +1,341 @@ +#!/usr/bin/bash.exe +set -xe +# get the full directory path of the script +SRC_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source $SRC_DIR/mingw_toolchain.sh $1 $2 + +TOOLS_PKGS="\ + mingw-w64-${ARCH}-cmake\ + mingw-w64-${ARCH}-gcc\ + mingw-w64-${ARCH}-python3\ + mingw-w64-${ARCH}-python-mako\ + mingw-w64-${ARCH}-python-six\ + mingw-w64-${ARCH}-make\ + mingw-w64-${ARCH}-doxygen\ + mingw-w64-${ARCH}-pcre2\ + git\ + svn\ + vim\ + base-devel\ + mingw-w64-${ARCH}-autotools\ + libtool\ +" + #mingw-w64-${ARCH}-boost +PACMAN_SYNC_DEPS="\ + mingw-w64-${ARCH}-fftw\ + mingw-w64-${ARCH}-orc\ + mingw-w64-${ARCH}-libxml2\ + mingw-w64-${ARCH}-libzip\ + mingw-w64-${ARCH}-fftw\ + mingw-w64-${ARCH}-libzip\ + mingw-w64-${ARCH}-libffi\ + mingw-w64-${ARCH}-glib2\ + mingw-w64-${ARCH}-glibmm\ + mingw-w64-${ARCH}-doxygen\ + mingw-w64-${ARCH}-qt5\ + mingw-w64-${ARCH}-zlib\ + mingw-w64-${ARCH}-breakpad\ + mingw-w64-${ARCH}-libusb\ + mingw-w64-${ARCH}-libserialport\ +" + +install_tools() { + $PACMAN -S unzip zip + pushd $WORKFOLDER + if [ ! -f windres.exe ]; then + wget http://swdownloads.analog.com/cse/build/windres.exe.gz + gunzip windres.exe.gz + fi + + if [ ! -f dpinst.zip ]; then + wget http://swdownloads.analog.com/cse/m1k/drivers/dpinst.zip + unzip "dpinst.zip" + fi + + if [ ! -f dfu-util.zip ]; then + wget http://swdownloads.analog.com/cse/m1k/drivers/dfu-util.zip + unzip "dfu-util.zip" + fi + + if [ ! -f cv2pdb-dlls.zip ]; then + wget https://swdownloads.analog.com/cse/scopydeps/cv2pdb-dlls.zip + unzip "cv2pdb-dlls.zip" + fi + + if [ ! -f is.exe ]; then + wget https://jrsoftware.org/download.php/is.exe + fi + $PACMAN -S $TOOLS_PKGS + popd +} + +install_deps() { + $PACMAN -S $PACMAN_SYNC_DEPS + $PACMAN -U https://repo.msys2.org/mingw/${ARCH}/mingw-w64-${ARCH}-boost-1.79.0-4-any.pkg.tar.zst +} + +recurse_submodules() { + pushd $WORKFOLDER + git submodule update --init --recursive --jobs 9 + popd +} + +create_build_status_file() { + echo "Built scopy-mingw-build-deps on Appveyor" >> $BUILD_STATUS_FILE + echo "on $(date)" >> $BUILD_STATUS_FILE + echo "url: ${APPVEYOR_URL}" >> $BUILD_STATUS_FILE + echo "api_url: ${APPVEYOR_API_URL}" >> $BUILD_STATUS_FILE + echo "acc_name: ${APPVEYOR_ACCOUNT_NAME}" >> $BUILD_STATUS_FILE + echo "prj_name: ${APPVEYOR_PROJECT_NAME}" >> $BUILD_STATUS_FILE + echo "build_id: ${APPVEYOR_BUILD_ID}" >> $BUILD_STATUS_FILE + echo "build_nr: ${APPVEYOR_BUILD_NUMBER}" >> $BUILD_STATUS_FILE + echo "build_version: ${APPVEYOR_BUILD_VERSION}" >> $BUILD_STATUS_FILE + echo "job_id: ${APPVEYOR_JOB_ID}" >> $BUILD_STATUS_FILE + echo "job_name: ${APPVEYOR_JOB_NAME}" >> $BUILD_STATUS_FILE + echo "job_nr: ${APPVEYOR_JOB_NUMBER}" >> $BUILD_STATUS_FILE + echo "job_link: ${APPVEYOR_URL}/project/${APPVEYOR_ACCOUNT_NAME}/${APPVEYOR_PROJECT_NAME}/builds/${APPVEYOR_BUILD_ID}/job/${APPVEYOR_JOB_ID}" >> $BUILD_STATUS_FILE + + echo $BUILD_STATUS_FILE + + echo "Repo deps locations/files" >> $BUILD_STATUS_FILE + echo $PACMAN_REPO_DEPS >> $BUILD_STATUS_FILE + #ls ${WORKFOLDER}/old_msys_deps_${MINGW_VERSION} +} + +__clean_build_dir() { + git clean -xdf + rm -rf ${WORKFOLDER}/${CURRENT_BUILD}/build-${ARCH} + mkdir ${WORKFOLDER}/${CURRENT_BUILD}/build-${ARCH} + cd ${WORKFOLDER}/${CURRENT_BUILD}/build-${ARCH} +} + +__build_with_cmake() { + INSTALL="install" + [ -z $NO_INSTALL ] || INSTALL="" + pushd $WORKFOLDER/$CURRENT_BUILD + __clean_build_dir + eval $CURRENT_BUILD_POST_CLEAN + eval $CURRENT_BUILD_PATCHES + $CMAKE $CURRENT_BUILD_CMAKE_OPTS $WORKFOLDER/$CURRENT_BUILD + eval $CURRENT_BUILD_POST_CMAKE + make $JOBS $INSTALL + eval $CURRENT_BUILD_POST_MAKE + echo "$CURRENT_BUILD - $(git rev-parse --short HEAD)" >> $BUILD_STATUS_FILE + popd + + #clean deps folder + [ -z $INSTALL ] || rm -rf ${WORKFOLDER}/${CURRENT_BUILD}/build-${ARCH} + + # clear vars + CURRENT_BUILD_CMAKE_OPTS="" + CURRENT_BUILD_POST_CLEAN="" + CURRENT_BUILD_PATCHES="" + CURRENT_BUILD_POST_CMAKE="" + CURRENT_BUILD_POST_MAKE="" + CURRENT_BUILD="" + NO_INSTALL="" +} + +build_libiio() { + CURRENT_BUILD=libiio + CURRENT_BUILD_CMAKE_OPTS="\ + ${RC_COMPILER_OPT}\ + -DWITH_USB_BACKEND:BOOL=ON\ + -DWITH_SERIAL_BACKEND:BOOL=ON\ + -DWITH_TESTS:BOOL=ON\ + -DWITH_DOC:BOOL=OFF\ + -DCSHARP_BINDINGS:BOOL=OFF\ + -DPYTHON_BINDINGS:BOOL=OFF\ + -DHAVE_DNS_SD:BOOL=ON\ + -DENABLE_IPV6:BOOL=OFF\ + " + __build_with_cmake +} + +build_libad9361() { + echo "### Building libad9361 - branch $LIBAD9361_BRANCH" + CURRENT_BUILD=libad9361 + __build_with_cmake +} + +build_libm2k() { + CURRENT_BUILD=libm2k + CURRENT_BUILD_CMAKE_OPTS="\ + -DENABLE_PYTHON=OFF\ + -DENABLE_CSHARP=OFF\ + -DBUILD_EXAMPLES=OFF\ + -DENABLE_TOOLS=ON\ + -DINSTALL_UDEV_RULES=OFF\ + " + __build_with_cmake +} + +build_spdlog() { + [ -f "/usr/bin/x86_64-w64-mingw32-windres.exe" ] && rm -v /usr/bin/x86_64-w64-mingw32-windres.exe + ln -s /usr/bin/windres.exe /usr/bin/x86_64-w64-mingw32-windres.exe + CURRENT_BUILD=spdlog + CURRENT_BUILD_CMAKE_OPTS="\ + -DSPDLOG_BUILD_SHARED=ON\ + -DSPDLOG_BUILD_EXAMPLE=OFF\ + " + __build_with_cmake +} + +build_libsndfile() { + CURRENT_BUILD=libsndfile + CURRENT_BUILD_CMAKE_OPTS="\ + -DENABLE_EXTERNAL_LIBS=OFF\ + -DENABLE_MPEG=OFF\ + -DBUILD_PROGRAMS=OFF\ + -DBUILD_EXAMPLES=OFF\ + -DENABLE_CPACK=OFF\ + -DBUILD_SHARED_LIBS=OFF\ + -DBUILD_TESTING=OFF" + __build_with_cmake +} + +build_volk() { + CURRENT_BUILD=volk + CURRENT_BUILD_POST_CLEAN="git submodule update --init ../cpu_features" + CURRENT_BUILD_CMAKE_OPTS="\ + -DENABLE_MODTOOL=OFF\ + -DENABLE_TESTING=OFF\ + -DPYTHON_EXECUTABLE=$STAGING_DIR/bin/python3.exe\ + -DGR_PYTHON_DIR==$STAGING_DIR/lib/python3.10/site-packages\ + " + __build_with_cmake + +} + +build_gnuradio() { + CURRENT_BUILD=gnuradio + CURRENT_BUILD_CMAKE_OPTS="\ + -DENABLE_DEFAULT=OFF\ + -DENABLE_GNURADIO_RUNTIME=ON\ + -DENABLE_GR_ANALOG=ON\ + -DENABLE_GR_BLOCKS=ON\ + -DENABLE_GR_FFT=ON\ + -DENABLE_GR_FILTER=ON\ + -DENABLE_VOLK=ON\ + -DENABLE_GR_IIO=ON\ + -DCMAKE_C_FLAGS=-fno-asynchronous-unwind-tables\ + -DPYTHON_EXECUTABLE=$STAGING_DIR/bin/python3.exe\ + -DGR_PYTHON_DIR==$STAGING_DIR/lib/python3.10/site-packages\ + " + __build_with_cmake +} + +build_grm2k() { + CURRENT_BUILD=gr-m2k + CURRENT_BUILD_CMAKE_OPTS="\ + -DPYTHON_EXECUTABLE=$STAGING_DIR/bin/python3.exe\ + -DGR_PYTHON_DIR==$STAGING_DIR/lib/python3.10/site-packages\ + " + __build_with_cmake +} + +build_grscopy() { + CURRENT_BUILD=gr-scopy + CURRENT_BUILD_CMAKE_OPTS="\ + -DPYTHON_EXECUTABLE=$STAGING_DIR/bin/python3.exe\ + -DGR_PYTHON_DIR=$STAGING_DIR/lib/python3.10/site-packages\ + " + __build_with_cmake +} + +build_qwt() { + echo "### Building qwt - branch $QWT_BRANCH" + CURRENT_BUILD=qwt + pushd $WORKFOLDER/$CURRENT_BUILD + git clean -xdf + $QMAKE qwt.pro + VERBOSE=1 make LDFLAGS="-Wl,verbose" $JOBS + make INSTALL_ROOT="$STAGING_DIR" $JOBS install + cp $STAGING_DIR/lib/qwt.dll $STAGING_DIR/bin/qwt.dll + echo "$CURRENT_BUILD - $(git rev-parse --short HEAD)" >> $BUILD_STATUS_FILE + popd +} + +build_libsigrokdecode() { + echo "### Building libsigrokdecode - branch $LIBSIGROKDECODE_BRANCH" + CURRENT_BUILD=libsigrokdecode + + pushd $WORKFOLDER/$CURRENT_BUILD + if [ -d "$WORKFOLDER/libsigrokdecode/build-$ARCH" ]; then + # hack .. this gets messed up somehow in docker due to changing files to lowercase + git reset --hard + git clean -xdf + fi + + rm -rf ${WORKFOLDER}/libsigrokdecode/build-${ARCH} + mkdir -p ${WORKFOLDER}/libsigrokdecode/build-${ARCH} + cd ${WORKFOLDER}/libsigrokdecode + + patch -p1 < ${WORKFOLDER}/sigrokdecode-windows-fix.patch + ./autogen.sh + cd build-${ARCH} + + CPPFLAGS="-DLIBSIGROKDECODE_EXPORT=1" ../configure ${AUTOCONF_OPTS} + $MAKE_BIN $JOBS install + rm -rf ${WORKFOLDER}/libsigrokdecode/build-${ARCH} + echo "$CURRENT_BUILD - $(git rev-parse --short HEAD)" >> $BUILD_STATUS_FILE + popd +} + +build_libtinyiiod() { + echo "### Building libtinyiiod - branch $LIBTINYIIOD_BRANCH" + CURRENT_BUILD=libtinyiiod + CURRENT_BUILD_CMAKE_OPTS="-DBUILD_EXAMPLES=OFF" + __build_with_cmake +} + +build_scopy() { + CURRENT_BUILD=scopy + NO_INSTALL="TRUE" + CURRENT_BUILD_CMAKE_OPTS="$RC_COMPILER_OPT\ + -DBREAKPAD_HANDLER=ON\ + -DWITH_DOC=ON\ + -DPYTHON_EXECUTABLE=$STAGING_DIR/bin/python3.exe\ + -DENABLE_PLUGIN_M2K=ON + -DEMBED_PYTHON=ON + " + __build_with_cmake +} + +write_status_file() { + echo "" >> $BUILD_STATUS_FILE + echo "$PACMAN -Qe output - all explicitly installed packages on build machine" >> $BUILD_STATUS_FILE + $PACMAN -Qe >> $BUILD_STATUS_FILE + echo "pacman -Qm output - all packages from nonsync sources" >> $BUILD_STATUS_FILE + $PACMAN -Qm >> $BUILD_STATUS_FILE + cp $BUILD_STATUS_FILE ${WORKFOLDER}/scopy-$MINGW_VERSION-build-status-file.txt + echo -n ${PACMAN_SYNC_DEPS} > ${WORKFOLDER}/scopy-$MINGW_VERSION-build-deps-pacman.txt +} + +build_deps() { + build_libiio + build_libad9361 + build_libm2k + build_spdlog + build_libsndfile + build_volk + build_gnuradio + build_grscopy + build_grm2k + build_qwt + build_libsigrokdecode + build_libtinyiiod +} + + +for arg in $@; do + $arg +done + +#recurse_submodules +#install_tools +#install_deps +#create_build_status_file +#build_deps +#build_scopy # for testing +#package_and_push diff --git a/ci/windows/docker/Dockerfile b/ci/windows/docker/Dockerfile new file mode 100644 index 0000000000..283a8811ce --- /dev/null +++ b/ci/windows/docker/Dockerfile @@ -0,0 +1,44 @@ +# select as base image matching your host to get process isolation +FROM mcr.microsoft.com/windows/servercore:ltsc2019 + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] +# this creates an empty file named recycle.bin which essentialy disables the recycle bin +# this hack is needed because msys seems to create some files with wierd names in recycle bin +# that freeze the docker layer when commiting +# dirty hack +RUN echo . > 'C:\$RECYCLE.BIN'; + +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \ +Invoke-WebRequest -UseBasicParsing -uri "https://github.com/msys2/msys2-installer/releases/download/2023-01-27/msys2-base-x86_64-20230127.sfx.exe" -OutFile msys2.exe; \ +.\msys2.exe -y -oC:\\; \ +Remove-Item msys2.exe; +RUN 'mkdir C:/msys64/home/docker/ && cd C:/msys64/home/docker/' + +SHELL ["cmd", "/S", "/C"] +# set envvars PATH HOME CHERE_INVOKING MSYS_SYSTEM - https://www.msys2.org/docs/ci/#other-systems +RUN setx PATH C:\msys64\bin;C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH% & \ +setx HOME C:\msys64\home\docker & \ +setx CHERE_INVOKING yes & \ +setx MSYSTEM MINGW64 + +WORKDIR C:\\msys64\\home\\docker +RUN C:\msys64\usr\bin\bash.exe -lc " " +SHELL ["cmd", "/S", "/C"] +RUN C:\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Syyu" +RUN C:\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Sy msys2-keyring" +RUN C:\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Su" +RUN C:\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Syuu" & C:\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Syuu" & C:\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Scc " +# install general packages needed to run build scripts +RUN C:\msys64\usr\bin\bash.exe -c 'pacman --noconfirm --needed -Sy git' +RUN C:\msys64\usr\bin\bash.exe -c "git clone https://github.com/analogdevicesinc/scopy-mingw-build-deps --branch ci-for-scopy2" + +# install packages and build scopy-deps +RUN C:\msys64\usr\bin\bash.exe -c "/home/docker/scopy-mingw-build-deps/build.sh install_tools install_deps recurse_submodules" +RUN C:\msys64\home\docker\scopy-mingw-build-deps\is.exe /VERYSILENT /SP- /SUPPRESSMSGBOXES /NORESTART /LOG=C:\msys64\home\docker\iss.log /DIR=C:\innosetup +RUN C:\msys64\usr\bin\bash.exe -c "/home/docker/scopy-mingw-build-deps/build.sh build_deps" +# clone scopy + +# build scopy + + + diff --git a/ci/windows/init_staging.sh b/ci/windows/init_staging.sh new file mode 100644 index 0000000000..d0fa24fadd --- /dev/null +++ b/ci/windows/init_staging.sh @@ -0,0 +1,14 @@ +#!/usr/bin/bash.exe +#set -ex + +init_staging() { + if [ "$USE_STAGING" == "ON" ] + then + source mingw_toolchain.sh ON + rm -rf $STAGING_ENV + mkdir -p $STAGING_ENV/var/lib/pacman/local + mkdir -p $STAGING_ENV/var/lib/pacman/sync + /usr/bin/bash.exe -c "$PACMAN -Syuu bash filesystem mintty pacman" + fi +} +init_staging diff --git a/ci/windows/mingw_toolchain.sh b/ci/windows/mingw_toolchain.sh new file mode 100644 index 0000000000..c64b6cfc32 --- /dev/null +++ b/ci/windows/mingw_toolchain.sh @@ -0,0 +1,74 @@ +#!/usr/bin/bash.exe + +set -ex +export MINGW_VERSION=mingw64 +export ARCH=x86_64 +# get the full directory path of the script +export WORKFOLDER=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +USE_STAGING=$1 +STAGING_PREFIX=$2 + +if [ ! -z "$USE_STAGING" ] && [ "$USE_STAGING" == "ON" ] + then + echo -- USING STAGING + export USE_STAGING="ON" + if [ -z "$STAGING_PREFIX" ] + then + STAGING_PREFIX="staging" + export STAGING_ENV=$WORKFOLDER/staging_$ARCH + else + echo -- STAGING_PREFIX:$STAGING_PREFIX + export STAGING_ENV=${STAGING_PREFIX}_${ARCH} + fi + export STAGING=${STAGING_PREFIX}_${ARCH} + export STAGING_DIR=${WORKFOLDER}/${STAGING}/${MINGW_VERSION} + export PACMAN="pacman -r $STAGING_ENV --noconfirm --needed" + else + echo -- NO STAGING + export USE_STAGING=OFF + export STAGING_DIR=/${MINGW_VERSION} + export STAGING_ENV="" + export PACMAN="pacman --noconfirm --needed" +fi + +export RC_COMPILER_OPT="-DCMAKE_RC_COMPILER=/mingw64/bin/windres.exe" +export PATH="/bin:$STAGING_DIR/bin:$WORKFOLDER/cv2pdb:/c/Program Files (x86)/Inno Setup 6:/c/innosetup/:/bin:/usr/bin:${STAGING_DIR}/bin:/c/Program\ Files/Git/cmd:/c/Windows/System32:/c/Program\ Files/Appveyor/BuildAgent:$PATH" +export QMAKE=${STAGING_DIR}/bin/qmake +export PKG_CONFIG_PATH=$STAGING_DIR/lib/pkgconfig +export CC=${STAGING_DIR}/bin/${ARCH}-w64-mingw32-gcc.exe +export CXX=${STAGING_DIR}/bin/${ARCH}-w64-mingw32-g++.exe +export JOBS="-j9" +export MAKE_BIN=$STAGING_ENV/usr/bin/make.exe +export MAKE_CMD="$MAKE_BIN $JOBS" +export CMAKE_GENERATOR="Unix Makefiles" +export CMAKE_OPTS=( \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_C_COMPILER:FILEPATH=${CC} \ + -DCMAKE_CXX_COMPILER:FILEPATH=${CXX} \ + -DCMAKE_MAKE_PROGRAM:FILEPATH=${MAKE_BIN}\ + -DPKG_CONFIG_EXECUTABLE=${STAGING_DIR}/bin/pkg-config.exe \ + -DCMAKE_MODULE_PATH=$STAGING_DIR \ + -DCMAKE_PREFIX_PATH=$STAGING_DIR/lib/cmake \ + -DCMAKE_STAGING_PREFIX=$STAGING_DIR \ + -DCMAKE_INSTALL_PREFIX=$STAGING_DIR \ +) +export CMAKE="${STAGING_DIR}/bin/cmake ${CMAKE_OPTS[@]} " + +export AUTOCONF_OPTS="--prefix=$STAGING_DIR \ + --host=${ARCH}-w64-mingw32 \ + --enable-shared \ + --disable-static" + +BUILD_STATUS_FILE=/tmp/scopy-mingw-build-status +touch $BUILD_STATUS_FILE + +echo -- MAKE_BIN:$MAKE_BIN +echo -- STAGING_DIR:$STAGING_DIR +echo -- STAGING_ENV:$STAGING_ENV +echo -- MINGW_VERSION:$MINGW_VERSION +echo -- TARGET ARCH:$ARCH +echo -- PATH:$PATH +echo -- USING CMAKE COMMAND +echo $CMAKE +echo diff --git a/ci/windows/sigrokdecode-windows-fix.patch b/ci/windows/sigrokdecode-windows-fix.patch new file mode 100644 index 0000000000..48c0981608 --- /dev/null +++ b/ci/windows/sigrokdecode-windows-fix.patch @@ -0,0 +1,21 @@ +commit 1b13802e324f00f4e840eff7b0f3b6761fffa1a1 +Author: Bindea Cristian +Date: Thu Mar 2 16:07:15 2023 +0200 + + Subject: [PATCH] Update public functions visibility on Windows + + Signed-off-by: Bindea Cristian + +diff --git a/libsigrokdecode.h b/libsigrokdecode.h +index ea17cb8..acc2cbc 100644 +--- a/libsigrokdecode.h ++++ b/libsigrokdecode.h +@@ -112,6 +112,8 @@ enum srd_loglevel { + # else + # define SRD_API extern + # endif ++#elif defined(LIBSIGROKDECODE_EXPORT) ++# define SRD_API __declspec(dllexport) + #else + # define SRD_API __attribute__((visibility("default"))) + #endif