Skip to content

Commit

Permalink
Add support to ndk-build in Application.mk
Browse files Browse the repository at this point in the history
Bug: android/ndk#837
Tests: ./run_tests.py –rebuild –filter weak_symbols_build_support
Change-Id: I08b45b667a7480fc6e68d6edffeecdb14700cde0
  • Loading branch information
ZijunZhaoCCK committed Oct 11, 2022
1 parent 251b613 commit 22d2943
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build/core/default-build-commands.mk
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ GLOBAL_CFLAGS += \

GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=2


ifeq ($(APP_WEAK_API_DEFS), true)
GLOBAL_CFLAGS += -D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__
endif

GLOBAL_LDFLAGS = \
-target $(LLVM_TRIPLE)$(TARGET_PLATFORM_LEVEL) \
-no-canonical-prefixes \
Expand Down
1 change: 1 addition & 0 deletions build/core/definitions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,7 @@ NDK_APP_VARS_OPTIONAL := \
APP_STL \
APP_STRIP_MODE \
APP_THIN_ARCHIVE \
APP_WEAK_API_DEFS \
APP_WRAP_SH \

# NDK_ALL_ABIS is not configured yet.
Expand Down
10 changes: 10 additions & 0 deletions tests/device/weak_symbols_build_support/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := weak_symbols
LOCAL_SRC_FILES := weak_symbols.cpp
LOCAL_STATIC_LIBRARIES := googletest_main
LOCAL_LDLIBS := -landroid
include $(BUILD_EXECUTABLE)

$(call import-module,third_party/googletest)
2 changes: 2 additions & 0 deletions tests/device/weak_symbols_build_support/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_STL := c++_static
APP_WEAK_API_DEFS := true
14 changes: 14 additions & 0 deletions tests/device/weak_symbols_build_support/jni/weak_symbols.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <gtest/gtest.h>
#include <android/trace.h>
#include <android/api-level.h>

TEST(weak_symbols, weak_symbol_enable) {
bool called = false;
if (__builtin_available(android 29, *)) {
// 0 is an arbitrary cookie. The specific value doesn't matter because
// this will never run concurrently.
ATrace_beginAsyncSection("ndk::asyncBeginEndSection", 0);
called = true;
}
ASSERT_EQ(android_get_device_api_level() >= 29, called);
}

0 comments on commit 22d2943

Please sign in to comment.