-
Notifications
You must be signed in to change notification settings - Fork 6
use cmake for compile #1
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
Open
mychaow
wants to merge
2
commits into
chenxu14:main
Choose a base branch
from
mychaow:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -1,4 +1,26 @@ | ||
| # IDE files | ||
| .project | ||
| .cproject | ||
| .settings | ||
| build/ | ||
|
|
||
| # Build directories | ||
| build/ | ||
| cmake-build-*/ | ||
| CMakeCache.txt | ||
| CMakeFiles/ | ||
| Makefile | ||
| cmake_install.cmake | ||
| deps/ | ||
|
|
||
| # Compiled binaries and libraries | ||
| bin/ | ||
| lib/ | ||
|
|
||
| # IDE files | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
|
|
||
| # Backup files | ||
| *~ |
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,3 @@ | ||
| [submodule "third_party/spdk"] | ||
| path = third_party/spdk | ||
| url = https://github.com/spdk/spdk.git |
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,127 @@ | ||
| cmake_minimum_required(VERSION 3.16) | ||
| project(FastFS VERSION 1.0 LANGUAGES CXX C) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 17) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
| set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
|
||
| find_package(Threads REQUIRED) | ||
|
|
||
| set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib64) | ||
| set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib64) | ||
| set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
|
|
||
| set(SCRIPTS_DIR ${CMAKE_SOURCE_DIR}/scripts) | ||
|
|
||
| # SPDK configuration | ||
| if(NOT DEFINED SPDK_ROOT_DIR) | ||
| set(SPDK_ROOT_DIR ${CMAKE_SOURCE_DIR}/third_party/spdk) | ||
| set(SPDK_AUTO_DOWNLOAD ON) | ||
| else() | ||
| set(SPDK_AUTO_DOWNLOAD OFF) | ||
| endif() | ||
| set(SPDK_BUILD_DIR ${SPDK_ROOT_DIR}/build) | ||
|
|
||
| set(DEPS_DIR ${CMAKE_SOURCE_DIR}/deps) | ||
|
|
||
| option(ENABLE_FIO "Enable FIO support" ON) | ||
| set(FIO_VERSION "fio-3.39" CACHE STRING "FIO version to download") | ||
| option(ENABLE_FUSE "Enable FUSE support" ON) | ||
| option(ENABLE_TESTS "Enable unit tests" ON) | ||
| option(BUILD_SPDK "Automatically build SPDK submodule" ON) | ||
| option(BUILD_FIO "Automatically build FIO when enabled" ON) | ||
|
|
||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -O2") | ||
|
|
||
| # SPDK setup and build logic | ||
| if(SPDK_AUTO_DOWNLOAD) | ||
| if(NOT EXISTS ${SPDK_ROOT_DIR}/mk/spdk.common.mk) | ||
| message(FATAL_ERROR "SPDK submodule not found at ${SPDK_ROOT_DIR}. Please run: git submodule update --init") | ||
| endif() | ||
| endif() | ||
|
|
||
| if(BUILD_SPDK) | ||
| set(SPDK_BUILD_COMMAND ${CMAKE_SOURCE_DIR}/scripts/build_spdk.sh ${SPDK_ROOT_DIR} ${CMAKE_SOURCE_DIR}/spdk.patch) | ||
|
|
||
| add_custom_target(build_spdk | ||
| COMMAND ${SPDK_BUILD_COMMAND} | ||
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
| COMMENT "Building SPDK" | ||
| ) | ||
|
|
||
| set(SPDK_DEPENDENCY build_spdk) | ||
| else() | ||
| set(SPDK_DEPENDENCY "") | ||
| endif() | ||
|
|
||
| # FIO configuration and build logic | ||
| if(ENABLE_FIO) | ||
| if(NOT DEFINED FIO_ROOT_DIR) | ||
| include(FetchContent) | ||
|
|
||
| FetchContent_Declare( | ||
| fio | ||
| URL https://github.com/axboe/fio/archive/refs/tags/${FIO_VERSION}.tar.gz | ||
| URL_HASH SHA256=e2f4ff137061b44ceb83a55eb9ca8856fe188db6d9b00cb59f8629c9162afe0a | ||
| DOWNLOAD_DIR ${DEPS_DIR} | ||
| SOURCE_DIR ${DEPS_DIR}/${FIO_VERSION} | ||
| ) | ||
|
|
||
| FetchContent_MakeAvailable(fio) | ||
|
|
||
| set(FIO_ROOT_DIR ${DEPS_DIR}/${FIO_VERSION}) | ||
| set(FIO_AUTO_DOWNLOAD ON) | ||
| else() | ||
| set(FIO_AUTO_DOWNLOAD OFF) | ||
| endif() | ||
|
|
||
| set(FIO_SRC_DIR ${FIO_ROOT_DIR}) | ||
| set(FIO_BUILD_DIR ${FIO_ROOT_DIR}) | ||
|
|
||
| if(BUILD_FIO) | ||
| set(FIO_BUILD_COMMAND ${CMAKE_SOURCE_DIR}/scripts/build_fio.sh ${FIO_SRC_DIR}) | ||
|
|
||
| add_custom_target(build_fio | ||
| COMMAND ${FIO_BUILD_COMMAND} | ||
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
| COMMENT "Building FIO" | ||
| ) | ||
|
|
||
| set(FIO_DEPENDENCY build_fio) | ||
| else() | ||
| set(FIO_DEPENDENCY "") | ||
| endif() | ||
| endif() | ||
|
|
||
| # Core library (always built) | ||
| add_subdirectory(core) | ||
| add_subdirectory(tools) | ||
|
|
||
| # Optional components with centralized condition checks | ||
| if(ENABLE_FUSE) | ||
| add_subdirectory(fuse) | ||
| endif() | ||
|
|
||
| if(ENABLE_TESTS) | ||
| add_subdirectory(test) | ||
| endif() | ||
|
|
||
| # Bench directory (contains both general benchmarks and FIO plugin) | ||
| add_subdirectory(bench) | ||
|
|
||
| install(DIRECTORY ${CMAKE_SOURCE_DIR}/bench/ DESTINATION share/fastfs/bench | ||
| FILES_MATCHING PATTERN "*.json") | ||
|
|
||
| message(STATUS "FastFS configuration:") | ||
| message(STATUS " SPDK_ROOT_DIR: ${SPDK_ROOT_DIR}") | ||
| message(STATUS " SPDK_AUTO_DOWNLOAD: ${SPDK_AUTO_DOWNLOAD}") | ||
| message(STATUS " DEPS_DIR: ${DEPS_DIR}") | ||
| message(STATUS " BUILD_SPDK: ${BUILD_SPDK}") | ||
| message(STATUS " ENABLE_FIO: ${ENABLE_FIO}") | ||
| if(ENABLE_FIO) | ||
| message(STATUS " FIO_ROOT_DIR: ${FIO_ROOT_DIR}") | ||
| message(STATUS " FIO_AUTO_DOWNLOAD: ${FIO_AUTO_DOWNLOAD}") | ||
| endif() | ||
| message(STATUS " BUILD_FIO: ${BUILD_FIO}") | ||
| message(STATUS " ENABLE_FUSE: ${ENABLE_FUSE}") | ||
| message(STATUS " ENABLE_TESTS: ${ENABLE_TESTS}") | ||
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,35 +1,72 @@ | ||
| ## Here's my code: | ||
| ### Compilation and Build | ||
| The compilation depends on SPDK, DPDK, and FIO, with the versions spdk-25.05, dpdk-22.11, and fio-3.39 used respectively. | ||
| The compilation depends on SPDK (as git submodule in third_party/spdk), DPDK, and optionally FIO for plugin support, with the versions spdk-25.05, dpdk-22.11, and fio-3.39 used respectively. | ||
|
|
||
| The spdk.patch must be applied during SPDK compilation, and C++17 compiler support is required. | ||
|
|
||
| Assuming all projects are located in /chenxu14/workspace | ||
|
|
||
| export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/chenxu14/workspace/spdk/build/lib:/chenxu14/workspace/spdk/dpdk/build/lib | ||
| make | ||
| #### Initialize SPDK Submodule | ||
| First, initialize the SPDK submodule: | ||
| ```bash | ||
| git submodule update --init | ||
| ``` | ||
|
|
||
| #### Using CMake (Recommended) | ||
| ```bash | ||
| # Basic build (automatically compiles SPDK and builds without FIO plugin) | ||
| ./compile.sh | ||
|
|
||
| # Build with FIO plugin support (automatically downloads and compiles FIO) | ||
| ./compile.sh --enable-fio-plugin | ||
|
|
||
| # Build without automatically compiling SPDK (assuming SPDK is already built) | ||
| ./compile.sh --disable-spdk-build | ||
|
|
||
| # Build with custom FIO version | ||
| ./compile.sh --enable-fio-plugin --fio-version fio-3.39 | ||
|
|
||
| # Manual CMake configuration | ||
| mkdir build && cd build | ||
| cmake .. -DENABLE_FIO_PLUGIN=ON -DBUILD_SPDK=ON -DBUILD_FIO=ON | ||
| make -j$(nproc) | ||
| ``` | ||
|
|
||
| #### Environment Setup | ||
| ```bash | ||
| export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/third_party/spdk/build/lib:$(pwd)/third_party/spdk/dpdk/build/lib | ||
| ``` | ||
|
|
||
| ### Benchmark | ||
| MDTEST Bench | ||
|
|
||
| ./bench/mdtest/fs_bench -c /chenxu14/workspace/FastFS/bench/bdev.json -b Malloc0 | ||
| ./build/bin/fs_bench -c /path/to/FastFS/bench/bdev.json -b Malloc0 | ||
|
|
||
| FIO Bench | ||
|
|
||
| fio /chenxu14/workspace/FastFS/bench/fio/fastfs.fio | ||
| fio /path/to/FastFS/bench/fio/fastfs.fio | ||
|
|
||
| ### Maintenance Tools | ||
| Format the filesystem | ||
|
|
||
| ./tools/fastfs_tools -c /chenxu14/workspace/FastFS/bench/bdev_aio.json -b aio0 -f | ||
| ./build/bin/fastfs_tools -c /path/to/FastFS/bench/bdev_aio.json -b aio0 -f | ||
|
|
||
| Dump metadata | ||
|
|
||
| ./tools/fastfs_tools -c /chenxu14/workspace/FastFS/bench/bdev_aio.json -b aio0 -D | ||
| ./build/bin/fastfs_tools -c /path/to/FastFS/bench/bdev_aio.json -b aio0 -D | ||
|
|
||
| Checkpoint operation | ||
|
|
||
| ./tools/fastfs_tools -c /chenxu14/workspace/FastFS/bench/bdev_aio.json -b aio0 -C | ||
| ./build/bin/fastfs_tools -c /path/to/FastFS/bench/bdev_aio.json -b aio0 -C | ||
|
|
||
| Mount FUSE | ||
|
|
||
| ./fuse/fastfs_fuse -c /chenxu14/workspace/FastFS/bench/bdev_aio.json -b aio0 -m /mnt/fastfs | ||
| ./build/bin/fastfs_fuse -c /path/to/FastFS/bench/bdev_aio.json -b aio0 -m /mnt/fastfs | ||
|
|
||
| ### CMake Build Options | ||
| - `-DBUILD_SPDK=ON/OFF`: Automatically build SPDK submodule (default: ON) | ||
| - `-DENABLE_FIO_PLUGIN=ON/OFF`: Enable FIO plugin support (default: OFF) | ||
| - `-DBUILD_FIO=ON/OFF`: Automatically build FIO when plugin enabled (default: ON) | ||
| - `-DFIO_VERSION=version`: FIO version to download (default: fio-3.39) | ||
| - `-DENABLE_FUSE=ON/OFF`: Enable FUSE support (default: ON) | ||
| - `-DENABLE_TESTS=ON/OFF`: Enable unit tests (default: ON) |
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,6 @@ | ||
| # Add benchmark subdirectories | ||
| add_subdirectory(mdtest) | ||
|
|
||
| if(ENABLE_FIO) | ||
| add_subdirectory(fio) | ||
| endif() |
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
| # FIO plugin support is optional | ||
| set(TARGET_NAME fastfs_fio) | ||
|
|
||
| set(SOURCES ${TARGET_NAME}.cpp) | ||
|
|
||
| add_library(${TARGET_NAME} SHARED ${SOURCES}) | ||
|
|
||
| target_include_directories(${TARGET_NAME} | ||
| PRIVATE | ||
| ${CMAKE_SOURCE_DIR} | ||
| ${FIO_ROOT_DIR} | ||
| ${SPDK_ROOT_DIR}/include | ||
| ${SPDK_ROOT_DIR}/build/include | ||
| ${SPDK_ROOT_DIR}/dpdk/build/include | ||
| ) | ||
|
|
||
| target_link_libraries(${TARGET_NAME} | ||
| PRIVATE | ||
| fastfs | ||
| ${SPDK_ROOT_DIR}/build/lib/libspdk_event.a | ||
| ${SPDK_ROOT_DIR}/build/lib/libspdk_event_bdev.a | ||
| Threads::Threads | ||
| ) | ||
|
|
||
| if(DEFINED SPDK_DEPENDENCY AND SPDK_DEPENDENCY) | ||
| add_dependencies(${TARGET_NAME} ${SPDK_DEPENDENCY}) | ||
| endif() | ||
| if(DEFINED FIO_DEPENDENCY AND FIO_DEPENDENCY) | ||
| add_dependencies(${TARGET_NAME} ${FIO_DEPENDENCY}) | ||
| endif() | ||
|
|
||
| target_compile_options(${TARGET_NAME} PRIVATE | ||
| -fpermissive | ||
| -O3 | ||
| -rdynamic | ||
| ) | ||
|
|
||
| set_target_properties(${TARGET_NAME} PROPERTIES | ||
| PREFIX "" | ||
| SUFFIX ".so" | ||
| INSTALL_RPATH "${CMAKE_SOURCE_DIR}/core:${SPDK_ROOT_DIR}/dpdk/build/lib:${SPDK_ROOT_DIR}/build/lib" | ||
| BUILD_RPATH "${CMAKE_BINARY_DIR}/lib:${SPDK_ROOT_DIR}/dpdk/build/lib:${SPDK_ROOT_DIR}/build/lib" | ||
| ) | ||
|
|
||
| install(TARGETS ${TARGET_NAME} DESTINATION lib64/fio) |
This file was deleted.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
声明FIO_ROOT_DIR变量,如果编译阶段用户手动声明了变量值,采用路径对应的FIO版本,否则通过FetchContent下载