diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 755e8f4e14..bf7e074a2a 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -2,13 +2,24 @@ # Copyright (C) 2020 by Tarek BOUCHKATI -on: push +on: + push: + branches: + - main + workflow_dispatch: + pull_request: -name: OpenOCD Snapshot +name: OpenOCD Build jobs: package: - runs-on: [ubuntu-latest] + strategy: + matrix: + target: [x86_64-pc-linux-gnu] + # For now, Windows build is brokewn + # target: [x86_64-pc-linux-gnu, i686-w64-mingw32] + # Use the same as the devcontainer + runs-on: [ubuntu-24.04] env: DL_DIR: ../downloads BUILD_DIR: ../build @@ -16,7 +27,7 @@ jobs: - name: Install needed packages run: | sudo apt-get update - sudo apt-get install autotools-dev autoconf automake libtool pkg-config cmake texinfo texlive g++-mingw-w64-i686 + sudo apt-get install autotools-dev autoconf automake libtool pkg-config cmake texinfo texlive g++-mingw-w64-i686 g++ libudev-dev - name: Checkout Code uses: actions/checkout@v4 - run: ./bootstrap @@ -74,11 +85,12 @@ jobs: wget https://github.com/msteveb/jimtcl/archive/refs/tags/${JIMTCL_VER}.tar.gz tar -xzf ${JIMTCL_VER}.tar.gz echo "JIMTCL_SRC=$PWD/jimtcl-${JIMTCL_VER}" >> $GITHUB_ENV - - name: Package OpenOCD for windows + - name: Package OpenOCD env: MAKE_JOBS: 2 - HOST: i686-w64-mingw32 - LIBUSB1_CONFIG: --enable-shared --disable-static + HOST: ${{ matrix.target }} + # LIBUSB1_CONFIG: --enable-shared --disable-static + LIBUSB1_CONFIG: --enable-static --disable-shared HIDAPI_CONFIG: --enable-shared --disable-static --disable-testgui LIBFTDI_CONFIG: -DSTATICLIBS=OFF -DEXAMPLES=OFF -DFTDI_EEPROM=OFF CAPSTONE_CONFIG: "CAPSTONE_BUILD_CORE_ONLY=yes CAPSTONE_STATIC=yes CAPSTONE_SHARED=no" @@ -97,35 +109,28 @@ jobs: export OPENOCD_TAG=$OPENOCD_TAG export OPENOCD_SRC=$PWD export OPENOCD_CONFIG="" - mkdir -p $BUILD_DIR && cd $BUILD_DIR - bash $OPENOCD_SRC/contrib/cross-build.sh $HOST - # add missing dlls - cd $HOST-root/usr - cp `$HOST-gcc --print-file-name=libwinpthread-1.dll` ./bin/ - # required by libftdi1.dll - cp `$HOST-gcc --print-file-name=libgcc_s_dw2-1.dll` ./bin/ + BUILD_DIR=$(realpath "$BUILD_DIR") + export PREFIX=/usr + mkdir -p $BUILD_DIR && cd $BUILD_DIR + + + if [[ "$HOST" == *"linux"* ]]; then + bash $OPENOCD_SRC/contrib/localbuild.sh + elif [[ "$HOST" == *"w64"* ]]; then + # add missing dlls for Windows and cross build + bash $OPENOCD_SRC/contrib/cross-build.sh $HOST + cd $HOST-root/usr + cp `$HOST-gcc --print-file-name=libwinpthread-1.dll` ./bin/ + # required by libftdi1.dll + cp `$HOST-gcc --print-file-name=libgcc_s_dw2-1.dll` ./bin/ + fi # prepare the artifact ARTIFACT="openocd-${OPENOCD_TAG}-${HOST}.tar.gz" tar -czf $ARTIFACT * echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV echo "IS_PRE_RELEASE=$IS_PRE_RELEASE" >> $GITHUB_ENV echo "ARTIFACT_PATH=$PWD/$ARTIFACT" >> $GITHUB_ENV - - name: Publish OpenOCD packaged for windows + - name: Publish OpenOCD uses: actions/upload-artifact@v4 with: path: ${{ env.ARTIFACT_PATH }} - - name: Delete 'latest' Release - uses: dev-drprasad/delete-tag-and-release@v1.1 - with: - delete_release: true - tag_name: ${{ env.RELEASE_NAME }} - github_token: ${{ secrets.GITHUB_TOKEN }} - - name: Create Release - uses: ncipollo/release-action@v1 - with: - tag: ${{ env.RELEASE_NAME }} - commit: ${{ github.sha }} - draft: false - artifacts: ${{ env.ARTIFACT_PATH }} - prerelease: ${{ env.IS_PRE_RELEASE }} - token: ${{ secrets.GITHUB_TOKEN }} diff --git a/contrib/localbuild.sh b/contrib/localbuild.sh new file mode 100755 index 0000000000..0e48b01672 --- /dev/null +++ b/contrib/localbuild.sh @@ -0,0 +1,139 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later + +# This is an example of how to do a cross-build of OpenOCD using pkg-config. +# Cross-building with pkg-config is deceptively hard and most guides and +# tutorials are incomplete or give bad advice. Some of the traps that are easy +# to fall in but handled by this script are: +# +# * Polluting search paths and flags with values from the build system. +# * Faulty pkg-config wrappers shipped with distribution packaged cross- +# toolchains. +# * Build failing because pkg-config discards some paths even though they are +# correctly listed in the .pc file. +# * Getting successfully built binaries that cannot find runtime data because +# paths refer to the build file system. +# +# This script is probably more useful as a reference than as a complete build +# tool but for some configurations it may be usable as-is. It only cross-builds +# libusb-1.0, hidapi, libftdi and capstone from source, but the script can be +# extended to build other prerequisites in a similar manner. +# +# Usage: +# export LIBUSB1_SRC=/path/to/libusb-1.0 +# export HIDAPI_SRC=/path/to/hidapi +# export OPENOCD_CONFIG="--enable-..." +# cd /work/dir +# /path/to/openocd/contrib/cross-build.sh +# +# For static linking, a workaround is to +# export LIBUSB1_CONFIG="--enable-static --disable-shared" +# +# All the paths must not contain any spaces. + +set -e -x + +WORK_DIR=$PWD + +## Source code paths, customize as necessary +: ${OPENOCD_SRC:="`dirname "$0"`/.."} +: ${LIBUSB1_SRC:=/path/to/libusb1} +: ${HIDAPI_SRC:=/path/to/hidapi} +: ${LIBFTDI_SRC:=/path/to/libftdi} +: ${CAPSTONE_SRC:=/path/to/capstone} +: ${LIBJAYLINK_SRC:=/path/to/libjaylink} +: ${JIMTCL_SRC:=/path/to/jimtcl} + +OPENOCD_SRC=`readlink -m $OPENOCD_SRC` +LIBUSB1_SRC=`readlink -m $LIBUSB1_SRC` +HIDAPI_SRC=`readlink -m $HIDAPI_SRC` +LIBFTDI_SRC=`readlink -m $LIBFTDI_SRC` +CAPSTONE_SRC=`readlink -m $CAPSTONE_SRC` +LIBJAYLINK_SRC=`readlink -m $LIBJAYLINK_SRC` +JIMTCL_SRC=`readlink -m $JIMTCL_SRC` + +BUILD_DIR=$WORK_DIR/build +LIBUSB1_BUILD_DIR=$BUILD_DIR/libusb1 +HIDAPI_BUILD_DIR=$BUILD_DIR/hidapi +LIBFTDI_BUILD_DIR=$BUILD_DIR/libftdi +CAPSTONE_BUILD_DIR=$BUILD_DIR/capstone +LIBJAYLINK_BUILD_DIR=$BUILD_DIR/libjaylink +JIMTCL_BUILD_DIR=$BUILD_DIR/jimtcl +OPENOCD_BUILD_DIR=$BUILD_DIR/openocd + +## Root of host file tree +SYSROOT=$WORK_DIR/root + +## Install location within host file tree +: ${PREFIX=/usr} + +## Make parallel jobs +: ${MAKE_JOBS:=1} + +## OpenOCD-only install dir for packaging +: ${OPENOCD_TAG:=`git --git-dir=$OPENOCD_SRC/.git describe --tags`} +PACKAGE_DIR=$WORK_DIR/openocd_${OPENOCD_TAG} + +####### + +# Create pkg-config wrapper and make sure it's used +export PKG_CONFIG=$WORK_DIR/pkg-config + +cat > $PKG_CONFIG <