Skip to content

feat: Make C++ exceptions and RTTI configurable#9913

Merged
pixelflinger merged 1 commit into
mainfrom
ma/exceptions-on
Apr 23, 2026
Merged

feat: Make C++ exceptions and RTTI configurable#9913
pixelflinger merged 1 commit into
mainfrom
ma/exceptions-on

Conversation

@pixelflinger
Copy link
Copy Markdown
Collaborator

Introduced the FILAMENT_ENABLE_EXCEPTIONS CMake option (default ON) to control both C++ exceptions and RTTI globally. This replaces previous hardcoded, platform-specific overrides and allows users to opt-out to save binary size.

Added a -E flag to build.sh to easily disable exceptions and RTTI during build configuration.

Removed hardcoded -fno-exceptions and -fno-rtti from android/build.gradle to allow CMake to control these flags uniformly.

Documented in CMakeLists.txt and BUILDING.md that the JNI library (Android/Java build) requires exceptions to be enabled. Users of Filament as a pure native library on Android can disable them to save space.

Maintained hardcoded -fno-rtti for WebGL and Cygwin due to specific platform constraints (e.g., emscripten::val usage).

@pixelflinger pixelflinger added the internal Issue/PR does not affect clients label Apr 17, 2026
@pixelflinger
Copy link
Copy Markdown
Collaborator Author

pixelflinger commented Apr 18, 2026

The extra 290KB is due to the unwind tables (verified with zbloat).

@pixelflinger pixelflinger force-pushed the ma/exceptions-on branch 3 times, most recently from b5a3070 to 23fd486 Compare April 21, 2026 08:15
Comment thread CMakeLists.txt
# Turn off exceptions on iOS debug as well. This fixes an availability error we see when using
# std::visit, which is not supported on iOS 11.0 when exceptions are enabled.
if (IOS)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-exceptions")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where's this part that disables exception for ios?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, now you have to do it manually. That's why the default for iOS is off.

I did this because someone might want to compile with exceptions for iOS, and it works as long as you're not using iOS 11. In fact it worked locally for me, but failed only in CI.

So on iOS it's off by default. But if someone wants exceptions they can turn them on at compile time. If we updated our lowest iOS version on the CI, I could have it on by default.

Comment thread CMakeLists.txt Outdated
endif()
if (ANDROID OR WEBGL)
# On Android and WebGL RELEASE builds, we omit unwind info to save space.
# Omitting unwind info prevents the generation of readable stack traces in crash reports on iOS.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment seems unreleated

@poweifeng
Copy link
Copy Markdown
Contributor

btw the sizeguard failure can be bypassed by adding this

SIZEGUARD_BYPASS

in the commit message (not the PR message)

Introduced the FILAMENT_ENABLE_EXCEPTIONS (default ON) and
FILAMENT_ENABLE_RTTI (default OFF) CMake options to control these
features globally. This replaces previous hardcoded, platform-specific
overrides.

Added a -E flag to build.sh to easily disable exceptions during
build configuration.

Removed hardcoded -fno-exceptions and -fno-rtti from
android/build.gradle to allow CMake to control these flags, but kept
-fno-rtti enabled by default for the Java/Android build as requested.

Documented in CMakeLists.txt and BUILDING.md that the JNI library
(Android/Java build) requires exceptions to be enabled.

Enabled RTTI specifically for the assimp target in
third_party/libassimp/tnt/CMakeLists.txt to fix compilation errors
caused by its use of dynamic_cast.

SIZEGUARD_BYPASS
@pixelflinger pixelflinger merged commit f9e56a1 into main Apr 23, 2026
18 checks passed
@pixelflinger pixelflinger deleted the ma/exceptions-on branch April 23, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Issue/PR does not affect clients

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants