nn: enable NDEBUG, but unset for tests
This CL allows the NDEBUG flag to be set for the core libraries, which
otherwise results in a linking error when using refptr due to the
destructor of RefCountedThreadSafeBase being defined differently based
on the NDEBUG flag. See b/174605330#comment13 for details.
We still require NDEBUG to be unset for tests, so this CL will unset the
define for the test targets, otherwise tests will not build or pass
correctly.
BUG=b:186996014
TEST=FEATURES=test USE=-cros-debug emerge-volteer aosp-frameworks-ml-nn
Change-Id: Icfc69dcd08f96577cc3ca30b0c05df556bfb0550
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/frameworks/ml/+/2870225
Tested-by: Jim Pollock <jmpollock@chromium.org>
Auto-Submit: Jim Pollock <jmpollock@chromium.org>
Commit-Queue: Jim Pollock <jmpollock@chromium.org>
Reviewed-by: Stuart Langley <slangley@chromium.org>
diff --git a/nn/BUILD.gn b/nn/BUILD.gn
index 406d2c3..44fe3d1 100644
--- a/nn/BUILD.gn
+++ b/nn/BUILD.gn
@@ -99,6 +99,26 @@
pkg_deps = [ "libnnapi-support" ]
}
+# Tests cannot be build with the NDEBUG flag set,
+# but we want to allow NDEBUG for the main lib.
+# Specifically, forcing NDEBUG to be always off
+# will cause issues in libchrome:
+# b/174605330#comment13
+# Using pkg_config forces the cflags to be put at
+# the end of the options string, which will allow it
+# to unset the NDEBUG flag setup by the global
+# cros-debug eclass. Just setting this in the
+# cflags of the executable() will put this before
+# the flags set by the ebuild, which will have no
+# effect.
+# See b/186996014 for the history on this issue.
+pkg_config("disable_ndebug") {
+ cflags_cc = [
+ "-UNDEBUG",
+ ]
+ pkg_deps = [ "libnnapi-support" ]
+}
+
static_library("runtime") {
configs += [
":target_defaults",
@@ -316,6 +336,7 @@
"-Wno-pessimizing-move",
]
configs += [
+ ":disable_ndebug",
":target_defaults",
":common_defaults",
"//common-mk:test",
diff --git a/nn/chromeos/tests/BUILD.gn b/nn/chromeos/tests/BUILD.gn
index 1f23097..b7a2e92 100644
--- a/nn/chromeos/tests/BUILD.gn
+++ b/nn/chromeos/tests/BUILD.gn
@@ -188,6 +188,7 @@
executable("cros_nnapi_cts") {
configs += [
+ "//aosp/frameworks/ml/nn:disable_ndebug",
"//aosp/frameworks/ml/nn:target_defaults",
"//common-mk:test",
]