diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml new file mode 100644 index 0000000..98e7961 --- /dev/null +++ b/.github/workflows/build-linux.yml @@ -0,0 +1,141 @@ +name: Build Linux + +on: + push: + branches-ignore: + - 'coverityScan' + pull_request: + branches: + - 'main' + +concurrency: + group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-linux: + name: '${{ matrix.os.id }} (${{ matrix.compiler }})' + runs-on: ${{ matrix.os.id }} + strategy: + matrix: + os: + - { id: ubuntu-22.04, name: jammy } + compiler: + - 'clang-13' + - 'clang-15' + - 'clang-16' + - 'clang-17' + - 'gcc-9' + - 'gcc-11' + - 'gcc-12' + - 'gcc-13' + fail-fast: false + env: + BUILD_OPTS: '' + steps: + - name: Runtime environment + shell: bash + env: + WORKSPACE: ${{ github.workspace }} + run: | + echo "$HOME/.local/bin" >> $GITHUB_PATH + echo "GITHUB_WORKSPACE=`pwd`" >> $GITHUB_ENV + - name: Setup GCC + if: startsWith(matrix.compiler, 'gcc') + shell: bash + run: | + CXX=${CC/#gcc/g++} + sudo apt-add-repository ppa:ubuntu-toolchain-r/test + sudo apt-get update + sudo apt-get install $CC $CXX + echo "CC=$CC" >> $GITHUB_ENV + echo "CXX=$CXX" >> $GITHUB_ENV + echo "GCOV=${CC/#gcc/gcov}" >> $GITHUB_ENV + env: + CC: ${{ matrix.compiler }} + - name: Setup Clang + if: startsWith(matrix.compiler, 'clang') + shell: bash + run: | + wget https://apt.llvm.org/llvm-snapshot.gpg.key + sudo apt-key add llvm-snapshot.gpg.key + rm llvm-snapshot.gpg.key + sudo apt-add-repository "deb https://apt.llvm.org/${{ matrix.os.name }}/ llvm-toolchain-${{ matrix.os.name }}${CC/#clang/} main" + sudo apt-get update + sudo apt-get install $CC + CXX=${CC/#clang/clang++} + echo "CC=$CC" >> $GITHUB_ENV + echo "CXX=$CXX" >> $GITHUB_ENV + echo "GCOV=${CC/#clang/llvm-cov} gcov" >> $GITHUB_ENV + env: + CC: ${{ matrix.compiler }} + working-directory: ${{ runner.temp }} + - name: Remove old LLVM 12 plugins + if: matrix.compiler != 'clang-12' + run: | + sudo apt purge llvm-12-linker-tools + - name: Remove old LLVM 13 plugins + if: matrix.compiler != 'clang-13' + run: | + sudo apt purge llvm-13-linker-tools + - name: Remove old LLVM 14 plugins + if: matrix.compiler != 'clang-14' + run: | + sudo apt purge llvm-14-linker-tools + - name: Remove old LLVM 15 plugins + if: matrix.compiler != 'clang-15' + run: | + sudo apt purge llvm-15-linker-tools + - name: Install dependencies + shell: bash + run: sudo apt-get install libudev-dev + - name: Checkout + uses: actions/checkout@v3 + with: + lfs: true + submodules: true + - name: Setup Meson + Ninja + gcovr + shell: bash + run: | + sudo python3 -m pip install --upgrade pip setuptools wheel + python3 -m pip install --user meson ninja gcovr + working-directory: ${{ runner.temp }} + - name: Version tools + shell: bash + run: | + $CC --version + $CXX --version + $GCOV --version + meson --version + ninja --version + - name: Configure + run: meson setup build --prefix=$HOME/.local $BUILD_OPTS + - name: Build + run: meson compile -C build + - name: Test + run: meson test -C build + - name: Install + run: meson install -C build + - name: Run coverage build + if: github.repository == 'blackmagic-debug/bmpflash' && matrix.compiler != 'clang-17' + # Codecov no longer parses gcov files automatically + run: | + rm -rf build + meson setup build --prefix=$HOME/.local -Db_coverage=true --buildtype=debug + meson compile -C build + meson test -C build + ninja -C build coverage-xml + - name: Upload failure logs + if: failure() + uses: actions/upload-artifact@v3 + with: + name: logs-${{ matrix.os.id }}-${{ matrix.compiler }} + path: ${{ github.workspace }}/build/meson-logs/* + retention-days: 5 + - name: Codecov + if: success() && github.repository == 'blackmagic-debug/bmpflash' && matrix.compiler != 'clang-17' + uses: codecov/codecov-action@v3 + with: + directory: ./build/meson-logs/ + files: coverage.xml + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml new file mode 100644 index 0000000..98e3088 --- /dev/null +++ b/.github/workflows/build-macos.yml @@ -0,0 +1,176 @@ +name: Build macOS + +on: + push: + branches-ignore: + - 'coverityScan' + pull_request: + branches: + - 'main' + +concurrency: + group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-macos: + name: '${{ matrix.os }} (Apple Clang)' + runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash + strategy: + matrix: + os: + - macos-12 + - macos-11 + build_opts: + - '' + include: + # static+LTO forced build to uncover any potential symbols issues with Mach-O + # single test to save runners as they are scarse and should validate all possible configurations + - os: macos-latest + build_opts: '-Db_lto=true -Ddefault_library=static' + fail-fast: false + env: + BUILD_OPTS: ${{ matrix.build_opts }} + steps: + - name: Runtime environment + env: + WORKSPACE: ${{ github.workspace }} + run: | + echo "GITHUB_WORKSPACE=`pwd`" >> $GITHUB_ENV + - name: Checkout + uses: actions/checkout@v3 + with: + lfs: true + submodules: true + - name: Setup Meson + Ninja + gcovr + run: | + brew install meson ninja gcovr + working-directory: ${{ runner.temp }} + - name: Version tools + run: | + cc --version || true + ld --version || true + gcov --version || true + meson --version + ninja --version + - name: Configure + run: meson setup build --prefix=$HOME/.local $BUILD_OPTS + - name: Build + run: meson compile -C build + - name: Test + run: meson test -C build + - name: Install + run: meson install -C build + - name: Run coverage build + if: github.repository == 'blackmagic-debug/bmpflash' + # Codecov no longer parses gcov files automatically + run: | + rm -rf build + meson setup build --prefix=$HOME/.local -Db_coverage=true --buildtype=debug $BUILD_OPTS + meson compile -C build + meson test -C build + ninja -C build coverage-xml + - name: Upload failure logs + if: failure() + uses: actions/upload-artifact@v3 + with: + name: logs-${{ matrix.os }}-appleclang + path: ${{ github.workspace }}/build/meson-logs/* + retention-days: 5 + - name: Codecov + if: success() && github.repository == 'blackmagic-debug/bmpflash' + uses: codecov/codecov-action@v3 + with: + directory: ./build/meson-logs/ + files: coverage.xml + token: ${{ secrets.CODECOV_TOKEN }} + + build-macos-homebrew: + # Apple LLD is unable to link GCC < 11 generated object files. + # https://stackoverflow.com/questions/73714336/xcode-update-to-version-2395-ld-compile-problem-occurs-computedatomcount-m + # rdar://FB11369327 + name: '${{ matrix.os }} (homebrew, ${{ matrix.compiler }})' + runs-on: ${{ matrix.os }} + if: false + defaults: + run: + shell: bash + strategy: + matrix: + os: + - macos-11 + compiler: + - gcc@9 + - gcc@11 + - gcc@12 + - gcc@13 # needs hardcoding for the GCOV replacement + fail-fast: false + env: + BUILD_OPTS: '' + steps: + - name: Runtime environment + env: + WORKSPACE: ${{ github.workspace }} + run: | + echo "GITHUB_WORKSPACE=`pwd`" >> $GITHUB_ENV + - name: Setup compiler + run: | + brew install ${{ matrix.compiler }} + CC=${COMPILER/@/-} + CXX=${CC/#gcc/g++} + echo "CC=$CC" >> $GITHUB_ENV + echo "CXX=$CXX" >> $GITHUB_ENV + echo "GCOV=${CC/#gcc/gcov}" >> $GITHUB_ENV + env: + COMPILER: ${{ matrix.compiler }} + - name: Checkout + uses: actions/checkout@v3 + with: + lfs: true + submodules: true + - name: Setup Meson + Ninja + gcovr + run: | + brew install meson ninja gcovr + working-directory: ${{ runner.temp }} + - name: Version tools + shell: bash + run: | + $CC --version + $CXX --version + $GCOV --version + meson --version + ninja --version + - name: Configure + run: meson setup build --prefix=$HOME/.local $BUILD_OPTS + - name: Build + run: meson compile -C build + - name: Test + run: meson test -C build + - name: Install + run: meson install -C build + - name: Run coverage build + if: github.repository == 'blackmagic-debug/bmpflash' + # Codecov no longer parses gcov files automatically + run: | + rm -rf build + meson setup build --prefix=$HOME/.local -Db_coverage=true --buildtype=debug + meson compile -C build + meson test -C build + ninja -C build coverage-xml + - name: Upload failure logs + if: failure() + uses: actions/upload-artifact@v3 + with: + name: logs-${{ matrix.os }}-homebrew-${{ matrix.compiler }} + path: ${{ github.workspace }}/build/meson-logs/* + retention-days: 5 + - name: Codecov + if: success() && github.repository == 'blackmagic-debug/bmpflash' + uses: codecov/codecov-action@v3 + with: + directory: ./build/meson-logs/ + files: coverage.xml + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml new file mode 100644 index 0000000..a53fc14 --- /dev/null +++ b/.github/workflows/build-windows.yml @@ -0,0 +1,189 @@ +name: Build Windows + +on: + push: + branches-ignore: + - 'coverityScan' + pull_request: + branches: + - 'main' + +concurrency: + group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-windows: + name: '${{ matrix.os }} (msvc ${{ matrix.arch }})' + runs-on: ${{ matrix.os }} + if: false + strategy: + matrix: + os: + - windows-2022 + arch: + - x86 + - amd64 + fail-fast: false + env: + CC: cl.exe + CXX: cl.exe + LD: link.exe + BUILD_OPTS: '' + steps: + - name: Runtime environment + env: + WORKSPACE: ${{ github.workspace }} + run: | + echo "${env:HOME}/.local/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "GITHUB_WORKSPACE=${{ env.WORKSPACE }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + - name: Setup compiler + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.arch }} + - name: Install OpenCppCoverage + if: github.repository == 'blackmagic-debug/bmpflash' + uses: crazy-max/ghaction-chocolatey@v2.1.0 + with: + args: install OpenCppCoverage + - name: Setup OpenCppCoverage + if: github.repository == 'blackmagic-debug/bmpflash' + run: | + echo "C:/Program Files/OpenCppCoverage" >> $env:GITHUB_PATH + - name: Checkout + uses: actions/checkout@v3 + with: + lfs: true + submodules: true + - name: Setup Meson + Ninja + shell: bash + run: | + python3 -m pip install --upgrade pip setuptools wheel + python3 -m pip install meson ninja + working-directory: ${{ runner.temp }} + - name: Version tools + run: | + cl /Bv + link + meson --version + ninja --version + - name: Configure + run: meson setup build --prefix=$HOME/.local $BUILD_OPTS + - name: Build + run: meson compile -C build + - name: Test + run: meson test -C build + - name: Install + run: meson install -C build + - name: Run coverage build + if: github.repository == 'blackmagic-debug/bmpflash' + run: | + Remove-Item -Recurse build + meson setup build --prefix=$HOME/.local -Db_coverage=true --buildtype=debug -Ddefault_library=static + meson compile -C build + meson test -C build + - name: Upload failure logs + if: failure() + uses: actions/upload-artifact@v3 + with: + name: logs-${{ matrix.os }}-${{ matrix.arch }} + path: | + ${{ github.workspace }}/build/meson-logs + ${{ github.workspace }}/build/test + retention-days: 5 + - name: Codecov + if: success() && github.repository == 'blackmagic-debug/bmpflash' + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + build-windows-mingw: + name: '${{ matrix.os }} (${{ matrix.sys }})' + runs-on: ${{ matrix.os }} + defaults: + run: + shell: msys2 {0} + strategy: + matrix: + os: + - windows-2019 + sys: + - mingw64 + - ucrt64 + - clang64 + fail-fast: false + env: + BUILD_OPTS: '' + steps: + - name: Use MinGW from MSYS + uses: msys2/setup-msys2@v2 + with: + msystem: ${{ matrix.sys }} + update: true + path-type: inherit + pacboy: >- + toolchain:p + lcov:p + - name: Runtime environment + env: + WORKSPACE: ${{ github.workspace }} + run: | + echo "$HOME/.local/bin" >> $GITHUB_PATH + echo "GITHUB_WORKSPACE=${{ env.WORKSPACE }}" >> $GITHUB_ENV + - name: Setup GCC + if: startsWith(matrix.sys, 'mingw') || startsWith(matrix.sys, 'ucrt64') + run: | + echo "GCOV=gcov" >> $GITHUB_ENV + - name: Setup Clang + if: startsWith(matrix.sys, 'clang') + run: | + echo "GCOV=llvm-cov gcov" >> $GITHUB_ENV + - name: Checkout + uses: actions/checkout@v3 + with: + lfs: true + submodules: true + - name: Setup Meson + Ninja + gcovr + shell: bash + run: | + python3 -m pip install --upgrade pip setuptools wheel + python3 -m pip install meson ninja gcovr + working-directory: ${{ runner.temp }} + - name: Version tools + run: | + cc --version + c++ --version + $GCOV --version + meson --version + ninja --version + - name: Configure + run: meson build --prefix=$HOME/.local $BUILD_OPTS + - name: Build + run: meson compile -C build + - name: Test + run: meson test -C build + - name: Install + run: meson install -C build + - name: Run coverage build + if: github.repository == 'blackmagic-debug/bmpflash' + # Codecov no longer parses gcov files automatically + run: | + rm -rf build + meson setup build --prefix=$HOME/.local -Db_coverage=true --buildtype=debug + meson compile -C build + meson test -C build + ninja -C build coverage-xml + - name: Upload failure logs + if: failure() + uses: actions/upload-artifact@v3 + with: + name: logs-${{ matrix.os }}-${{ matrix.sys }} + path: ${{ github.workspace }}/build/meson-logs/* + retention-days: 5 + - name: Codecov + if: success() && github.repository == 'blackmagic-debug/bmpflash' + uses: codecov/codecov-action@v3 + with: + directory: ./build/meson-logs/ + files: coverage.xml + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/src/bmp.cxx b/src/bmp.cxx index fb8dd3f..d7fef44 100644 --- a/src/bmp.cxx +++ b/src/bmp.cxx @@ -113,7 +113,13 @@ bmp_t::bmp_t(const usbDevice_t &usbDevice) : device{usbDevice.open()} { // Get each interface and inspect the first alt-mode const auto interface{config.interface(idx)}; + // Check that the interface is valid, skip if not + if (!interface.valid()) + continue; const auto firstAltMode{interface.altMode(0)}; + // Check that the mode is valid, skip if not + if (!firstAltMode.valid()) + continue; // Check if the interface matches the data interface index if (firstAltMode.interfaceNumber() != dataInterfaceNumber) diff --git a/src/bmpflash.cxx b/src/bmpflash.cxx index d16d164..85b8462 100644 --- a/src/bmpflash.cxx +++ b/src/bmpflash.cxx @@ -34,7 +34,7 @@ namespace bmpflash console.writeln(); programOptions.displayHelp(); console.writeln(); - console.writeln("This utility is licened under BSD-3-Clause"sv); + console.writeln("This utility is licensed under BSD-3-Clause"sv); console.writeln("Please report bugs to https://github.com/blackmagic-debug/bmpflash/issues"sv); } } diff --git a/src/meson.build b/src/meson.build index 23b1494..0c8de63 100644 --- a/src/meson.build +++ b/src/meson.build @@ -3,6 +3,10 @@ # SPDX-FileContributor: Written by Rachel Mant cxx = meson.get_compiler('cpp') +if cxx.get_id() == 'msvc' and cxx.version().version_compare('<19.37') + error('Your compiler is broken, please upgrade to at least MSVC 2022 release 17.7 to build bmpflash with MSVC.') +endif + extendedWarnings = [ '-Wdouble-promotion', '-Wformat=2', @@ -50,6 +54,7 @@ extendedWarnings = [ '-Wswitch-enum', '-Wdefaulted-function-deleted', '-Wdeprecated-copy', + '-ftrapv', # MSVC unique warnings that are useful '-w35030', # attribute 'gnu::packed' is not recognized @@ -134,6 +139,16 @@ libusb = dependency( fallback: 'libusb' ) +deps = [substrate, fmt, libusb] + +if substrate.get_variable('command_line_enabled') == 'false' + error('Refusing to build - substrate has not enabled the command line options parser') +endif + +# GCC < 9.1 splits the filesystem module into a separate library +libstdcppFS = cxx.find_library('stdc++fs', required: false) +deps += libstdcppFS + subdir('include') bmpflashSrc = [ @@ -153,11 +168,13 @@ if host_machine.system() == 'windows' ] endif +bmpflashCppArgs += '-DHAS_FILESYSTEM_PATH' + bmpflash = executable( 'bmpflash', bmpflashSrc, cpp_args: bmpflashCppArgs, include_directories: [include_directories('include', 'include/elf')], - dependencies: [substrate, fmt, libusb], + dependencies: deps, gnu_symbol_visibility: 'inlineshidden' ) diff --git a/src/remoteSPI.cxx b/src/remoteSPI.cxx index 747c486..3ded1bd 100644 --- a/src/remoteSPI.cxx +++ b/src/remoteSPI.cxx @@ -9,6 +9,7 @@ #elif defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wswitch-enum" +#pragma GCC diagnostic ignored "-Wsign-conversion" #endif #include #if defined(_MSC_VER) @@ -29,7 +30,7 @@ using substrate::indexSequence_t; constexpr static auto remoteResponseOK{'K'}; constexpr static auto remoteResponseParameterError{'P'}; -constexpr static auto remoteResponseError{'E'}; +[[maybe_unused]] constexpr static auto remoteResponseError{'E'}; constexpr static auto remoteResponseNotSupported{'N'}; #define REMOTE_UINT8 "{:02x}"