Skip to content

Commit 4fd9d57

Browse files
committed
sync version
1 parent f094f39 commit 4fd9d57

6 files changed

Lines changed: 99 additions & 27 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,14 @@ set_target_properties(libcachesim_python PROPERTIES
274274
INSTALL_RPATH "$ORIGIN"
275275
)
276276

277-
target_compile_definitions(libcachesim_python PRIVATE VERSION_INFO=${PROJECT_VERSION})
277+
if(DEFINED SKBUILD_PROJECT_VERSION AND NOT SKBUILD_PROJECT_VERSION STREQUAL "")
278+
set(LCS_PYTHON_VERSION ${SKBUILD_PROJECT_VERSION})
279+
else()
280+
set(LCS_PYTHON_VERSION "dev")
281+
endif()
282+
message(STATUS "libcachesim_python version: ${LCS_PYTHON_VERSION}")
283+
284+
target_compile_definitions(libcachesim_python PRIVATE VERSION_INFO=${LCS_PYTHON_VERSION})
278285

279286
# =============================================================================
280287
# Platform-Specific Configuration

‎docs/src/en/getting_started/installation.md‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,26 @@ dependencies that CMake looks for at configure time: **pkg-config**, **GLib 2.0*
128128
`find_package(ZSTD REQUIRED)` — and a missing one aborts configuration before any code is
129129
compiled, with an error such as `No package 'glib-2.0' found`.
130130

131-
The dependency scripts above install them on the platforms they cover (`install_deps.sh` targets
132-
yum-based distributions and macOS). On Debian/Ubuntu, use the submodule's script or install them
133-
directly:
131+
`scripts/install_deps.sh` installs them on Debian/Ubuntu, CentOS/RHEL and macOS, picking the
132+
package manager to use automatically. It calls `sudo` only when not already running as root:
134133

135134
```bash
136-
bash src/libCacheSim/scripts/install_dependency.sh
135+
bash scripts/install_deps.sh
136+
```
137+
138+
Or, on Debian/Ubuntu or macOS, install just the three by hand:
137139

138-
# or, the minimum needed to configure the build
140+
```bash
141+
# Debian/Ubuntu
139142
sudo apt install -y pkg-config libglib2.0-dev libzstd-dev
143+
144+
# macOS
145+
brew install pkgconf glib zstd
140146
```
141147

148+
On CentOS/RHEL prefer the script: it builds Zstandard from source, because the version in the
149+
base repositories is often too old.
150+
142151
The build itself is driven by [scikit-build-core](https://scikit-build-core.readthedocs.io/),
143152
which configures and builds the bundled C library before compiling the
144153
[pybind11](https://pybind11.readthedocs.io/) bindings.

‎docs/src/zh/getting_started/installation.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,24 @@ bash scripts/install.sh --all
107107

108108
构建扩展需要支持 C++17 的编译器、CMake ≥ 3.15 以及 Ninja,另外还需要三个在 configure 阶段查找的原生依赖:**pkg-config**、**GLib 2.0** 和 **Zstandard**。这三者都是必需的——`CMakeLists.txt` 中分别以 `find_package(PkgConfig REQUIRED)`、`pkg_check_modules(GLib REQUIRED glib-2.0)` 和 `find_package(ZSTD REQUIRED)` 声明——缺少任意一个都会在编译任何代码之前中断配置,并报出类似 `No package 'glib-2.0' found` 的错误。
109109

110-
上文的依赖脚本会在其支持的平台上安装它们(`install_deps.sh` 面向基于 yum 的发行版和 macOS)。在 Debian/Ubuntu 上,请使用子模块提供的脚本,或直接安装:
110+
`scripts/install_deps.sh` 会在 Debian/Ubuntu、CentOS/RHEL 和 macOS 上安装它们,并自动选择对应的包管理器;只有在非 root 身份运行时才会调用 `sudo`:
111111

112112
```bash
113-
bash src/libCacheSim/scripts/install_dependency.sh
113+
bash scripts/install_deps.sh
114+
```
115+
116+
如果不想运行该脚本,在 Debian/Ubuntu 或 macOS 上也可以手动只安装这三个依赖:
114117

115-
# 或者只装配置构建所需的最小集合
118+
```bash
119+
# Debian/Ubuntu
116120
sudo apt install -y pkg-config libglib2.0-dev libzstd-dev
121+
122+
# macOS
123+
brew install pkgconf glib zstd
117124
```
118125

126+
在 CentOS/RHEL 上建议直接使用脚本:它会从源码构建 Zstandard,因为基础仓库中的版本通常过旧。
127+
119128
构建本身由 [scikit-build-core](https://scikit-build-core.readthedocs.io/) 驱动,它会先配置并构建内置的 C 库,再编译 [pybind11](https://pybind11.readthedocs.io/) 绑定。
120129

121130
## 疑难排查

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build-backend = "scikit_build_core.build"
99

1010
[project]
1111
name = "libcachesim"
12-
version = "0.3.3.post4"
12+
version = "0.3.5"
1313
description="Python bindings for libCacheSim"
1414
readme = "README.md"
1515
requires-python = ">=3.10"

‎scripts/install_deps.sh‎

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ log_error() {
2121
echo -e "${RED}[ERROR]${NC} $1" >&2
2222
}
2323

24+
# Elevation helper.
25+
#
26+
# This script is both a developer convenience and cibuildwheel's `before-all`
27+
# (see [tool.cibuildwheel] in pyproject.toml), where it runs as root inside the
28+
# manylinux container with no sudo available. Running as root leaves SUDO empty,
29+
# so every command below is byte-for-byte what it was before this helper existed.
30+
SUDO=""
31+
if [[ ${EUID} -ne 0 ]]; then
32+
if command -v sudo >/dev/null 2>&1; then
33+
SUDO="sudo"
34+
else
35+
log_error "This script needs root privileges, but neither root nor sudo is available."
36+
exit 1
37+
fi
38+
fi
39+
2440
# Install and configure g++ version
2541
install_gcc() {
2642
log_info "Installing and configuring g++ version..."
@@ -96,7 +112,7 @@ install_zstd() {
96112
pushd _build >/dev/null
97113
cmake -G Ninja ..
98114
ninja
99-
ninja install
115+
${SUDO} ninja install
100116
popd >/dev/null
101117
popd >/dev/null
102118
popd >/dev/null
@@ -114,7 +130,7 @@ install_xgboost() {
114130
pushd build >/dev/null
115131
cmake -G Ninja ..
116132
ninja
117-
ninja install
133+
${SUDO} ninja install
118134
popd >/dev/null
119135
popd >/dev/null
120136
popd >/dev/null
@@ -132,16 +148,45 @@ install_lightgbm() {
132148
pushd build >/dev/null
133149
cmake -G Ninja ..
134150
ninja
135-
ninja install
151+
${SUDO} ninja install
136152
popd >/dev/null
137153
popd >/dev/null
138154
popd >/dev/null
139155
}
140156

141-
# Detect OS and install dependencies
142-
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
143-
log_info "Detected Linux system, installing dependencies via yum..."
144-
157+
# Detect OS and install dependencies.
158+
#
159+
# Dispatch on the available package manager rather than on $OSTYPE alone, so that
160+
# this covers the same platforms as upstream's
161+
# src/libCacheSim/scripts/install_dependency.sh (Debian/Ubuntu/WSL, macOS,
162+
# CentOS/RHEL). macOS is matched first; the manylinux images used for the release
163+
# wheels ship yum/dnf but no apt-get, so they still take the yum branch below.
164+
if [[ "$OSTYPE" == "darwin"* ]]; then
165+
log_info "Detected macOS system, installing dependencies via brew..."
166+
167+
# Install basic dependencies via Homebrew
168+
brew install glib google-perftools argp-standalone xxhash llvm wget cmake ninja zstd xgboost lightgbm
169+
170+
elif command -v apt-get >/dev/null 2>&1; then
171+
log_info "Detected Debian/Ubuntu system, installing dependencies via apt..."
172+
173+
${SUDO} apt-get update
174+
# CMakeLists.txt requires pkg-config, GLib 2.0 and Zstandard; the rest mirrors
175+
# upstream's setup_ubuntu. Unlike the yum branch there is no need to build CMake
176+
# or Zstd from source, since apt ships cmake >= 3.15 and libzstd-dev.
177+
${SUDO} apt-get install -y --no-install-recommends \
178+
build-essential pkg-config git wget cmake ninja-build \
179+
libglib2.0-dev libzstd-dev \
180+
libgoogle-perftools-dev google-perftools xxhash libunwind-dev
181+
182+
# Needed by the optional learned algorithms (ENABLE_GLCACHE / ENABLE_3L_CACHE /
183+
# ENABLE_LRB); no distro packages provide the CMake config files these need.
184+
install_xgboost
185+
install_lightgbm
186+
187+
elif command -v yum >/dev/null 2>&1 || command -v dnf >/dev/null 2>&1; then
188+
log_info "Detected CentOS/RHEL system, installing dependencies via yum..."
189+
145190
# Enable EPEL repository
146191
yum install -y epel-release
147192

@@ -167,15 +212,9 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
167212
install_zstd
168213
install_xgboost
169214
install_lightgbm
170-
171-
elif [[ "$OSTYPE" == "darwin"* ]]; then
172-
log_info "Detected macOS system, installing dependencies via brew..."
173-
174-
# Install basic dependencies via Homebrew
175-
brew install glib google-perftools argp-standalone xxhash llvm wget cmake ninja zstd xgboost lightgbm
176-
215+
177216
else
178-
log_error "Unsupported operating system: $OSTYPE"
217+
log_error "Unsupported operating system: $OSTYPE (no brew, apt-get, yum or dnf found)"
179218
exit 1
180219
fi
181220

‎scripts/sync_version.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
from pathlib import Path
1414

1515

16+
# Matches the [project] version line. The trailing [^"]* accepts PEP 440 suffixes such
17+
# as ".post4", "rc1" or ".dev0" -- an earlier pattern required exactly N.N.N, so a
18+
# version like "0.3.3.post4" matched nothing and this script silently stopped syncing.
19+
# Anchoring on "dev" or a leading digit keeps it from matching pins like ">=3.15".
20+
VERSION_LINE_RE = r"version = \"(dev|[0-9]+\.[0-9]+\.[0-9]+[^\"]*)\""
21+
22+
1623
def get_project_root():
1724
"""Get the project root directory."""
1825
script_dir = Path(__file__).parent
@@ -52,7 +59,7 @@ def update_pyproject_toml(version):
5259
pyproject_data = f.read()
5360

5461
# Update the version line in pyproject.toml, make it can match any version in version.txt, like "0.3.1" or "dev"
55-
match = re.search(r"version = \"(dev|[0-9]+\.[0-9]+\.[0-9]+)\"", pyproject_data)
62+
match = re.search(VERSION_LINE_RE, pyproject_data)
5663
if not match:
5764
print("Error: Could not find a valid version line in pyproject.toml", file=sys.stderr)
5865
return False
@@ -65,7 +72,8 @@ def update_pyproject_toml(version):
6572
print(f"Warning: pyproject version {current_version} is newer than version.txt {version}, skipping update")
6673
return False
6774
# replace the version line with the new version
68-
pyproject_data = re.sub(r"version = \"(dev|[0-9]+\.[0-9]+\.[0-9]+)\"", f'version = "{version}"', pyproject_data)
75+
# count=1: only the [project] version, never the tool version pins further down.
76+
pyproject_data = re.sub(VERSION_LINE_RE, f'version = "{version}"', pyproject_data, count=1)
6977

7078
# Write back to file with proper formatting
7179
with open(pyproject_toml_path, "w") as f:

0 commit comments

Comments
 (0)