ONNX link error when building from source (no CUDA)

I am trying to build PyTorch from the source code and getting a linking error. I followed the official instructions: I use conda environment, do not use CUDA, tried both MS Studio 2019 and ninja (clean builds).

My setup is like this:

conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses
conda install -c conda-forge libuv=1.39

git clone --recursive https://github.com/pytorch/pytorch
cd pytorch

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
set USE_CUDA=0
python setup.py install

I am getting linking errors for torch_python.lib (here just one missing reference):

   Creating library lib\torch_python.lib and object lib\torch_python.exp
shape_type_inference.cpp.obj : error LNK2019: unresolved external symbol "private: static class onnx_torch::GraphProto * __cdecl google::protobuf::Arena::CreateMaybeMessage<class onnx_torch::GraphProto>(class google::protobuf::Arena *)" (??$CreateMaybeMessage@VGraphProto@onnx_torch@@$$V@Arena@protobuf@google@@CAPEAVGraphProto@onnx_torch@@PEAV012@@Z) referenced in function "protected: static class onnx_torch::GraphProto * __cdecl google::protobuf::MessageLite::CreateMaybeMessage<class onnx_torch::GraphProto>(class google::protobuf::Arena *)" (??$CreateMaybeMessage@VGraphProto@onnx_torch@@@MessageLite@protobuf@google@@KAPEAVGraphProto@onnx_torch@@PEAVArena@12@@Z)

I was checking the project and as I understood some libraries are compiled as dynamic and some as static. ONNX is compiled as static. torch_python.lib doesn’t reference ONNX directly. When I tried to link it manually, then I got name collisions with protobuf library.

Anyone knows the fix?