Create cmake-multi-platform.yml #32887

pull Sazwan96 wants to merge 1 commits into bitcoin:master from Sazwan96:master changing 1 files +75 −0
  1. Sazwan96 commented at 10:24 pm on July 6, 2025: none

    Here’s a cmake-multi-platform.yml GitHub Actions workflow that builds and tests a CMake project on multiple platforms (Linux, macOS, Windows) with different compilers:

     0name: CMake Multi-Platform Build
     1
     2on:
     3  push:
     4    branches: [ main, master ]
     5  pull_request:
     6    branches: [ main, master ]
     7
     8jobs:
     9  build:
    10    runs-on: ${{ matrix.os }}
    11    strategy:
    12      matrix:
    13        include:
    14          # Linux configurations
    15          - os: ubuntu-22.04
    16            compiler: gcc
    17            cc: gcc
    18            cxx: g++
    19            generator: Ninja
    20          - os: ubuntu-22.04
    21            compiler: clang
    22            cc: clang
    23            cxx: clang++
    24            generator: Ninja
    25
    26          # macOS configurations
    27          - os: macos-13
    28            compiler: appleclang
    29            cc: clang
    30            cxx: clang++
    31            generator: Ninja
    32
    33          # Windows configurations
    34          - os: windows-latest
    35            compiler: msvc
    36            generator: Visual Studio 17 2022
    37            architecture: x64
    38          - os: windows-latest
    39            compiler: mingw
    40            cc: gcc
    41            cxx: g++
    42            generator: MinGW Makefiles
    43
    44    steps:
    45      - name: Checkout code
    46        uses: actions/checkout@v4
    47
    48      # Install dependencies
    49      - name: Install Linux dependencies
    50        if: runner.os == 'Linux'
    51        run: |
    52          sudo apt-get update
    53          sudo apt-get install -y ninja-build
    54
    55      - name: Install macOS dependencies
    56        if: runner.os == 'macOS'
    57        run: brew install ninja
    58
    59      - name: Install Windows dependencies (MinGW)
    60        if: matrix.os == 'windows-latest' && matrix.compiler == 'mingw'
    61        uses: msys2/setup-msys2@v2
    62        with:
    63          update: true
    64          install: mingw-w64-x86_64-gcc mingw-w64-x86_64-ninja
    65
    66      # Setup compilers
    67      - name: Set up GCC (Linux)
    68        if: matrix.os == 'ubuntu-22.04' && matrix.compiler == 'gcc'
    69        run: |
    70          sudo apt-get update
    71          sudo apt-get install -y gcc g++
    72
    73      - name: Set up Clang (Linux)
    74        if: matrix.os == 'ubuntu-22.04' && matrix.compiler == 'clang'
    75        run: |
    76          sudo apt-get update
    77          sudo apt-get install -y clang
    78
    79      # Configure CMake
    80      - name: Configure CMake
    81        shell: bash
    82        run: |
    83          cmake -B build \
    84          -G "${{ matrix.generator }}" \
    85          ${{ matrix.architecture && '-A ' + matrix.architecture || '' }} \
    86          ${{ matrix.cc && '-DCMAKE_C_COMPILER=' + matrix.cc || '' }} \
    87          ${{ matrix.cxx && '-DCMAKE_CXX_COMPILER=' + matrix.cxx || '' }} \
    88          -DCMAKE_BUILD_TYPE=Release
    89
    90      # Build project
    91      - name: Build
    92        shell: bash
    93        run: cmake --build build --config Release --parallel
    94
    95      # Run tests
    96      - name: Run tests
    97        shell: bash
    98        run: ctest --test-dir build --output-on-failure -C Release
    

    Key Features:

    1. Multi-Platform Support:

      • Ubuntu Linux (GCC, Clang)
      • macOS (Apple Clang)
      • Windows (MSVC, MinGW)
    2. Compiler Matrix:

      • GCC (Linux)
      • Clang (Linux)
      • Apple Clang (macOS)
      • MSVC (Windows)
      • MinGW (Windows)
    3. Build System:

      • Uses Ninja for Linux/macOS
      • Uses Visual Studio generator for MSVC
      • Uses MinGW Makefiles for MinGW
    4. Configuration Options:

      • Automatic generator selection
      • Compiler detection
      • Architecture specification for Windows
      • Release builds
    5. Testing:

      • Runs tests using CTest
      • Shows failure outputs

    Customization Notes:

    1. CMake Options: Add additional CMake flags in the “Configure CMake” step: yaml -DCMAKE_CXX_STANDARD=17 -DOPTION_NAME=ON

    2. Build Types: To add Debug builds, duplicate matrix entries and change CMAKE_BUILD_TYPE.

    3. Windows Architecture: For ARM builds, change architecture: ARM64.

    4. macOS Version: Adjust macos-13 to other versions like macos-12 or macos-latest.

    5. Dependencies: Add system dependencies in the appropriate “Install dependencies” section.

    This workflow provides a solid foundation for CI/CD of CMake projects across different platforms and compilers. The matrix strategy ensures all configurations are tested independently, and the setup optimizes build times through parallelization.

  2. Create cmake-multi-platform.yml
    Here's a `cmake-multi-platform.yml` GitHub Actions workflow that builds and tests a CMake project on multiple platforms (Linux, macOS, Windows) with different compilers:
    
    ```yaml
    name: CMake Multi-Platform Build
    
    on:
      push:
        branches: [ main, master ]
      pull_request:
        branches: [ main, master ]
    
    jobs:
      build:
        runs-on: ${{ matrix.os }}
        strategy:
          matrix:
            include:
              # Linux configurations
              - os: ubuntu-22.04
                compiler: gcc
                cc: gcc
                cxx: g++
                generator: Ninja
              - os: ubuntu-22.04
                compiler: clang
                cc: clang
                cxx: clang++
                generator: Ninja
    
              # macOS configurations
              - os: macos-13
                compiler: appleclang
                cc: clang
                cxx: clang++
                generator: Ninja
    
              # Windows configurations
              - os: windows-latest
                compiler: msvc
                generator: Visual Studio 17 2022
                architecture: x64
              - os: windows-latest
                compiler: mingw
                cc: gcc
                cxx: g++
                generator: MinGW Makefiles
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
    
          # Install dependencies
          - name: Install Linux dependencies
            if: runner.os == 'Linux'
            run: |
              sudo apt-get update
              sudo apt-get install -y ninja-build
    
          - name: Install macOS dependencies
            if: runner.os == 'macOS'
            run: brew install ninja
    
          - name: Install Windows dependencies (MinGW)
            if: matrix.os == 'windows-latest' && matrix.compiler == 'mingw'
            uses: msys2/setup-msys2@v2
            with:
              update: true
              install: mingw-w64-x86_64-gcc mingw-w64-x86_64-ninja
    
          # Setup compilers
          - name: Set up GCC (Linux)
            if: matrix.os == 'ubuntu-22.04' && matrix.compiler == 'gcc'
            run: |
              sudo apt-get update
              sudo apt-get install -y gcc g++
    
          - name: Set up Clang (Linux)
            if: matrix.os == 'ubuntu-22.04' && matrix.compiler == 'clang'
            run: |
              sudo apt-get update
              sudo apt-get install -y clang
    
          # Configure CMake
          - name: Configure CMake
            shell: bash
            run: |
              cmake -B build \
              -G "${{ matrix.generator }}" \
              ${{ matrix.architecture && '-A ' + matrix.architecture || '' }} \
              ${{ matrix.cc && '-DCMAKE_C_COMPILER=' + matrix.cc || '' }} \
              ${{ matrix.cxx && '-DCMAKE_CXX_COMPILER=' + matrix.cxx || '' }} \
              -DCMAKE_BUILD_TYPE=Release
    
          # Build project
          - name: Build
            shell: bash
            run: cmake --build build --config Release --parallel
    
          # Run tests
          - name: Run tests
            shell: bash
            run: ctest --test-dir build --output-on-failure -C Release
    ```
    
    ### Key Features:
    1. **Multi-Platform Support**:
       - Ubuntu Linux (GCC, Clang)
       - macOS (Apple Clang)
       - Windows (MSVC, MinGW)
    
    2. **Compiler Matrix**:
       - GCC (Linux)
       - Clang (Linux)
       - Apple Clang (macOS)
       - MSVC (Windows)
       - MinGW (Windows)
    
    3. **Build System**:
       - Uses Ninja for Linux/macOS
       - Uses Visual Studio generator for MSVC
       - Uses MinGW Makefiles for MinGW
    
    4. **Configuration Options**:
       - Automatic generator selection
       - Compiler detection
       - Architecture specification for Windows
       - Release builds
    
    5. **Testing**:
       - Runs tests using CTest
       - Shows failure outputs
    
    ### Customization Notes:
    1. **CMake Options**: Add additional CMake flags in the "Configure CMake" step:
       ```yaml
       -DCMAKE_CXX_STANDARD=17 -DOPTION_NAME=ON
       ```
    
    2. **Build Types**: To add Debug builds, duplicate matrix entries and change `CMAKE_BUILD_TYPE`.
    
    3. **Windows Architecture**: For ARM builds, change `architecture: ARM64`.
    
    4. **macOS Version**: Adjust `macos-13` to other versions like `macos-12` or `macos-latest`.
    
    5. **Dependencies**: Add system dependencies in the appropriate "Install dependencies" section.
    
    This workflow provides a solid foundation for CI/CD of CMake projects across different platforms and compilers. The matrix strategy ensures all configurations are tested independently, and the setup optimizes build times through parallelization.
    100ffd8752
  3. DrahtBot commented at 10:24 pm on July 6, 2025: contributor
    ♻️ Automatically closing for now based on heuristics. Please leave a comment, if this was erroneous. Generally, please focus on creating high-quality, original content that demonstrates a clear understanding of the project’s requirements and goals.
  4. DrahtBot closed this on Jul 6, 2025

  5. DrahtBot commented at 10:24 pm on July 6, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32887.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  6. Sazwan96 commented at 10:52 pm on July 6, 2025: none
    Heloo
  7. bitcoin locked this on Jul 6, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-07-07 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me