Skip to content

Conversation

@mychaow
Copy link

@mychaow mychaow commented Oct 10, 2025

sh compile.sh执行就行

CMakeLists.txt Outdated
cmake_minimum_required(VERSION 3.16)
project(FastFS VERSION 1.0 LANGUAGES CXX C)

# 设置 C++ 标准
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中文注释都去掉吧,部分IDE对中文编码支持不太友好

CMakeLists.txt Outdated
set(SCRIPTS_DIR ${CMAKE_SOURCE_DIR}/scripts)

# SPDK 作为 submodule 的路径 (现在在 third_party/spdk)
set(SPDK_SUBMODULE_DIR ${CMAKE_SOURCE_DIR}/third_party/spdk)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量可以改成SPDK_ROOT_DIR,如果编译阶段用户手动声明了变量值,采用路径对应的spdk版本,否则从git仓库下载编译


# 编译选项
option(ENABLE_FIO_PLUGIN "Enable FIO plugin support" ON)
set(FIO_VERSION "fio-3.39" CACHE STRING "FIO version to download")
Copy link
Owner

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下载

CMakeLists.txt Outdated
set(DEPS_DIR ${CMAKE_SOURCE_DIR}/deps)

# 编译选项
option(ENABLE_FIO_PLUGIN "Enable FIO plugin support" ON)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENABLE_FIO

CMakeLists.txt Outdated
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -O2")

# 检查 SPDK submodule 是否存在
if(NOT EXISTS ${SPDK_SUBMODULE_DIR}/mk/spdk.common.mk)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPDK的编译需要绑定一个具体的Release版本,master分支不稳定,可以向FIO那样通过FetchContent获取
if(NOT SPDK_ROOT_DIR)
message(STATUS "Fetching SPDK...")
include(FetchContent)
FetchContent_Declare(
spdk
GIT_REPOSITORY https://github.com/spdk/spdk.git
GIT_TAG ${SPDK_VERSION}
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR ${DEPS_DIR}/spdk-${SPDK_VERSION}
)
FetchContent_MakeAvailable(spdk)

set(SPDK_ROOT_DIR ${DEPS_DIR}/spdk-${SPDK_VERSION})
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"
)

endif()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git submodule是锁定了一个发行版本的commit,如果代码不修改的情况下,是锁定这个版本了。

@@ -1,5 +1,5 @@
diff --git a/include/spdk/bit_pool.h b/include/spdk/bit_pool.h
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个补丁文件应该不用调整

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调整一下操作系统相关的东西,我们那个编译镜像是阿里os的,不识别,我改了下可以识别


# 编译 SPDK
echo "编译 SPDK..."
make -j16
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

并发度改成2

git submodule update --init
./scripts/pkgdep.sh
echo "配置 SPDK..."
./configure --disable-tests --disable-unit-tests --disable-apps --disable-examples
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加--with-shared选项

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前是静态链接的,默认也不编译动态库,是不是先就检查静态库就行了

# 配置 SPDK
cd "$SPDK_DIR"
git submodule update --init
./scripts/pkgdep.sh
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个注释掉吧,部分云主机检测会失败

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不这样没法执行编译,spdk官方编译也是执行这个脚本呀,https://github.com/spdk/spdk

cd "$SPDK_DIR"

# 检查补丁是否已经应用
if git apply --check "../../$PATCH_FILE" 2>/dev/null; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PATCH_FILE是绝对路径?
git apply --check $PATCH_FILE

@mychaow mychaow requested a review from chenxu14 October 21, 2025 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants