Release profile on x64 Windows generated without optimization flags when building under dev Cargo profile
This is with cmake 3.31.4
I observed that if I build llama.cpp from the command line:
mkdir build
cd build
cmake.exe ../ -DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_TESTS=OFF -DLLAMA_BUILD_SERVER=OFF
cmake.exe --build . -j 32 --config Release
the compiler flags comes out to:
CMAKE_CXX_FLAGS:STRING=/DWIN32 /D_WINDOWS /W3 /GR /EHsc
CMAKE_CXX_FLAGS_RELEASE:STRING=/MD /O2 /Ob2 /DNDEBUG
CMAKE_C_FLAGS:STRING=/DWIN32 /D_WINDOWS /W3
CMAKE_C_FLAGS_RELEASE:STRING=/MD /O2 /Ob2 /DNDEBUG
by contrast, llama-cpp-rs's build script which uses this crate ends up generating:
CMAKE_CXX_FLAGS:STRING= -nologo -MD -Brepro
CMAKE_CXX_FLAGS_RELEASE:STRING= -nologo -MD -Brepro
CMAKE_C_FLAGS:STRING= -nologo -MD -Brepro
CMAKE_C_FLAGS_RELEASE:STRING= -nologo -MD -Brepro
when building the dev Cargo profile which seems wrong - optimizations shouldn't disappear from the Release CMake profile just because we're building under dev. The flags revert to the correct settings when built under release.
Filed upstream ticket to track it in both repos https://github.com/utilityai/llama-cpp-rs/issues/649 but I suspect the fault has to lie with this crate since the build.rs isn't doing anything that would explain a change in this behavior.
I think this is partially the culprit https://github.com/rust-lang/cmake-rs/blob/fd56c5a6b4ecda8815c863eb5b12d7b3f0391197/src/lib.rs#L738-L761 which uses https://github.com/rust-lang/cmake-rs/blob/fd56c5a6b4ecda8815c863eb5b12d7b3f0391197/src/lib.rs#L716-L719
Obviously the optimization flags are being stripped and there's even a warning about it, but unclear why it's only stripped in debug builds as you'd think this would strip it in both. Not sure if https://github.com/rust-lang/cmake-rs/blob/fd56c5a6b4ecda8815c863eb5b12d7b3f0391197/src/lib.rs#L518-L533 is at all related either as the optimization level is initialized to off.