Bug 1962300 - Provide support for unavailable symbols as weak symbols r=m_kato,gfx-reviewers,firefox-build-system-reviewers,glandium,necko-reviewers,geckoview-reviewers,cubeb-reviewers,valentin,padenot,jnicol

Compiler support make it possible to detect missing checks at compile
time, so it's relatively safe, as described in https://developer.android.com/ndk/guides/using-newer-apis

It's now applied globally on android.

Deactivate the associate compiler warning on cubeb as it otherwise
throws warning for type computations.

Differential Revision: https://phabricator.services.mozilla.com/D246803
This commit is contained in:
serge-sans-paille
2025-05-15 09:32:02 +00:00
committed by sguelton@mozilla.com
parent e828ae5ced
commit 5d938d8488
3 changed files with 27 additions and 4 deletions

View File

@@ -274,11 +274,29 @@ def extra_toolchain_flags(android_sysroot, toolchain_dir):
@depends(extra_toolchain_flags) @depends(extra_toolchain_flags)
def android_flags(extra_toolchain_flags): def android_flags(extra_toolchain_flags):
wead_symbols_defines = [
"-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
]
weak_symbols_flags = wead_symbols_defines + [
"-Werror=unguarded-availability",
]
return namespace( return namespace(
cflags=extra_toolchain_flags + ["-fno-short-enums"], cflags=extra_toolchain_flags
cxxflags=extra_toolchain_flags + ["-fno-short-enums"], + [
"-fno-short-enums",
]
+ weak_symbols_flags,
cxxflags=extra_toolchain_flags
+ [
"-fno-short-enums",
]
+ weak_symbols_flags,
ldflags=extra_toolchain_flags, ldflags=extra_toolchain_flags,
asflags=extra_toolchain_flags + ["-DANDROID"], asflags=extra_toolchain_flags
+ [
"-DANDROID",
]
+ wead_symbols_defines,
) )

View File

@@ -95,7 +95,7 @@ if CONFIG['MOZ_AAUDIO'] or CONFIG['MOZ_OPENSL']:
if CONFIG['MOZ_AAUDIO']: if CONFIG['MOZ_AAUDIO']:
SOURCES += ['cubeb_aaudio.cpp'] SOURCES += ['cubeb_aaudio.cpp']
SOURCES['cubeb_aaudio.cpp'].flags += ['-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__'] SOURCES['cubeb_aaudio.cpp'].flags += ['-Wno-unguarded-availability']
DEFINES['USE_AAUDIO'] = True DEFINES['USE_AAUDIO'] = True
if CONFIG['MOZ_OPENSL']: if CONFIG['MOZ_OPENSL']:

View File

@@ -29,6 +29,11 @@ if CONFIG["OS_TARGET"] == "Darwin":
# when building with MACOSX_DEPLOYMENT_TARGET < 10.15 with >= 10.15 SDK. # when building with MACOSX_DEPLOYMENT_TARGET < 10.15 with >= 10.15 SDK.
# We have our own definition of the function, so it doesn't matter what the SDK says. # We have our own definition of the function, so it doesn't matter what the SDK says.
SOURCES["Replay.cpp"].flags += ["-Wno-unguarded-availability-new"] SOURCES["Replay.cpp"].flags += ["-Wno-unguarded-availability-new"]
elif CONFIG["OS_TARGET"] == "Android":
# Work around "warning: 'aligned_alloc' is only available on Android 27 or
# lower. We have our own definition of the function, so it doesn't matter.
SOURCES["Replay.cpp"].flags += ["-Wno-unguarded-availability"]
if CONFIG["MOZ_REPLACE_MALLOC_STATIC"] and (CONFIG["MOZ_DMD"] or CONFIG["MOZ_PHC"]): if CONFIG["MOZ_REPLACE_MALLOC_STATIC"] and (CONFIG["MOZ_DMD"] or CONFIG["MOZ_PHC"]):
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [