Skip to content

Commit 5538e72

Browse files
committed
Use uv for both doc and lib
1 parent d71f1f7 commit 5538e72

File tree

3 files changed

+89
-36
lines changed

3 files changed

+89
-36
lines changed

.github/workflows/build.yml

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,55 @@ permissions:
77

88
jobs:
99
build:
10-
runs-on: ubuntu-latest
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest, macos-14]
14+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
15+
1116
steps:
1217
- uses: actions/checkout@v4
13-
14-
- name: Set up Python
15-
uses: actions/setup-python@v4
1618
with:
17-
python-version: "3.10"
19+
submodules: recursive
1820

19-
- name: Init submodules
20-
run: git submodule update --init --recursive
21-
22-
- name: Prepare
23-
run: bash src/libCacheSim/scripts/install_dependency.sh
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v4
23+
with:
24+
version: "latest"
2425

25-
- name: Build main libCacheSim project
26-
run: |
27-
pushd src/libCacheSim
28-
cmake -G Ninja -B build
29-
ninja -C build
30-
popd
26+
- name: Set up Python ${{ matrix.python-version }}
27+
run: uv python install ${{ matrix.python-version }}
3128

32-
- name: Build libCacheSim-python
29+
- name: Build and test with uv
3330
run: |
34-
pip install -e .[dev]
31+
uv venv --python ${{ matrix.python-version }}
32+
uv pip install -e .[dev]
33+
uv run python -c "import libcachesim; print('✓ Import successful for Python ${{ matrix.python-version }} on ${{ matrix.os }}')"
3534
3635
- name: Run tests
3736
run: |
38-
python -m pytest tests/
37+
if [ -d "tests" ]; then
38+
uv run python -m pytest tests/ -v
39+
else
40+
echo "No tests directory found, skipping tests"
41+
fi
3942
4043
docs:
4144
runs-on: ubuntu-latest
4245
steps:
4346
- uses: actions/checkout@v4
4447

45-
- name: Set up Python
46-
uses: actions/setup-python@v4
47-
with:
48-
python-version: "3.x"
49-
50-
- name: Cache dependencies
51-
uses: actions/cache@v3
48+
- name: Install uv
49+
uses: astral-sh/setup-uv@v4
5250
with:
53-
path: ~/.cache/pip
54-
key: ${{ runner.os }}-pip-docs-${{ hashFiles('docs/requirements.txt') }}
55-
restore-keys: |
56-
${{ runner.os }}-pip-docs-
51+
version: "latest"
5752

58-
- name: Install documentation dependencies
59-
run: |
60-
pip install -r docs/requirements.txt
53+
- name: Set up Python
54+
run: uv python install 3.11
6155

62-
- name: Test documentation build
56+
- name: Install documentation dependencies and build
6357
run: |
6458
cd docs
65-
mkdocs build --clean --strict
59+
uv venv
60+
uv pip install -r requirements.txt
61+
uv run mkdocs build --clean --strict

CMakeLists.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,50 @@ project(libCacheSim-python)
33
set(DESCRIPTION "The libCacheSim Python Package")
44
set(PROJECT_WEB "http://cachemon.github.io/libCacheSim-python")
55

6+
# Auto-initialize submodules if not already done
7+
find_package(Git QUIET)
8+
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
9+
# Check if submodule is initialized
10+
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/src/libCacheSim/CMakeLists.txt")
11+
message(STATUS "Initializing git submodules...")
12+
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
13+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
14+
RESULT_VARIABLE GIT_SUBMOD_RESULT)
15+
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
16+
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}")
17+
endif()
18+
endif()
19+
endif()
20+
21+
# Auto-build libCacheSim if needed
22+
set(LIBCACHESIM_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/libCacheSim")
23+
if(NOT EXISTS "${LIBCACHESIM_SOURCE_DIR}/CMakeLists.txt")
24+
message(FATAL_ERROR "libCacheSim submodule not found. Please run 'git submodule update --init --recursive'")
25+
endif()
26+
27+
# Build libCacheSim first
28+
set(LIBCACHESIM_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/libCacheSim/build")
29+
if(NOT EXISTS "${LIBCACHESIM_BUILD_DIR}/export_vars.cmake")
30+
message(STATUS "Building libCacheSim...")
31+
execute_process(
32+
COMMAND ${CMAKE_COMMAND} -S ${LIBCACHESIM_SOURCE_DIR} -B ${LIBCACHESIM_BUILD_DIR} -G Ninja
33+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
34+
RESULT_VARIABLE CMAKE_CONFIG_RESULT
35+
)
36+
if(NOT CMAKE_CONFIG_RESULT EQUAL "0")
37+
message(FATAL_ERROR "Failed to configure libCacheSim")
38+
endif()
39+
40+
execute_process(
41+
COMMAND ${CMAKE_COMMAND} --build ${LIBCACHESIM_BUILD_DIR}
42+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
43+
RESULT_VARIABLE CMAKE_BUILD_RESULT
44+
)
45+
if(NOT CMAKE_BUILD_RESULT EQUAL "0")
46+
message(FATAL_ERROR "Failed to build libCacheSim")
47+
endif()
48+
endif()
49+
650
# Note(haocheng): now we still utilize the exported cache from
751
# the main project, which should be deprecated soon
852

pyproject.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
[build-system]
2-
requires = ["scikit-build-core>=0.10", "pybind11"]
2+
requires = [
3+
"scikit-build-core>=0.10",
4+
"pybind11",
5+
"cmake>=3.15",
6+
"ninja; platform_system!='Windows'",
7+
"setuptools_scm[toml]>=6.2"
8+
]
39
build-backend = "scikit_build_core.build"
410

511

@@ -36,6 +42,13 @@ dev = [
3642

3743
[tool.scikit-build]
3844
wheel.expand-macos-universal-tags = true
45+
build-dir = "build"
46+
cmake.build-type = "Release"
47+
cmake.args = ["-G", "Ninja"]
48+
cmake.define = { CMAKE_OSX_DEPLOYMENT_TARGET = "14.0" }
49+
cmake.version = ">=3.15"
50+
cmake.source-dir = "."
51+
install.strip = false
3952

4053
[tool.pytest.ini_options]
4154
minversion = "8.0"

0 commit comments

Comments
 (0)