/daily-scripts-4-us

Just share some daily scripts which maybe helpful:)

Primary LanguageShellMIT LicenseMIT

hope this may help someone

I write many little script which inspire my life from 13 years, hope this may help others.

some of them learn from other place, I will add reference at the beginning if I remmember.

Speed you windows C++ build by ccache like tools

1. Install ccache to c:\ccache

https://ccache.dev/download.html

2. Three way to make ccache work on windows

- [The first way] Work for Visual Studio project

Tips: You may need call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" like stuff

1. Step1:

Copy ccache.exe to cl.exe, masq as cl.exe and will forward work to real cl.exe,

cd c:\ccache\
copy c:\ccache\ccache.exe cl.exe

2. Step2:

Put Directory.Build.props in any upper dir

3. Step3:

Put Directory.Build.targets in any upper dir

- [The second way] Work for ninja-build like tools

Tips: You may need call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" like stuff

1. Create a real wapper with this content,

ccache_cl_wrapper.bat

Tips: put the file with your ccache.exe

@echo off
%~dp0\ccache.exe cl.exe %*

2. run some tools which work with CC&CXX Environment Variable

set CC=c:\ccache\ccache_cl_wrapper.bat
set CXX=c:\ccache\cmake -G Ninja -S your_src_dir -B your_build_dir

For work with vcpkg

set VCPKG_KEEP_ENV_VARS=CC;CXX

Ref: https://learn.microsoft.com/en-us/vcpkg/users/config-environment#vcpkg_keep_env_vars

- [The third way] Work with CMake by CMAKE_C_COMPILER_LAUNCHER and CMAKE_CXX_COMPILER_LAUNCHER

cmake -G Ninja -DCMAKE_C_COMPILER_LAUNCHER="c:\ccache\ccache.exe" -DCMAKE_CXX_COMPILER_LAUNCHER="c:\ccache\ccache.exe" -S your_src_dir -B your_build_dir

For work with vcpkg

set CMAKE_C_COMPILER_LAUNCHER="c:\ccache\ccache.exe"
set CMAKE_CXX_COMPILER_LAUNCHER="c:\ccache\ccache.exe" 
set VCPKG_KEEP_ENV_VARS=CMAKE_C_COMPILER_LAUNCHER;CMAKE_CXX_COMPILER_LAUNCHER

Ref: https://learn.microsoft.com/en-us/vcpkg/users/config-environment#vcpkg_keep_env_vars

3. The hard part

some time, you may mix these way together, which does not work most of the time, windows is not friendly for build cache, as Visual Studio is a one in all solution?!

4. How to debug ccache works or not

By your cache info

c:\ccache\ccache -s
c:\ccache\ccache --print-stats

5. Have a lot of fun