Skip to content

Commit e471815

Browse files
committed
update
1 parent 905e694 commit e471815

4 files changed

Lines changed: 47 additions & 31 deletions

File tree

‎.github/workflows/python-wheels.yml‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,6 @@ jobs:
3131
fetch-depth: 1
3232
show-progress: true
3333

34-
- name: Resolve release version
35-
if: github.event_name == 'release'
36-
id: release_version
37-
shell: bash
38-
run: |
39-
tag="${GITHUB_REF_NAME}"
40-
echo "value=${tag#v}" >> "$GITHUB_OUTPUT"
41-
42-
- name: Set version for release
43-
if: github.event_name == 'release'
44-
shell: bash
45-
run: |
46-
python - <<'PY'
47-
from pathlib import Path
48-
49-
path = Path("pyproject.toml")
50-
data = path.read_text(encoding="utf-8")
51-
version = "${{ steps.release_version.outputs.value }}"
52-
old = 'version = "0.1.0"'
53-
new = f'version = "{version}"'
54-
if old not in data:
55-
raise SystemExit('Expected version string not found in pyproject.toml')
56-
data = data.replace(old, new, 1)
57-
path.write_text(data, encoding="utf-8")
58-
PY
59-
6034
- name: Build wheels
6135
uses: pypa/cibuildwheel@v3.1.0
6236
env:

‎CMakeLists.txt‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
1-
cmake_minimum_required(VERSION 3.18)
1+
cmake_minimum_required(VERSION 3.26)
22

3-
project(hello_cpp VERSION 0.1.0 LANGUAGES CXX)
3+
function(split_version str MAJOR MINOR PATCH)
4+
# Parse the string directly into the names provided by the arguments
5+
string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ ${str})
6+
7+
set(${MAJOR} ${CMAKE_MATCH_1})
8+
set(${MINOR} ${CMAKE_MATCH_2})
9+
set(${PATCH} ${CMAKE_MATCH_3})
10+
11+
return(PROPAGATE ${MAJOR} ${MINOR} ${PATCH})
12+
endfunction()
13+
14+
if(DEFINED SKBUILD_PROJECT_VERSION)
15+
set(HELLO_CPP_VERSION ${SKBUILD_PROJECT_VERSION})
16+
else()
17+
set(HELLO_CPP_VERSION "0.9.0")
18+
endif()
19+
20+
split_version(${HELLO_CPP_VERSION}
21+
HELLO_CPP_VERSION_MAJOR
22+
HELLO_CPP_VERSION_MINOR
23+
HELLO_CPP_VERSION_PATCH)
24+
25+
project(hello_cpp VERSION ${HELLO_CPP_VERSION} LANGUAGES CXX)
26+
27+
message(STATUS "HELLO_CPP_VERSION_MAJOR: ${HELLO_CPP_VERSION_MAJOR}")
28+
message(STATUS "HELLO_CPP_VERSION_MINOR: ${HELLO_CPP_VERSION_MINOR}")
29+
message(STATUS "HELLO_CPP_VERSION_PATCH: ${HELLO_CPP_VERSION_PATCH}")
430

531
set(CMAKE_CXX_STANDARD 17)
632
set(CMAKE_CXX_STANDARD_REQUIRED ON)
733

834
find_package(pybind11 CONFIG REQUIRED)
935

36+
1037
pybind11_add_module(hello_cpp src/hello.cpp)
38+
target_compile_definitions(hello_cpp PUBLIC HELLO_CPP_VERSION="${HELLO_CPP_VERSION}")
1139

1240
install(
1341
TARGETS hello_cpp

‎pyproject.toml‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["scikit-build-core>=0.9.0", "pybind11>=2.11.0"]
2+
requires = ["scikit-build-core>=0.9.0", "pybind11>=2.11.0", "setuptools-scm"]
33
build-backend = "scikit_build_core.build"
44

55
[project]
66
name = "hello-cpp"
7-
version = "0.1.0"
7+
dynamic = ["version"]
88
description = "Minimal pybind11 hello world module built with CMake."
99
readme = "README.md"
1010
requires-python = ">=3.11,<3.12"
@@ -20,7 +20,21 @@ dependencies = [
2020
]
2121

2222
[tool.scikit-build]
23+
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
2324
minimum-version = "0.9"
2425
cmake.version = ">=3.26"
2526
build-dir = "build/{wheel_tag}"
2627
wheel.packages = []
28+
29+
[tool.uv.workspace]
30+
members = [
31+
".",
32+
]
33+
34+
[tool.uv.sources]
35+
hello-cpp = { workspace = true, editable = true }
36+
37+
[dependency-groups]
38+
dev = [
39+
"hello-cpp",
40+
]

‎src/hello.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace py = pybind11;
44

55
std::string hello() {
6-
return "Hello from C++!";
6+
return std::string("v") + std::string(HELLO_CPP_VERSION) + ": Hello from C++!";
77
}
88

99
PYBIND11_MODULE(hello_cpp, m) {

0 commit comments

Comments
 (0)