Skip to content

Commit c801463

Browse files
committed
Initial commit
0 parents  commit c801463

204 files changed

Lines changed: 46462 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: LLVM
4+
IndentWidth: 2
5+
ColumnLimit: 80

.clang-format-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/detail/third_party/

.clang-tidy

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Checks: "-*,\
2+
bugprone-*,
3+
clang-analyzer-*,
4+
modernize-*,
5+
performance-*,
6+
portability-*,
7+
readability-identifier-naming,
8+
misc-include-cleaner,
9+
-bugprone-easily-swappable-parameters,
10+
-bugprone-exception-escape,
11+
-modernize-avoid-c-arrays,
12+
-clang-analyzer-security.*,
13+
-clang-analyzer-optin.*"
14+
15+
WarningsAsErrors: ""
16+
17+
FormatStyle: file
18+
19+
HeaderFilterRegex: "^(?!.*third_party).*"
20+
21+
CheckOptions:
22+
- key: readability-identifier-naming.ClassCase
23+
value: CamelCase
24+
- key: readability-identifier-naming.StructCase
25+
value: CamelCase
26+
- key: readability-identifier-naming.FunctionCase
27+
value: camelBack
28+
- key: readability-identifier-naming.VariableCase
29+
value: camelBack
30+
- key: readability-identifier-naming.ParameterCase
31+
value: camelBack
32+
- key: readability-identifier-naming.MemberCase
33+
value: camelBack
34+
- key: readability-identifier-naming.PrivateMemberPrefix
35+
value: _
36+
- key: readability-identifier-naming.GlobalConstantCase
37+
value: UPPER_CASE
38+
- key: readability-identifier-naming.NamespaceCase
39+
value: camelBack
40+
- key: readability-identifier-naming.EnumCase
41+
value: CamelCase
42+
- key: readability-identifier-naming.EnumConstantCase
43+
value: UPPER_CASE
44+
- key: misc-include-cleaner.IgnoreHeaders
45+
value: bits/.*;signal.h;stdio.h;unistd.h;arpa/inet.h;netinet/in.h;sys/socket.h;sys/types.h;sys/wait.h;ifaddrs.h;fcntl.h;filesystem;nlohmann/json_fwd.hpp;nlohmann/json.hpp;httplib.h;stdlib.h;math.h;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Install System Dependencies"
2+
description: "Install common system dependencies for plotly.cpp builds"
3+
4+
inputs:
5+
extra-packages:
6+
description: "Additional packages to install (space-separated)"
7+
required: false
8+
default: ""
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Install base dependencies
14+
shell: bash
15+
run: |
16+
sudo apt-get update
17+
sudo apt-get install -y \
18+
build-essential \
19+
cmake \
20+
pkg-config \
21+
nlohmann-json3-dev \
22+
libgtest-dev \
23+
libgoogle-glog-dev \
24+
libunwind-dev \
25+
libboost-dev \
26+
libboost-system-dev
27+
28+
- name: Install extra packages
29+
if: inputs.extra-packages != ''
30+
shell: bash
31+
run: |
32+
sudo apt-get install -y ${{ inputs.extra-packages }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Setup Clang"
2+
description: "Install and configure Clang compiler"
3+
4+
inputs:
5+
clang-version:
6+
description: "Clang version to install (20, 21)"
7+
required: false
8+
default: "20"
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Install and setup clang
14+
shell: bash
15+
run: |
16+
# Determine Ubuntu codename
17+
UBUNTU_CODENAME=$(lsb_release -cs)
18+
19+
# Add LLVM repository key
20+
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/llvm.asc
21+
22+
# Install specific clang version
23+
CLANG_VERSION="${{ inputs.clang-version }}"
24+
echo "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-${CLANG_VERSION} main" | sudo tee /etc/apt/sources.list.d/llvm.list
25+
sudo apt-get update
26+
sudo apt-get install -y clang-${CLANG_VERSION} clang-format-${CLANG_VERSION} clang-tidy-${CLANG_VERSION}

.github/workflows/ci.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
workflow_dispatch:
9+
10+
env:
11+
CTEST_TIMEOUT: 120
12+
CLANG_VERSION: "20"
13+
14+
jobs:
15+
build-and-test:
16+
name: Build & Test (${{ matrix.os }}, C++${{ matrix.cxx_standard }})
17+
runs-on: ${{ matrix.os }}
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ubuntu-22.04, ubuntu-24.04]
23+
cxx_standard: [17, 20]
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Install dependencies
30+
uses: ./.github/actions/install-dependencies
31+
32+
- name: Setup Clang
33+
uses: ./.github/actions/setup-clang
34+
with:
35+
clang-version: ${{ env.CLANG_VERSION }}
36+
37+
- name: Build
38+
run: |
39+
CMAKE_CXX_STANDARD=${{ matrix.cxx_standard }} \
40+
CMAKE_C_COMPILER=clang-${{ env.CLANG_VERSION }} \
41+
CMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} \
42+
make debug
43+
44+
- name: Run tests
45+
run: |
46+
cd ${{github.workspace}}/build
47+
xvfb-run -a --server-args="-screen 0 1024x768x24 -ac +extension GLX +render -noreset" ctest --output-on-failure --verbose --timeout ${{ env.CTEST_TIMEOUT }}
48+
49+
- name: Upload test results
50+
if: always()
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: test-results-${{ matrix.os }}-cpp${{ matrix.cxx_standard }}
54+
path: |
55+
${{github.workspace}}/build/Testing/
56+
${{github.workspace}}/build/test/
57+
58+
sanitizer-analysis:
59+
name: Sanitizer Analysis (${{ matrix.sanitizer }})
60+
runs-on: ubuntu-24.04
61+
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
sanitizer: [asan, tsan]
66+
67+
steps:
68+
- name: Checkout code
69+
uses: actions/checkout@v4
70+
71+
- name: Install dependencies
72+
uses: ./.github/actions/install-dependencies
73+
74+
- name: Setup Clang
75+
uses: ./.github/actions/setup-clang
76+
with:
77+
clang-version: ${{ env.CLANG_VERSION }}
78+
79+
- name: Build with sanitizer
80+
run: |
81+
CMAKE_C_COMPILER=clang-${{ env.CLANG_VERSION }} \
82+
CMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} \
83+
make ${{ matrix.sanitizer }}
84+
85+
- name: Run tests with sanitizer
86+
run: |
87+
build_dir="build-${{ matrix.sanitizer }}"
88+
cd $build_dir
89+
# Set sanitizer options
90+
if [ "${{ matrix.sanitizer }}" = "asan" ]; then
91+
export ASAN_OPTIONS="detect_leaks=1:abort_on_error=1"
92+
elif [ "${{ matrix.sanitizer }}" = "tsan" ]; then
93+
export TSAN_OPTIONS="abort_on_error=1"
94+
fi
95+
xvfb-run -a --server-args="-screen 0 1024x768x24 -ac +extension GLX +render -noreset" ctest --output-on-failure --verbose --timeout ${{ env.CTEST_TIMEOUT }}
96+
97+
- name: Upload sanitizer results
98+
if: always()
99+
uses: actions/upload-artifact@v4
100+
with:
101+
name: sanitizer-results-${{ matrix.sanitizer }}
102+
path: |
103+
build-${{ matrix.sanitizer }}/Testing/
104+
build-${{ matrix.sanitizer }}/test/
105+
106+
coverage-analysis:
107+
name: Coverage Analysis
108+
runs-on: ubuntu-22.04
109+
110+
steps:
111+
- name: Checkout code
112+
uses: actions/checkout@v4
113+
114+
- name: Install dependencies
115+
uses: ./.github/actions/install-dependencies
116+
117+
- name: Generate coverage report
118+
run: |
119+
xvfb-run -a --server-args="-screen 0 1024x768x24 -ac +extension GLX +render -noreset" make coverage
120+
121+
- name: Upload coverage to Codecov
122+
uses: codecov/codecov-action@v4
123+
with:
124+
file: ./build-coverage/coverage_filtered.info
125+
fail_ci_if_error: true
126+
127+
- name: Upload HTML coverage reports
128+
uses: actions/upload-artifact@v4
129+
with:
130+
name: coverage-report
131+
path: |
132+
build-coverage/coverage_filtered.info
133+
coverage/

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/build*
2+
.vscode
3+
.cursor
4+
.claude
5+
coverage

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: trailing-whitespace
6+
exclude: ^(webapp/|src/detail/third_party/)
7+
- id: end-of-file-fixer
8+
exclude: ^(webapp/|src/detail/third_party/)
9+
- id: check-yaml
10+
exclude: ^(webapp/|src/detail/third_party/)
11+
12+
- repo: https://github.com/pre-commit/mirrors-clang-format
13+
rev: v20.1.8
14+
hooks:
15+
- id: clang-format
16+
files: \.(cpp|hpp|c|h|cc|cxx)$
17+
exclude: ^(build/|build-coverage/|\.git/|webapp/|src/detail/third_party/)
18+
19+
- repo: https://github.com/cheshirekow/cmake-format-precommit
20+
rev: v0.6.13
21+
hooks:
22+
- id: cmake-format
23+
args: [--in-place]
24+
files: \.(cmake|CMakeLists\.txt)$
25+
exclude: ^(webapp/|src/detail/third_party/)

CMakeLists.txt

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
cmake_minimum_required(VERSION 3.14) # Required for stable FetchContent
2+
3+
project(plotly-cpp VERSION 0.1.0 LANGUAGES CXX)
4+
5+
enable_testing()
6+
7+
# Include cmake modules
8+
include(cmake/InstallConfig.cmake)
9+
include(cmake/PackageConfig.cmake)
10+
include(FetchContent)
11+
12+
# Configure version header
13+
configure_file(
14+
"${CMAKE_CURRENT_SOURCE_DIR}/include/plotly/version.hpp.in"
15+
"${CMAKE_CURRENT_BINARY_DIR}/include/plotly/version.hpp"
16+
@ONLY
17+
)
18+
19+
# Build options
20+
option(PLOTLY_CPP_BUILD_GALLERY "Build example gallery applications" OFF)
21+
option(PLOTLY_CPP_BUILD_TESTS "Build test suite" OFF)
22+
23+
# Display configuration summary
24+
message(STATUS "plotly.cpp configuration:")
25+
message(STATUS " Build gallery: ${PLOTLY_CPP_BUILD_GALLERY}")
26+
message(STATUS " Build tests: ${PLOTLY_CPP_BUILD_TESTS}")
27+
28+
find_package(nlohmann_json QUIET)
29+
if(NOT nlohmann_json_FOUND)
30+
FetchContent_Declare(
31+
nlohmann_json
32+
GIT_REPOSITORY https://github.com/nlohmann/json.git
33+
GIT_TAG v3.11.3
34+
GIT_SHALLOW TRUE
35+
)
36+
FetchContent_MakeAvailable(nlohmann_json)
37+
message(STATUS "Using FetchContent for nlohmann_json")
38+
endif()
39+
40+
41+
# Define source files explicitly (better than GLOB for reproducibility)
42+
set(PLOTLY_SOURCES
43+
src/plotly.cpp
44+
src/logger.cpp
45+
src/detail/browser.cpp
46+
src/detail/http_server.cpp
47+
src/detail/json_rpc.cpp
48+
src/detail/uuid.cpp
49+
src/detail/websockets_client.cpp
50+
src/detail/websockets_endpoint.cpp
51+
src/detail/websockets_server.cpp
52+
)
53+
54+
# Function to configure common target settings (eliminates duplication)
55+
function(configure_plotly_target target_name)
56+
# Set webapp path for both build and install contexts
57+
set(WEBAPP_PATH_BUILD "${CMAKE_CURRENT_SOURCE_DIR}/webapp/")
58+
set(WEBAPP_PATH_INSTALL "/usr/share/plotly/webapp/")
59+
60+
target_compile_definitions(${target_name}
61+
PUBLIC
62+
PLOTLY_CPP_WEBAPP_PATH="$<BUILD_INTERFACE:${WEBAPP_PATH_BUILD}>$<INSTALL_INTERFACE:${WEBAPP_PATH_INSTALL}>"
63+
PRIVATE
64+
CPPHTTPLIB_THREAD_POOL_COUNT=3
65+
)
66+
67+
target_link_libraries(${target_name}
68+
PRIVATE
69+
pthread
70+
PUBLIC
71+
nlohmann_json::nlohmann_json
72+
)
73+
74+
target_include_directories(${target_name}
75+
PRIVATE
76+
${CMAKE_CURRENT_SOURCE_DIR}/include
77+
${CMAKE_CURRENT_SOURCE_DIR}/src
78+
${CMAKE_CURRENT_SOURCE_DIR}/src/detail/third_party
79+
PUBLIC
80+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
81+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
82+
$<INSTALL_INTERFACE:include>
83+
)
84+
85+
# Configure compiler settings
86+
endfunction()
87+
88+
# Create libraries
89+
add_library(plotly-cpp SHARED ${PLOTLY_SOURCES})
90+
add_library(plotly-cpp-static STATIC ${PLOTLY_SOURCES})
91+
92+
# Apply common configuration
93+
configure_plotly_target(plotly-cpp)
94+
configure_plotly_target(plotly-cpp-static)
95+
96+
# Create alias targets for modern CMake usage
97+
add_library(plotly-cpp::plotly-cpp ALIAS plotly-cpp)
98+
add_library(plotly-cpp::plotly-cpp-static ALIAS plotly-cpp-static)
99+
100+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gallery" AND PLOTLY_CPP_BUILD_GALLERY)
101+
add_subdirectory(gallery)
102+
endif()
103+
104+
# Add tests subdirectory
105+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test" AND PLOTLY_CPP_BUILD_TESTS)
106+
add_subdirectory(test)
107+
endif()
108+
109+
# Configure installation
110+
configure_plotly_installation()
111+
112+
# Include CPack for package generation
113+
include(CPack)

0 commit comments

Comments
 (0)