valhalla icon indicating copy to clipboard operation
valhalla copied to clipboard

Add CMake option to build Valhalla with `-fno-rtti`

Open SiarheiFedartsou opened this issue 3 years ago • 5 comments

Some projects depending on Valhalla have a requirement to be built with -fno-rtti flag(for various reasons, mainly due to binary size). In general there are no any issues with Valhalla and -fno-rtti, but from time to time new changes are introduced in Valhalla which explicitly require RTTI: e.g. those ones which use typeid or dynamic_cast(https://github.com/valhalla/valhalla/pull/3191). The idea is the following:

  1. Introduce CMake option DISABLE_RTTI, which applies -fno-rtti if ON.
  2. Configure CI job which would check if Valhalla can be built with DISABLE_RTTI.

cc @valhalla/core

SiarheiFedartsou avatar Jul 22 '21 12:07 SiarheiFedartsou

@SiarheiFedartsou sorry it didnt occur to me that you guys were disabling rtti. it seems to me that having a cmake flag control it doesnt make sense because even if CI can detect it you'll just have to rewrite your code to work around it. if its a hard requirement downstream we should just avoid it completely and make impossible to opt out of it (though what about our 3rd party dependencies). before we do that i would ask you, how much does it actually save on binary size?

also protobuf is loaded with typeid, at least the version im compiling that comes with my system. iirc you build protobuf from source and disable rtti for it directly?

kevinkreiser avatar Jul 22 '21 16:07 kevinkreiser

@kevinkreiser also I see we actively use boost::property_tree which requires RTTI. There is PR in Boost which fixes this, but it is being stuck for 5 years. Don't we want to get rid of this and use something like usual json or strong-typed structure instead? WDYT? I could take this work probably.

SiarheiFedartsou avatar Nov 11 '21 09:11 SiarheiFedartsou

@kevinkreiser also I see we actively use boost::property_tree which requires RTTI. There is PR in Boost which fixes this, but it is being stuck for 5 years. Don't we want to get rid of this and use something like usual json or strong-typed structure instead? WDYT? I could take this work probably.

if you wonder how do we build Valhalla without RTTI now: we simply use patched version of boost, but want to switch to mainstream

SiarheiFedartsou avatar Nov 11 '21 09:11 SiarheiFedartsou

also protobuf is loaded with typeid, at least the version im compiling that comes with my system. iirc you build protobuf from source and disable rtti for it directly?

Yes, we use GOOGLE_PROTOBUF_NO_RTTI

SiarheiFedartsou avatar Nov 11 '21 09:11 SiarheiFedartsou

Yes we would like to stop using ptree and use rapidjson everywhere but it's a decent amount of work which is why we haven't already done it. If you are interested in doing some of it that would be great

kevinkreiser avatar Nov 11 '21 11:11 kevinkreiser