Skip to content

Commit dc6ac5f

Browse files
committed
Add C++17 bindings
1 parent 936160f commit dc6ac5f

823 files changed

Lines changed: 115903 additions & 320 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.

.github/ci-versions.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ CI_RUST=1.93.1
22
CI_GO=1.22.3
33
CI_GOLANGCI_LINT=2.12.2
44
CI_PYTHON=3.10
5+
CI_CLANG_FORMAT=22.1.5

.github/workflows/docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ jobs:
6060
"$PYTHON_PATH" -m pip install -r docs/requirements.txt
6161
6262
- name: Install maturin and Python build dependencies
63-
run: "$PYTHON_PATH" -m pip install -r requirements.txt
63+
run: |
64+
"$PYTHON_PATH" -m pip install -r requirements.txt
6465
6566
- name: Setup just
6667
uses: extractions/setup-just@v3

.github/workflows/release.yml

Lines changed: 101 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ jobs:
241241
shell: bash
242242
run: just --justfile "$JUSTFILE" copy-python-metadata
243243

244+
- name: Use static MSVC CRT for Windows wheel
245+
if: matrix.target == 'x86_64-pc-windows-msvc'
246+
shell: bash
247+
run: echo "RUSTFLAGS=-C target-feature=+crt-static" >> "$GITHUB_ENV"
248+
244249
- name: Build Linux wheel
245250
if: startsWith(matrix.os, 'ubuntu')
246251
uses: PyO3/maturin-action@v1
@@ -271,15 +276,12 @@ jobs:
271276
echo "WHEEL_PATH=${WHEEL_PATH}" >> "$GITHUB_ENV"
272277
273278
- name: Install built wheel
274-
if:
275-
matrix.name == 'linux-x86_64-manylinux2014' || !startsWith(matrix.os,
276-
'ubuntu')
277-
run: "$PYTHON_PATH" -m pip install --force-reinstall --no-deps "${{ env.WHEEL_PATH }}"
279+
if: matrix.name == 'linux-x86_64-manylinux2014' || !startsWith(matrix.os, 'ubuntu')
280+
run: |
281+
"$PYTHON_PATH" -m pip install --force-reinstall --no-deps "${{ env.WHEEL_PATH }}"
278282
279283
- name: Verify wheel import and version
280-
if:
281-
matrix.name == 'linux-x86_64-manylinux2014' || !startsWith(matrix.os,
282-
'ubuntu')
284+
if: matrix.name == 'linux-x86_64-manylinux2014' || !startsWith(matrix.os, 'ubuntu')
283285
shell: bash
284286
env:
285287
BASE_VERSION: ${{ needs.verify-tag.outputs.base_version }}
@@ -288,9 +290,7 @@ jobs:
288290
run: just --justfile "$JUSTFILE" verify-wheel-version "$RELEASE_MODE" "$VERSION" "$BASE_VERSION"
289291

290292
- name: Run wheel tests
291-
if:
292-
matrix.name == 'linux-x86_64-manylinux2014' || !startsWith(matrix.os,
293-
'ubuntu')
293+
if: matrix.name == 'linux-x86_64-manylinux2014' || !startsWith(matrix.os, 'ubuntu')
294294
shell: bash
295295
run: just --justfile "$JUSTFILE" test-wheel
296296

@@ -520,11 +520,19 @@ jobs:
520520
$src = "target/${{ matrix.target }}/release/${{ matrix.lib_name }}"
521521
$dst = "dist/openpit-ffi--${{ matrix.goos }}-${{ matrix.goarch }}-${{ matrix.lib_name }}"
522522
Copy-Item $src $dst -Force
523+
$implibSrc = "$src.lib"
524+
if (!(Test-Path $implibSrc)) {
525+
throw "MSVC import library not found at $implibSrc"
526+
}
527+
$implibDst = "$dst.lib"
528+
Copy-Item $implibSrc $implibDst -Force
523529
Copy-Item bindings/c/openpit.h dist/openpit.h -Force
524530
Copy-Item LICENSE dist/LICENSE -Force
525531
Copy-Item OWNERS dist/OWNERS -Force
526532
$hash = (Get-FileHash -Path $dst -Algorithm SHA256).Hash.ToLower()
527533
Set-Content -Path "$dst.sha256" -Value $hash
534+
$implibHash = (Get-FileHash -Path $implibDst -Algorithm SHA256).Hash.ToLower()
535+
Set-Content -Path "$implibDst.sha256" -Value $implibHash
528536
529537
- name: Upload runtime artifacts
530538
if: ${{ needs.verify-tag.outputs.release_mode == 'production' }}
@@ -543,12 +551,82 @@ jobs:
543551
if-no-files-found: error
544552
retention-days: 1
545553

554+
build-cpp-distributable:
555+
name: Build C++ distributable
556+
needs:
557+
- verify
558+
- verify-tag
559+
runs-on: ubuntu-22.04
560+
steps:
561+
- name: Checkout
562+
uses: actions/checkout@v4
563+
564+
- name: Load CI versions
565+
shell: bash
566+
run: cat "$GITHUB_WORKSPACE/.github/ci-versions.env" >> "$GITHUB_ENV"
567+
568+
- name: Setup Rust
569+
uses: dtolnay/rust-toolchain@stable
570+
with:
571+
toolchain: ${{ env.CI_RUST }}
572+
573+
- name: Cache Rust build
574+
uses: Swatinem/rust-cache@v2
575+
576+
- name: Setup CMake
577+
uses: jwlawson/actions-setup-cmake@v2
578+
with:
579+
cmake-version: "3.28"
580+
581+
- name: Setup just
582+
uses: extractions/setup-just@v3
583+
584+
- name: Build C++ binding
585+
shell: bash
586+
run: just build-cpp
587+
588+
- name: Install C++ binding into staging prefix
589+
shell: bash
590+
env:
591+
VERSION: ${{ needs.verify-tag.outputs.version }}
592+
run: |
593+
set -euo pipefail
594+
cmake --install bindings/cpp/build \
595+
--prefix /tmp/openpit-cpp-install \
596+
--config Release
597+
cp LICENSE /tmp/openpit-cpp-install/LICENSE
598+
cp OWNERS /tmp/openpit-cpp-install/OWNERS
599+
600+
- name: Package C++ distributable
601+
shell: bash
602+
env:
603+
VERSION: ${{ needs.verify-tag.outputs.version }}
604+
run: just --justfile "$JUSTFILE" package-cpp /tmp/openpit-cpp-install
605+
606+
- name: Upload C++ artifact
607+
if: ${{ needs.verify-tag.outputs.release_mode == 'production' }}
608+
uses: actions/upload-artifact@v4
609+
with:
610+
name: cpp-distributable
611+
path: dist/openpit-cpp--*.tar.gz*
612+
if-no-files-found: error
613+
614+
- name: Upload C++ artifact (dry-run)
615+
if: ${{ needs.verify-tag.outputs.release_mode == 'dry-run' }}
616+
uses: actions/upload-artifact@v4
617+
with:
618+
name: cpp-distributable
619+
path: dist/openpit-cpp--*.tar.gz*
620+
if-no-files-found: error
621+
retention-days: 1
622+
546623
publish-go-sources:
547624
name: Publish pit-go sources
548625
needs:
549626
- publish-rust
550627
- publish-sdist
551628
- build-runtime-artifacts
629+
- build-cpp-distributable
552630
- verify-tag
553631
runs-on: ubuntu-22.04
554632
permissions:
@@ -708,6 +786,7 @@ jobs:
708786
- publish-rust
709787
- publish-sdist
710788
- build-runtime-artifacts
789+
- build-cpp-distributable
711790
- verify-tag
712791
if: ${{ needs.verify-tag.outputs.release_mode == 'production' }}
713792
runs-on: ubuntu-22.04
@@ -724,6 +803,12 @@ jobs:
724803
path: release-assets
725804
merge-multiple: true
726805

806+
- name: Download C++ distributable artifact
807+
uses: actions/download-artifact@v4
808+
with:
809+
name: cpp-distributable
810+
path: release-assets
811+
727812
- name: Create GitHub Release with runtime assets
728813
shell: bash
729814
run: |
@@ -736,8 +821,12 @@ jobs:
736821
- crates.io: https://crates.io/crates/openpit
737822
- PyPI: https://pypi.org/project/openpit/${{ needs.verify-tag.outputs.version }}/
738823
739-
Runtime artifacts for Go SDK delivery are attached to this release
740-
(`.so`, `.dylib`, `.dll` and `.sha256` files per target).
824+
Runtime artifacts for SDK delivery are attached to this release
825+
(\`.so\`, \`.dylib\`, \`.dll\`, Windows \`.dll.lib\`, and
826+
\`.sha256\` files per target).
827+
828+
The C++ distributable (\`openpit-cpp--${{ needs.verify-tag.outputs.version }}.tar.gz\`)
829+
contains the public headers and CMake config-file package.
741830
EOF
742831
743832
mapfile -t ASSETS < <(find release-assets -type f | sort)

.github/workflows/verify.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,111 @@ jobs:
128128
- name: Check C
129129
run: just --justfile "$JUSTFILE" test-c-examples
130130

131+
cpp:
132+
name: C++ checks (${{ matrix.name }})
133+
runs-on: ${{ matrix.os }}
134+
strategy:
135+
fail-fast: false
136+
matrix:
137+
include:
138+
- name: linux-gcc
139+
os: ubuntu-22.04
140+
cc: gcc
141+
cxx: g++
142+
- name: linux-clang
143+
os: ubuntu-22.04
144+
cc: clang
145+
cxx: clang++
146+
- name: macos-appleclang
147+
os: macos-14
148+
cc: clang
149+
cxx: clang++
150+
- name: windows-msvc
151+
os: windows-2022
152+
steps:
153+
- name: Checkout
154+
uses: actions/checkout@v4
155+
156+
- name: Load CI versions
157+
shell: bash
158+
run: cat "$GITHUB_WORKSPACE/.github/ci-versions.env" >> "$GITHUB_ENV"
159+
160+
- name: Setup Rust
161+
uses: dtolnay/rust-toolchain@stable
162+
with:
163+
toolchain: ${{ env.CI_RUST }}
164+
165+
- name: Cache Rust build
166+
uses: Swatinem/rust-cache@v2
167+
168+
- name: Setup CMake
169+
uses: jwlawson/actions-setup-cmake@v2
170+
with:
171+
cmake-version: "3.28"
172+
173+
- name: Setup just
174+
uses: extractions/setup-just@v3
175+
176+
- name: Install C++ tooling (Linux)
177+
if: startsWith(matrix.os, 'ubuntu')
178+
run: |
179+
sudo apt-get update
180+
sudo apt-get install --yes clang-tidy doxygen
181+
182+
- name: Install C++ tooling (macOS)
183+
if: startsWith(matrix.os, 'macos')
184+
run: brew install doxygen
185+
186+
# clang-format ships a per-OS-divergent format from apt/brew, so pin one
187+
# wheel-packaged build across every runner to keep fmt-check deterministic.
188+
- name: Install pinned clang-format
189+
if: ${{ matrix.os != 'windows-2022' }}
190+
shell: bash
191+
run: |
192+
pipx install "clang-format==${CI_CLANG_FORMAT}"
193+
# Prepend pipx's bin dir so the pinned build shadows any clang-format
194+
# already baked into the runner image (e.g. /usr/bin/clang-format).
195+
CF_BIN_DIR="$(pipx environment --value PIPX_BIN_DIR)"
196+
echo "$CF_BIN_DIR" >> "$GITHUB_PATH"
197+
"$CF_BIN_DIR/clang-format" --version
198+
199+
- name: Build C++ binding
200+
shell: bash
201+
run: |
202+
if [[ -n "${{ matrix.cc }}" ]]; then
203+
export CC="${{ matrix.cc }}"
204+
export CXX="${{ matrix.cxx }}"
205+
fi
206+
just build-cpp
207+
208+
- name: Test C++ binding
209+
shell: bash
210+
run: just test-cpp
211+
212+
- name: Build and test C++ examples
213+
shell: bash
214+
run: |
215+
if [[ -n "${{ matrix.cc }}" ]]; then
216+
export CC="${{ matrix.cc }}"
217+
export CXX="${{ matrix.cxx }}"
218+
fi
219+
just test-examples-cpp
220+
221+
- name: Check C++ formatting
222+
if: ${{ matrix.os != 'windows-2022' }}
223+
shell: bash
224+
run: just fmt-check-cpp
225+
226+
- name: Generate C++ API reference
227+
if: ${{ matrix.os != 'windows-2022' }}
228+
shell: bash
229+
run: just gen-docs-cpp
230+
231+
- name: Lint C++ sources
232+
if: startsWith(matrix.os, 'ubuntu')
233+
shell: bash
234+
run: just lint-cpp
235+
131236
go:
132237
name: Go checks
133238
runs-on: ubuntu-22.04

0 commit comments

Comments
 (0)