• Stars
    star
    118
  • Rank 293,522 (Top 6 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created almost 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Install all the tools required for building and testing C++/C projects.

setup-cpp

Install all the tools required for building and testing C++/C projects.

Build Status (Github Actions)

Setting up a cross-platform environment for building and testing C++/C projects is a bit tricky. Each platform has its own compilers, and each of them requires a different installation procedure. This package aims to fix this issue.

setup-cpp can be used locally from terminal, from CI services like GitHub Actions and GitLab Pipelines, and inside containers like Docker.

setup-cpp is supported on many platforms. It is continuously tested on several configurations including Windows (11, 10, 2022, 2019), Linux (Ubuntu 22.04, Ubuntu 20.04, Fedora, ArchLinux), and macOS (12, 11, 10.15). setup-cpp is backed by unit tests for each tool and integration tests for compiling cpp projects.

Features

setup-cpp is modular and you can choose to install any of these tools:

category tools
compiler and analyzer llvm, gcc, msvc, vcvarsall, cppcheck, clangtidy, clangformat
build system cmake, ninja, meson, make, task, bazel
package manager vcpkg, conan, choco, brew, nala
cache cppcache, sccache
documentation doxygen, graphviz
coverage gcovr, opencppcoverage, kcov
other python, powershell, sevenzip

setup-cpp automatically handles the dependencies of the selected tool (e.g., python is required for conan).

Usage

From Terminal

With npm and Nodejs

Run setup-cpp with the available options.

# Windows example (open PowerShell as admin)
npx setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true

RefreshEnv.cmd # activate the environment
# Linux/Macos example
sudo npx setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true

source ~/.cpprc

NOTE: In the compiler entry, you can specify the version after - like llvm-11.0.0. For the tools, you can pass a specific version instead of true that chooses the default version

NOTE: On Unix systems, when setup-cpp is used locally or in other CI services like GitLab, the environment variables are added to ~/.cpprc. You should run source ~/.cpprc to immediately activate the environment variables. This file is automatically sourced in the next shell restart from ~/.bashrc or ~/.profile if SOURCE_CPPRC is not set to 0. To deactivate .cpprc in the next shell restart, rename/remove ~/.cpprc.

NOTE: On Unix systems, if you are already a root user (e.g., in a GitLab runner or Docker), you will not need to use sudo.

With executable

Download the executable for your platform from here, and run it with the available options. You can also automate downloading using wget, curl, or other similar tools.

An example that installs llvm, cmake, ninja, ccache, and vcpkg:

# windows example (open PowerShell as admin)
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.31.0/setup-cpp-x64-windows.exe"
./setup-cpp-x64-windows --compiler llvm --cmake true --ninja true --ccache true --vcpkg true

RefreshEnv.cmd # activate cpp environment variables
# linux example
wget "https://github.com/aminya/setup-cpp/releases/download/v0.31.0/setup-cpp-x64-linux"
chmod +x ./setup-cpp-x64-linux
sudo ./setup-cpp-x64-linux --compiler llvm --cmake true --ninja true --ccache true --vcpkg true

source ~/.cpprc # activate cpp environment variables
# macos example
wget "https://github.com/aminya/setup-cpp/releases/download/v0.31.0/setup-cpp-x64-macos"
chmod +x ./setup-cpp-x64-macos
sudo ./setup-cpp-x64-macos --compiler llvm --cmake true --ninja true --ccache true --vcpkg true

source ~/.cpprc # activate cpp environment variables

Inside GitHub Actions

Here is a complete cross-platform example that tests llvm, gcc, and msvc. It also uses cmake, ninja, vcpkg, and cppcheck.

.github/workflows/ci.yml:

name: ci
on:
  pull_request:
  push:
    branches:
      - main
      - master

jobs:
  Test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - windows-2022
          - ubuntu-22.04
          - macos-12
        compiler:
          - llvm
          - gcc
          # you can specify the version after `-` like `llvm-13.0.0`.
        include:
          - os: "windows-2022"
            compiler: "msvc"
    steps:
      - uses: actions/checkout@v3
      - name: Cache
        uses: actions/cache@v3
        with:
          path: |
            ~/vcpkg
            ./build/vcpkg_installed
            ${{ env.HOME }}/.cache/vcpkg/archives
            ${{ env.XDG_CACHE_HOME }}/vcpkg/archives
            ${{ env.LOCALAPPDATA }}\vcpkg\archives
            ${{ env.APPDATA }}\vcpkg\archives
          key: ${{ runner.os }}-${{ matrix.compiler }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}
          restore-keys: |
            ${{ runner.os }}-${{ env.BUILD_TYPE }}-

      - name: Setup Cpp
        uses: aminya/setup-cpp@v1
        with:
          compiler: ${{ matrix.compiler }}
          vcvarsall: ${{ contains(matrix.os, 'windows') }}
          cmake: true
          ninja: true
          vcpkg: true
          cppcheck: true
          clangtidy: true # instead of `true`, which chooses the default version, you can pass a specific version.
          # ...

Inside Docker

Here is an example for using setup-cpp to make a builder image that has the Cpp tools you need.

#### Base Image
FROM ubuntu:22.04 as setup-cpp-ubuntu

RUN apt-get update -qq && \
    # install nodejs
    apt-get install -y --no-install-recommends nodejs npm && \
    # install setup-cpp
    npm install -g [email protected] && \
    # install the compiler and tools
    setup-cpp \
        --nala true \
        --compiler llvm \
        --cmake true \
        --ninja true \
        --task true \
        --vcpkg true \
        --python true \
        --make true \
        --cppcheck true \
        --gcovr true \
        --doxygen true \
        --ccache true && \
    # cleanup
    nala autoremove -y && \
    nala autopurge -y && \
    apt-get clean && \
    nala clean --lists && \
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /tmp/*

ENTRYPOINT ["/bin/bash"]

#### Building (example)
FROM setup-cpp-ubuntu AS builder

COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
    && task build'

#### Running environment
# use a fresh image as the runner
FROM ubuntu:22.04 as runner

# copy the built binaries and their runtime dependencies
COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/
ENTRYPOINT ["./my_exe"]

See this folder, for some dockerfile examples.

If you want to build the ones included, then run:

git clone --recurse-submodules https://github.com/aminya/setup-cpp
cd ./setup-cpp
docker build -f ./dev/docker/setup-cpp-ubuntu.dockerfile -t setup-cpp .

Where you should use the path to the dockerfile after -f.

After build, run the following to start an interactive shell in your container

docker run -it setup-cpp

Inside Docker inside GitHub Actions

You can use the docker file discussed in the previous section inside GitHub Actions like the following:

jobs:
  Docker:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os:
          - ubuntu-22.04
    steps:
      - uses: actions/checkout@v3
      - name: Build
        id: docker_build
        run: |
          docker build -f ./dev/docker/ubuntu.dockerfile -t setup-cpp .

Inside GitLab pipelines

The following gives an example for setting up a C++ environment inside GitLab pipelines.

.gitlab-ci.yaml

image: ubuntu:22.04

stages:
  - test

.setup_linux: &setup_linux |
  DEBIAN_FRONTEND=noninteractive

  # set time-zone
  TZ=Canada/Pacific
  ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

  # for downloading
  apt-get update -qq
  apt-get install -y --no-install-recommends curl gnupg ca-certificates

  # keys used by apt
  apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
  apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5
  apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F

.setup-cpp: &setup-cpp |
  curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.31.0/setup-cpp-x64-linux"
  chmod +x setup-cpp-x64-linux
  ./setup-cpp-x64-linux --compiler $compiler --cmake true --ninja true --ccache true --vcpkg true
  source ~/.cpprc

.test: &test |
  # Build and Test
  # ...

test_linux_llvm:
  stage: test
  variables:
    compiler: llvm
  script:
    - *setup_linux
    - *setup-cpp
    - *test

test_linux_gcc:
  stage: test
  variables:
    compiler: gcc
  script:
    - *setup_linux
    - *setup-cpp
    - *test

Articles

Setup-Cpp on Dev.to

Usage Examples

See all of the usage examples on GitHub here.

More Repositories

1

project_options

A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.
CMake
263
star
2

solid-simple-table

Blazing fast Table component with solid-js
TypeScript
46
star
3

tocPDF

Generates bookmarks from the table of contents already available at the beginning of pdf files.
25
star
4

package-switch

Easy package activation/deactivation
TypeScript
24
star
5

CompileBot.jl

Automatic compilation for Julia packages
Julia
17
star
6

cpp_vcpkg_project

A production-ready C++ project made with vcpkg
CMake
13
star
7

astro-parcel

Build and optimize your Astro project using Parcel
TypeScript
11
star
8

eslint-plugin-yaml

Lint YAML files using ESLint
TypeScript
9
star
9

typescript-optimization

Compares different for-loops in TypeScript/JavaScript
TypeScript
7
star
10

VarStructs.jl

Variable Julia Structs with dispatching
Julia
7
star
11

d-tree-sitter

The D bindings for tree-sitter
D
7
star
12

AcuteMSWord

My Microsoft Word VBA macros
VBA
6
star
13

minijson

Minify JSON files fast! Supports Comments. Uses D, C, and AVX2 and SSE4_1 SIMD.
D
6
star
14

juno-plus

Enhances Juno - Julia IDE
TypeScript
5
star
15

globify_gitignore

Convert Gitignore to Glob patterns in Go
Go
4
star
16

AcuteML.jl

Acute Markup Language - HTML/XML in Julia
Julia
4
star
17

AcuteLyx

A collection of environments, shortcuts, toolbars, packages, etc. to enhance Lyx.
TeX
4
star
18

AcutePowerShell

Various PowerShell scripts
PowerShell
3
star
19

TypeTransform.jl

Transform the given type to another type during defining a method
Julia
3
star
20

patha

File paths library. All you need to work with paths. Tiny drop-in replacement for 'path'. Works in Node, Browser, and Deno.
TypeScript
3
star
21

Dispatch.m

Runtime multiple dispatch for Matlab.
MATLAB
2
star
22

aminya

2
star
23

jira-issue-navigate

Go to the next/prev issue using buttons
TypeScript
2
star
24

AcuteGit

My most used git commands for the operations that are not available through github desktop software
PowerShell
2
star
25

AcuteBenchmark.jl

Automatically benchmark functions!
Julia
2
star
26

cmove

Move const values in C++
CMake
2
star
27

assemblyscript-template

An AssemblyScript template with support for many environments
TypeScript
2
star
28

chocolatey-wabt

The WebAssembly Binary Toolkit
PowerShell
1
star
29

.github

1
star
30

Matlab-Snippets

Generate Matlab snippets for Atom and VSCode
Julia
1
star
31

globify-gitignore

Convert Gitignore to Glob patterns
TypeScript
1
star
32

chocolatey-emscripten

Chocolatey package for emscripten
PowerShell
1
star
33

admina

Detect root/admin/sudo and execute commands as it if available
TypeScript
1
star
34

projsync

Sync projects to different remote machines over SSH or WSL
Rust
1
star
35

svg-extract

Extract inline SVG to a new file in VsCode
TypeScript
1
star