-
Notifications
You must be signed in to change notification settings - Fork 81
[FEATURE]: create python binding #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3185063
Use scikit build
haochengxia bd1b0aa
Feat: support plugin in python
haochengxia c3b66d4
Clean up
haochengxia 1808ded
Apply the suggestion from copilot
haochengxia ef02bfb
Remove create_cache
haochengxia 2fbede9
Remove redundant header
haochengxia 9678a2d
Complete binding for trace type
haochengxia f1909d3
Clean up python code
haochengxia 22c4953
Update README.md
haochengxia 0b0cef4
Prepare for PyPI
haochengxia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Python | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: "3.10" | ||
|
|
||
| - name: Prepare | ||
| run: bash scripts/install_dependency.sh | ||
|
|
||
| - name: Build main libCacheSim project | ||
| run: | | ||
| cmake -G Ninja -B build | ||
| ninja -C build | ||
|
|
||
| - name: Install Python dependencies | ||
| run: | | ||
| pip install --upgrade pip | ||
| pip install -r requirements.txt | ||
| pip install pytest | ||
|
|
||
| - name: Build libCacheSim-python | ||
| run: | | ||
| cd libCacheSim-python | ||
| pip install -e . | ||
|
|
||
| - name: Run tests | ||
| run: | | ||
| cd libCacheSim-python | ||
| pytest tests/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,5 @@ sftp-config.json | |
| # Clangd cache | ||
| *.cache/ | ||
| .lint-logs/ | ||
| # Python wheels | ||
| *.whl | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Automatically generated by `hgimportsvn` | ||
| .svn | ||
| .hgsvn | ||
|
|
||
| # Ignore local virtualenvs | ||
| lib/ | ||
| bin/ | ||
| include/ | ||
| .Python/ | ||
|
|
||
| # These lines are suggested according to the svn:ignore property | ||
| # Feel free to enable them by uncommenting them | ||
| *.pyc | ||
| *.pyo | ||
| *.swp | ||
| *.class | ||
| *.orig | ||
| *~ | ||
| .hypothesis/ | ||
|
|
||
| # autogenerated | ||
| src/_pytest/_version.py | ||
| # setuptools | ||
| .eggs/ | ||
|
|
||
| doc/*/_build | ||
| doc/*/.doctrees | ||
| build/ | ||
| dist/ | ||
| *.egg-info | ||
| htmlcov/ | ||
| issue/ | ||
| env/ | ||
| .env/ | ||
| .venv/ | ||
| /pythonenv*/ | ||
| 3rdparty/ | ||
| .tox | ||
| .cache | ||
| .pytest_cache | ||
| .mypy_cache | ||
| .coverage | ||
| .coverage.* | ||
| coverage.xml | ||
| .ropeproject | ||
| .idea | ||
| .hypothesis | ||
| .pydevproject | ||
| .project | ||
| .settings | ||
| .vscode | ||
| __pycache__/ | ||
| .python-version | ||
|
|
||
| # generated by pip | ||
| pip-wheel-metadata/ | ||
|
|
||
| # pytest debug logs generated via --debug | ||
| pytestdebug.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| cmake_minimum_required(VERSION 3.15...3.27) | ||
|
|
||
| # Include exported variables from cache | ||
| if(DEFINED LIBCB_BUILD_DIR) | ||
| set(PARENT_BUILD_DIR "${LIBCB_BUILD_DIR}") | ||
| message(STATUS "Using provided LIBCB_BUILD_DIR: ${LIBCB_BUILD_DIR}") | ||
| else() | ||
| set(PARENT_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../build") | ||
| endif() | ||
| set(EXPORT_FILE "${PARENT_BUILD_DIR}/export_vars.cmake") | ||
|
|
||
| if(EXISTS "${EXPORT_FILE}") | ||
| include("${EXPORT_FILE}") | ||
| message(STATUS "Loaded variables from export_vars.cmake") | ||
| else() | ||
| message(FATAL_ERROR "export_vars.cmake not found at ${EXPORT_FILE}. Please build the main project first (e.g. cd .. && cmake -G Ninja -B build)") | ||
| endif() | ||
|
|
||
| # Force enable -fPIC | ||
| set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") | ||
|
|
||
| project(libCacheSim-python VERSION "${LIBCACHESIM_VERSION}") | ||
|
|
||
| if(LOG_LEVEL_LOWER STREQUAL "default") | ||
| if(CMAKE_BUILD_TYPE_LOWER MATCHES "debug") | ||
| add_compile_definitions(LOGLEVEL=6) | ||
| else() | ||
| add_compile_definitions(LOGLEVEL=7) | ||
| endif() | ||
| elseif(LOG_LEVEL_LOWER STREQUAL "verbose") | ||
| add_compile_definitions(LOGLEVEL=5) | ||
| elseif(LOG_LEVEL_LOWER STREQUAL "debug") | ||
| add_compile_definitions(LOGLEVEL=6) | ||
| elseif(LOG_LEVEL_LOWER STREQUAL "info") | ||
| add_compile_definitions(LOGLEVEL=7) | ||
| elseif(LOG_LEVEL_LOWER STREQUAL "warn") | ||
| add_compile_definitions(LOGLEVEL=8) | ||
| elseif(LOG_LEVEL_LOWER STREQUAL "error") | ||
| add_compile_definitions(LOGLEVEL=9) | ||
| else() | ||
| add_compile_definitions(LOGLEVEL=7) | ||
| endif() | ||
|
|
||
| # Find python and pybind11 | ||
| find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) | ||
| find_package(pybind11 CONFIG REQUIRED) | ||
|
|
||
| # Include directories for dependencies | ||
| include_directories(${GLib_INCLUDE_DIRS}) | ||
| include_directories(${GLib_CONFIG_INCLUDE_DIR}) | ||
| include_directories(${XGBOOST_INCLUDE_DIR}) | ||
| include_directories(${LIGHTGBM_PATH}) | ||
| include_directories(${ZSTD_INCLUDE_DIR}) | ||
| include_directories(${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin) | ||
|
|
||
| # Find the main libCacheSim library | ||
| set(MAIN_PROJECT_BUILD_DIR "${PARENT_BUILD_DIR}") | ||
| set(MAIN_PROJECT_LIB_PATH "${MAIN_PROJECT_BUILD_DIR}/liblibCacheSim.a") | ||
|
|
||
| if(EXISTS "${MAIN_PROJECT_LIB_PATH}") | ||
| message(STATUS "Found pre-built libCacheSim library at ${MAIN_PROJECT_LIB_PATH}") | ||
|
|
||
| # Import the main library as an imported target | ||
| add_library(libCacheSim_main STATIC IMPORTED) | ||
| set_target_properties(libCacheSim_main PROPERTIES | ||
| IMPORTED_LOCATION "${MAIN_PROJECT_LIB_PATH}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/include;${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/utils/include;${MAIN_PROJECT_SOURCE_DIR}/libCacheSim" | ||
| ) | ||
|
|
||
| # Link dependencies that the main library needs | ||
| target_link_libraries(libCacheSim_main INTERFACE ${dependency_libs}) | ||
| set(LIBCACHESIM_TARGET libCacheSim_main) | ||
|
|
||
| else() | ||
| message(FATAL_ERROR "Pre-built libCacheSim library not found. Please build the main project first: cd .. && cmake -G Ninja -B build && ninja -C build") | ||
| endif() | ||
|
|
||
| python_add_library(_libcachesim MODULE | ||
| src/pylibcachesim.cpp | ||
| ${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/cli_reader_utils.c | ||
| WITH_SOABI | ||
| ) | ||
|
|
||
| set_target_properties(_libcachesim PROPERTIES | ||
| POSITION_INDEPENDENT_CODE ON | ||
| INSTALL_RPATH_USE_LINK_PATH TRUE | ||
| BUILD_WITH_INSTALL_RPATH TRUE | ||
| INSTALL_RPATH "$ORIGIN" | ||
| ) | ||
|
|
||
| target_compile_definitions(_libcachesim PRIVATE VERSION_INFO=${PROJECT_VERSION}) | ||
|
|
||
| target_link_libraries(_libcachesim PRIVATE | ||
| ${LIBCACHESIM_TARGET} | ||
| pybind11::headers | ||
| pybind11::module | ||
| -Wl,--no-as-needed -ldl | ||
| ) | ||
|
|
||
| # install to wheel directory | ||
| install(TARGETS _libcachesim LIBRARY DESTINATION libcachesim) |
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.