Skip to content

Commit 19cae22

Browse files
authored
Merge pull request #19 from Rac75116/developing
ver 1.3.3
2 parents 310c093 + 257c55a commit 19cae22

18 files changed

Lines changed: 236 additions & 386 deletions

.clangd

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
CompileFlags:
2-
Add:
3-
- "-std=c++23"
4-
- "-Wall"
5-
- "-Wextra"
6-
71
Diagnostics:
82
UnusedIncludes: Strict
93
MissingIncludes: Strict

.devcontainer/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04
2+
3+
RUN curl -1sLf 'https://dl.cloudsmith.io/public/task/task/setup.deb.sh' | sudo -E bash
4+
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
ca-certificates \
7+
clang \
8+
clangd \
9+
cmake \
10+
curl \
11+
git \
12+
ninja-build \
13+
task \
14+
pngquant \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin sh

.devcontainer/devcontainer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "libcpprime",
3+
"build": {
4+
"dockerfile": "Dockerfile"
5+
},
6+
"customizations": {
7+
"vscode": {
8+
"extensions": [
9+
"llvm-vs-code-extensions.vscode-clangd",
10+
"ms-vscode.cmake-tools",
11+
"redhat.vscode-yaml",
12+
"ms-python.python",
13+
"charliermarsh.ruff"
14+
]
15+
}
16+
},
17+
"postCreateCommand": "task configure:clang"
18+
}

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.12
1+
3.14

.vscode/settings.json

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,30 @@
44
"editor.formatOnPaste": false,
55
"editor.insertSpaces": true,
66
"editor.tabSize": 4,
7-
"[json]": {
8-
"editor.defaultFormatter": "vscode.json-language-features"
9-
},
10-
"[jsonc]": {
11-
"editor.defaultFormatter": "vscode.json-language-features"
12-
},
13-
"[yaml]": {
14-
"editor.defaultFormatter": "redhat.vscode-yaml",
15-
"editor.tabSize": 2
16-
},
17-
"[cpp]": {
18-
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
19-
},
20-
"[python]": {
21-
"editor.defaultFormatter": "charliermarsh.ruff"
22-
},
23-
"terminal.integrated.defaultProfile.windows": "PowerShell",
24-
"terminal.integrated.env.windows": {
25-
"PSExecutionPolicyPreference": "RemoteSigned"
26-
},
27-
"terminal.integrated.defaultProfile.linux": "bash",
7+
"editor.semanticHighlighting.enabled": true,
288
"files.eol": "\n",
299
"files.insertFinalNewline": true,
3010
"files.trimTrailingWhitespace": true,
3111
"files.associations": {
3212
".clang-format": "yaml",
3313
".clangd": "yaml",
34-
"**/bundled/*.hpp": "plaintext"
3514
},
3615
"files.exclude": {
37-
"build": true,
3816
"build-*": true,
3917
".cache": true,
4018
".venv": true
4119
},
4220
"search.exclude": {
43-
"build": true,
4421
"build-*": true,
4522
".cache": true,
4623
".venv": true
4724
},
25+
"terminal.integrated.defaultProfile.windows": "PowerShell",
26+
"terminal.integrated.env.windows": {
27+
"PSExecutionPolicyPreference": "RemoteSigned"
28+
},
29+
"terminal.integrated.defaultProfile.linux": "bash",
30+
"clangd.enable": true,
4831
"ruff.enable": true,
4932
"python.terminal.activateEnvironment": true,
5033
"python.analysis.ignore": [
@@ -56,8 +39,23 @@
5639
"cmake.autoSelectActiveFolder": false,
5740
"github.copilot.enable": {
5841
"*": true,
59-
"*.txt": false,
42+
"plaintext": false,
43+
"markdown": true,
44+
},
45+
"[json]": {
46+
"editor.defaultFormatter": "vscode.json-language-features"
47+
},
48+
"[jsonc]": {
49+
"editor.defaultFormatter": "vscode.json-language-features"
50+
},
51+
"[yaml]": {
52+
"editor.defaultFormatter": "redhat.vscode-yaml",
53+
"editor.tabSize": 2
54+
},
55+
"[cpp]": {
56+
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
57+
},
58+
"[python]": {
59+
"editor.defaultFormatter": "charliermarsh.ruff"
6060
},
61-
"liveServer.settings.root": "/site",
62-
"liveServer.settings.file": "404.html"
6361
}

CMakeLists.txt

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ endif()
9393
option(LIBCPPRIME_BUILD_EXAMPLES "Build examples" ON)
9494
option(LIBCPPRIME_BUILD_TESTS "Build tests" ON)
9595
option(LIBCPPRIME_BUILD_BENCHMARKS "Build benchmarks" ON)
96-
option(LIBCPPRIME_WARNINGS "Enable warnings" ON)
9796

9897
# ================================
9998
# Header-only library
@@ -104,6 +103,21 @@ target_include_directories(libcpprime INTERFACE
104103
$<INSTALL_INTERFACE:include>
105104
)
106105

106+
# ================================
107+
# Optimization flags
108+
# ================================
109+
function(libcpprime_apply_optimization target)
110+
if(LIBCPPRIME_MSVC_LIKE)
111+
target_compile_options(${target} PRIVATE
112+
/Ox /arch:AVX2
113+
)
114+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
115+
target_compile_options(${target} PRIVATE
116+
-O3 -march=native
117+
)
118+
endif()
119+
endfunction()
120+
107121
# ================================
108122
# Examples
109123
# ================================
@@ -112,12 +126,10 @@ if(LIBCPPRIME_BUILD_EXAMPLES)
112126
target_link_libraries(example_basic PRIVATE libcpprime)
113127
target_compile_features(example_basic PRIVATE cxx_std_23)
114128

115-
if(LIBCPPRIME_WARNINGS)
116-
if(LIBCPPRIME_MSVC_LIKE)
117-
target_compile_options(example_basic PRIVATE /W4 /permissive- /Zc:__cplusplus)
118-
else()
119-
target_compile_options(example_basic PRIVATE -Wall -Wextra -Wpedantic -Wconversion)
120-
endif()
129+
if(LIBCPPRIME_MSVC_LIKE)
130+
target_compile_options(example_basic PRIVATE /W4 /permissive- /Zc:__cplusplus)
131+
else()
132+
target_compile_options(example_basic PRIVATE -Wall -Wextra -Wpedantic -Wconversion)
121133
endif()
122134
endif()
123135

@@ -141,28 +153,27 @@ if(LIBCPPRIME_BUILD_TESTS)
141153
FetchContent_MakeAvailable(googletest)
142154

143155
function(libcpprime_apply_test_options target)
144-
if(LIBCPPRIME_WARNINGS)
145-
if(LIBCPPRIME_CLANG_CL)
146-
target_compile_options(${target} PRIVATE
147-
/W4 /permissive- /Zc:__cplusplus
148-
/clang:-fconstexpr-steps=10000000
149-
)
150-
elseif(MSVC)
151-
target_compile_options(${target} PRIVATE
152-
/W4 /permissive- /Zc:__cplusplus
153-
/constexpr:steps10000000
154-
)
155-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
156-
target_compile_options(${target} PRIVATE
157-
-Wall -Wextra -Wpedantic -Wconversion
158-
-fconstexpr-steps=10000000
159-
)
160-
else()
161-
target_compile_options(${target} PRIVATE
162-
-Wall -Wextra -Wpedantic -Wconversion
163-
)
164-
endif()
156+
if(LIBCPPRIME_CLANG_CL)
157+
target_compile_options(${target} PRIVATE
158+
/W4 /permissive- /Zc:__cplusplus
159+
/clang:-fconstexpr-steps=10000000
160+
)
161+
elseif(MSVC)
162+
target_compile_options(${target} PRIVATE
163+
/W4 /permissive- /Zc:__cplusplus
164+
/constexpr:steps10000000
165+
)
166+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
167+
target_compile_options(${target} PRIVATE
168+
-Wall -Wextra -Wpedantic -Wconversion
169+
-fconstexpr-steps=10000000
170+
)
171+
else()
172+
target_compile_options(${target} PRIVATE
173+
-Wall -Wextra -Wpedantic -Wconversion
174+
)
165175
endif()
176+
libcpprime_apply_optimization(${target})
166177
endfunction()
167178

168179
function(libcpprime_add_isprime_test target cxx_standard)
@@ -206,13 +217,13 @@ if(LIBCPPRIME_BUILD_BENCHMARKS)
206217

207218
target_link_libraries(benchmark_isprime PRIVATE libcpprime nanobench::nanobench)
208219

209-
if(LIBCPPRIME_WARNINGS)
210-
if(LIBCPPRIME_MSVC_LIKE)
211-
target_compile_options(benchmark_isprime PRIVATE /W4 /permissive- /Zc:__cplusplus)
212-
else()
213-
target_compile_options(benchmark_isprime PRIVATE -Wall -Wextra -Wpedantic -Wconversion)
214-
endif()
220+
if(LIBCPPRIME_MSVC_LIKE)
221+
target_compile_options(benchmark_isprime PRIVATE /W4 /permissive- /Zc:__cplusplus)
222+
else()
223+
target_compile_options(benchmark_isprime PRIVATE -Wall -Wextra -Wpedantic -Wconversion)
215224
endif()
225+
226+
libcpprime_apply_optimization(benchmark_isprime)
216227
endif()
217228

218229
# ================================

CONTRIBUTING.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Contributing to libcpprime
2+
3+
Thanks for your interest in improving `libcpprime`.
4+
5+
## Development principles
6+
7+
- Keep the public API minimal and stable.
8+
- Keep `include/libcpprime/` compatible with C++11 and older compiler versions in the supported matrix.
9+
- Avoid compiler-specific behavior unless guarded and tested across compilers.
10+
- If a change is breaking, call it out clearly in the PR description.
11+
12+
## Required tools
13+
14+
### Build and test
15+
16+
- CMake >= 3.20
17+
- A C++ compiler toolchain (GCC/Clang/MSVC/clang-cl)
18+
- Ninja
19+
- Task (`go-task`)
20+
- Git
21+
22+
### Python tooling (benchmarks/docs)
23+
24+
- Python >= 3.12
25+
- `uv`
26+
- pngquant
27+
28+
Python dependencies are managed by `uv`.
29+
30+
### Why Windows development is recommended
31+
32+
Windows development is recommended when contributing significant changes, because this repository validates both `msvc` and `clang-cl` in CI and those toolchains are easiest to reproduce locally on Windows.
33+
34+
However, since it is difficult to generate a proper Compilation database with MSVC and clang-cl, if you are developing on Windows, configuring with MinGW GCC or Clang is also required.
35+
36+
Linux/macOS development is still fine for day-to-day work, especially for GCC/Clang checks.
37+
38+
### Dev Container support
39+
40+
This repository includes a Dev Container at `.devcontainer/`.
41+
Use it if you want a reproducible Linux environment without installing tools manually.
42+
43+
## Quick start
44+
45+
### 1) Clone
46+
47+
```bash
48+
git clone https://github.com/<your-account>/libcpprime.git
49+
cd libcpprime
50+
```
51+
52+
### 2) Install dependencies
53+
54+
- Install CMake, compiler(s), and Task.
55+
- For docs/benchmark plots, install Python 3.12+ and `uv`.
56+
57+
### 3) Run tests
58+
59+
```bash
60+
task test:gcc
61+
task test:clang
62+
task test:msvc
63+
task test:clang-cl
64+
```
65+
66+
Typical runtime for tests is around 20-60 seconds per run.
67+
68+
## Command reference
69+
70+
All project commands are defined in `Taskfile.yml`.
71+
72+
### Configure
73+
74+
- `task configure:gcc|clang|clang-cl|msvc`: Configure a build directory
75+
- `task configure`: Run all configure tasks above
76+
77+
### Tests
78+
79+
- `task test:gcc|clang|clang-cl|msvc`: Run tests
80+
- `task test`: Run all test tasks above
81+
82+
### Benchmarks
83+
84+
- `task bench:gcc|clang|clang-cl|msvc`: Run standard benchmark and generate plots
85+
- `task bench-heavy:gcc|clang|clang-cl|msvc`: Run heavier benchmark variant (`--heavy`)
86+
87+
### Docs
88+
89+
- `task docs`: Copy `README.md` to `docs/index.md`, then build MkDocs site
90+
- `task serve`: Serve MkDocs locally
91+
92+
### Clean
93+
94+
- `task clean:gcc|clang|clang-cl|msvc`: Remove one build directory
95+
- `task clean`: Remove all build directories

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Rac75116
3+
Copyright (c) 2026 Rac75116
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)