Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ def get_option_link_args(self, target: 'BuildTarget', env: 'Environment', subpro
return libs
return []

def is_libcpp_enable_assertions_deprecated(self) -> bool:
return version_compare(self.version, ">=18")
Copy link
Contributor

Choose a reason for hiding this comment

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

This checks clang version and not libc++ version, right? They might mismatch so this check is technically incorrect, especially on systems with more than one version of clang installed.

(This is the previous behavior so it's probably fine to keep it here, just noting)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I noticed that too. In principle, we would want the check to be: "if libc++ >= 18 is used, or Apple's libc++ >=17 is used, use _LIBCPP_HARDENING_MODE instead of _LIBCPP_ENABLE_ASSERTIONS".

Copy link
Member

Choose a reason for hiding this comment

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

That merits a comment, but it's already handled in my pending refactoring of it.


def get_assert_args(self, disable: bool, env: 'Environment') -> T.List[str]:
if disable:
return ['-DNDEBUG']
Expand All @@ -323,7 +326,7 @@ def get_assert_args(self, disable: bool, env: 'Environment') -> T.List[str]:
if self.language_stdlib_provider(env) == 'stdc++':
return ['-D_GLIBCXX_ASSERTIONS=1']
else:
if version_compare(self.version, '>=18'):
if self.is_libcpp_enable_assertions_deprecated():
return ['-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST']
elif version_compare(self.version, '>=15'):
return ['-D_LIBCPP_ENABLE_ASSERTIONS=1']
Expand All @@ -343,7 +346,12 @@ class ArmLtdClangCPPCompiler(ClangCPPCompiler):


class AppleClangCPPCompiler(AppleCompilerMixin, AppleCPPStdsMixin, ClangCPPCompiler):
pass
def is_libcpp_enable_assertions_deprecated(self) -> bool:
# Upstream libc++ deprecated _LIBCPP_ENABLE_ASSERTIONS
# in favor of _LIBCPP_HARDENING_MODE from version 18 onwards,
# but Apple Clang 17's libc++ has back-ported that change.
# See: https://github.com/mesonbuild/meson/issues/14440
return version_compare(self.version, ">=17")


class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler):
Expand Down
Loading