diff --git a/.github/actions/windows-build-steps/action.yml b/.github/actions/windows-build-steps/action.yml index 0986099ce9..699d4aa0e5 100644 --- a/.github/actions/windows-build-steps/action.yml +++ b/.github/actions/windows-build-steps/action.yml @@ -4,6 +4,16 @@ runs: steps: - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v1.3.1 + - name: Cache ccache directory + id: ccache-cache + uses: actions/cache@v4 + with: + path: C:\a\rocksdb\rocksdb\.ccache + key: rocksdb-build-${{ runner.os }}-${{ runner.arch }}-ccache-${{ hashFiles('CMakeLists.txt', 'cmake/**/*.cmake') }}-v1 + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + max-size: "10GB" - name: Custom steps env: THIRDPARTY_HOME: ${{ github.workspace }}/thirdparty @@ -38,11 +48,12 @@ runs: $env:Path = $env:JAVA_HOME + ";" + $env:Path mkdir build cd build - & cmake -G "$Env:CMAKE_GENERATOR" -DCMAKE_BUILD_TYPE=Debug -DOPTDBG=1 -DPORTABLE="$Env:CMAKE_PORTABLE" -DSNAPPY=1 -DXPRESS=1 -DJNI=1 .. + & cmake -G "$Env:CMAKE_GENERATOR" -DCMAKE_BUILD_TYPE=Debug -DWIN_CI=1 -DPORTABLE="$Env:CMAKE_PORTABLE" -DSNAPPY=1 -DXPRESS=1 -DJNI=1 .. if(!$?) { Exit $LASTEXITCODE } cd .. echo "Building with VS version: $Env:CMAKE_GENERATOR" - msbuild build/rocksdb.sln -maxCpuCount -property:Configuration=Debug -property:Platform=x64 + # use more parallel processes than the number of processes available, as most of the compile command would be cache hit + msbuild build/rocksdb.sln /m:32 /p:LinkIncremental=false -property:Configuration=Debug -property:Platform=x64 if(!$?) { Exit $LASTEXITCODE } echo ========================= Test RocksDB ========================= build_tools\run_ci_db_test.ps1 -SuiteRun arena_test,db_basic_test,db_test,db_test2,db_merge_operand_test,bloom_test,c_test,coding_test,crc32c_test,dynamic_bloom_test,env_basic_test,env_test,hash_test,random_test -Concurrency 16 @@ -52,3 +63,7 @@ runs: & ctest -C Debug -j 16 if(!$?) { Exit $LASTEXITCODE } shell: pwsh + - name: Show ccache stats + shell: pwsh + run: | + ccache --show-stats -v diff --git a/CMakeLists.txt b/CMakeLists.txt index 44c5644815..e0bbbc4c5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,9 +203,16 @@ if(WIN32 AND MSVC) endif() endif() +option(WIN_CI "Accelerate build speed and reduce build artifect size for github CI with MSVC" OFF) + if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W4 /wd4127 /wd4996 /wd4100 /wd4324") + if(WIN_CI) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /nologo /EHsc /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /W4 /wd4127 /wd4996 /wd4100 /wd4324 /wd4702") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W4 /wd4127 /wd4996 /wd4100 /wd4324") + endif() else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall -pthread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-strict-aliasing -Wno-invalid-offsetof") @@ -450,24 +457,33 @@ else() endif() endif() -# Used to run CI build and tests so we can run faster +# Used to run optimized debug build and tests so we can run faster option(OPTDBG "Build optimized debug build with MSVC" OFF) option(WITH_RUNTIME_DEBUG "build with debug version of runtime library" ON) if(MSVC) - if(OPTDBG) + if (WIN_CI) message(STATUS "Debug optimization is enabled") set(CMAKE_CXX_FLAGS_DEBUG "/Oxt") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG:FASTLINK") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG:FASTLINK") else() - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /RTC1") - - # Minimal Build is deprecated after MSVC 2015 - if( MSVC_VERSION GREATER 1900 ) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Gm-") + if(OPTDBG) + message(STATUS "Debug optimization is enabled") + set(CMAKE_CXX_FLAGS_DEBUG "/Oxt") else() - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Gm") - endif() + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /RTC1") + # Minimal Build is deprecated after MSVC 2015 + if( MSVC_VERSION GREATER 1900 ) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Gm-") + else() + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Gm") + endif() + endif() + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG") endif() + if(WITH_RUNTIME_DEBUG) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /${RUNTIME_LIBRARY}d") else() @@ -475,8 +491,6 @@ if(MSVC) endif() set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oxt /Zp8 /Gm- /Gy /${RUNTIME_LIBRARY}") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG") endif() if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000000..5862fb2c2f --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,9 @@ + + + + ccache_msvc_compiler.bat + $(MSBuildThisFileDirectory) + true + true + + diff --git a/ccache_msvc_compiler.bat b/ccache_msvc_compiler.bat new file mode 100644 index 0000000000..9501ec592b --- /dev/null +++ b/ccache_msvc_compiler.bat @@ -0,0 +1 @@ +ccache.exe cl.exe %*