Get RNTester to compile and run

Summary:
This diff includes a few changes:
1. Move the headers inside `jsiexecutor` into `jsiexecutor/jsireact`. As far as I'm aware, the Android ndk build system isn't flexible enough to support header namespaces, so we can't just expose the headers inside the `jsiexecutor` directory under the `jsireact` namespace. Therefore, I moved the headers to `jsiexecutor/jsireact`, and added `jsiexecutor` to the header search path.  This was the easiest way to simulate `jsireact` namespace.
2. Setup the Android.mk files to get RNTester compiling and running.
3. Introduce a `jscexecutor` module to make `JSCExecutor.java` execute without throwing.

**Note:** Moving the header files inside `jsiexecutor` probably breaks the iOS builds and internal builds. I'll fix those in subsequent diffs on this stack.

Reviewed By: shergin

Differential Revision: D9995429

fbshipit-source-id: 418a4ee91f585842c5e317af2f300227a51e9ba8
This commit is contained in:
Marc Horowitz
2018-10-18 00:47:06 -07:00
committed by Facebook Github Bot
parent e8cbc4f893
commit 6370b86c1f
8 changed files with 113 additions and 62 deletions

View File

@@ -129,7 +129,7 @@ task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy)
task downloadJSCHeaders(type: Download) {
// in sync with webkit SVN revision 174650
def jscAPIBaseURL = 'https://raw.githubusercontent.com/WebKit/webkit/38b15a3ba3c1b0798f2036f7cea36ffdc096202e/Source/JavaScriptCore/API/'
def jscHeaderFiles = ['JavaScript.h', 'JSBase.h', 'JSContextRef.h', 'JSObjectRef.h', 'JSRetainPtr.h', 'JSStringRef.h', 'JSValueRef.h', 'WebKitAvailability.h']
def jscHeaderFiles = ['JavaScript.h', 'JSBase.h', 'JSContextRef.h', 'JSObjectRef.h', 'JSStringRef.h', 'JSValueRef.h', 'WebKitAvailability.h']
def output = new File(downloadsDir, 'jsc')
output.mkdirs()
src(jscHeaderFiles.collect { headerName -> "$jscAPIBaseURL$headerName" })
@@ -221,6 +221,7 @@ task buildReactNdkLib(dependsOn: [prepareJSC, prepareBoost, prepareDoubleConvers
"NDK_LIBS_OUT=$buildDir/react-ndk/all",
"THIRD_PARTY_NDK_DIR=$buildDir/third-party-ndk",
"REACT_COMMON_DIR=$projectDir/../ReactCommon",
"REACT_SRC_DIR=$projectDir/src/main/java/com/facebook/react",
'-C', file('src/main/jni/react/jni').absolutePath,
'--jobs', project.hasProperty("jobs") ? project.property("jobs") : Runtime.runtime.availableProcessors()
}

View File

@@ -0,0 +1,16 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jscexecutor
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_CFLAGS += -fvisibility=hidden -fexceptions -frtti
LOCAL_STATIC_LIBRARIES := libjsi libjsireact
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni
include $(BUILD_SHARED_LIBRARY)

View File

@@ -5,7 +5,19 @@ APP_PLATFORM := android-16
APP_MK_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
NDK_MODULE_PATH := $(APP_MK_DIR)$(HOST_DIRSEP)$(THIRD_PARTY_NDK_DIR)$(HOST_DIRSEP)$(REACT_COMMON_DIR)$(HOST_DIRSEP)$(APP_MK_DIR)first-party
# What is NDK_MODULE_PATH?
# This is comparable to the PATH environment variable in Linux. The purpose
# of NDK_MODULE_PATH is to provide a list of directories that contain modules
# we want ndk-build to compile.
#
# What is HOST_DIRSEP?
# In PATH, the directories are separated by a ':'.
# In NDK_MODULE_PATH, the directories are separated by $(HOST_DIRSEP).
#
# Where are APP_MK_DIR, THIRD_PARTY_NDK_DIR, etc. defined?
# The directories inside NDK_MODULE_PATH (ex: APP_MK_DIR, THIRD_PARTY_NDK_DIR,
# etc.) are defined inside build.gradle.
NDK_MODULE_PATH := $(APP_MK_DIR)$(HOST_DIRSEP)$(THIRD_PARTY_NDK_DIR)$(HOST_DIRSEP)$(REACT_COMMON_DIR)$(HOST_DIRSEP)$(APP_MK_DIR)first-party$(HOST_DIRSEP)$(REACT_SRC_DIR)
APP_STL := gnustl_shared

View File

@@ -2,47 +2,61 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := reactnativejni
LOCAL_SRC_FILES := \
AndroidJSCFactory.cpp \
CatalystInstanceImpl.cpp \
CxxModuleWrapper.cpp \
JavaModuleWrapper.cpp \
JReactMarker.cpp \
JMessageQueueThread.cpp \
JSCPerfLogging.cpp \
JSLoader.cpp \
JSLogging.cpp \
JniJSModulesUnbundle.cpp \
MethodInvoker.cpp \
ModuleRegistryBuilder.cpp \
NativeArray.cpp \
NativeCommon.cpp \
NativeDeltaClient.cpp \
NativeMap.cpp \
OnLoad.cpp \
ProxyExecutor.cpp \
ReadableNativeArray.cpp \
ReadableNativeMap.cpp \
WritableNativeArray.cpp \
WritableNativeMap.cpp \
# Include . in the header search path for all source files in this module.
LOCAL_C_INCLUDES := $(LOCAL_PATH)
# Include ./../../ in the header search path for modules that depend on
# reactnativejni. This will allow external modules to require this module's
# headers using #include <react/jni/<header>.h>, assuming:
# . == jni
# ./../ == react
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../..
LOCAL_CFLAGS += -fvisibility=hidden -fexceptions -frtti
LOCAL_CFLAGS += -fexceptions -frtti
LOCAL_LDLIBS += -landroid
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libjsc libglog_init libyoga libprivatedata
# The dynamic libraries (.so files) that this module depends on.
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libjsc libglog_init libyoga
# The static libraries (.a files) that this module depends on.
LOCAL_STATIC_LIBRARIES := libreactnative
# Name of this module.
#
# Other modules can depend on this one by adding libreactnativejni to their
# LOCAL_SHARED_LIBRARIES variable.
LOCAL_MODULE := reactnativejni
# Compile all local c++ files.
LOCAL_SRC_FILES := $(wildcard *.cpp)
# Build the files in this directory as a shared library
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cxxreact)
$(call import-module,privatedata)
$(call import-module,fb)
$(call import-module,fbgloginit)
# Compile the c++ dependencies required for ReactAndroid
#
# How does the import-module function work?
# For each $(call import-module,<module-dir>), you search the directories in
# NDK_MODULE_PATH. (This variable is defined in Application.mk). If you find a
# <module-dir>/Android.mk you in a directory <dir>, you run:
# include <dir>/<module-dir>/Android.mk
#
# What does it mean to include an Android.mk file?
# Whenever you encounter an include <dir>/<module-dir>/Android.mk, you
# tell andorid-ndk to compile the module in <dir>/<module-dir> according
# to the specification inside <dir>/<module-dir>/Android.mk.
$(call import-module,folly)
$(call import-module,fb)
$(call import-module,jsc)
$(call import-module,fbgloginit)
$(call import-module,yogajni)
$(call import-module,cxxreact)
$(call import-module,jsi)
$(call import-module,jsiexecutor)
# TODO(ramanpreet):
# Why doesn't this import-module call generate a jscexecutor.so file?
# $(call import-module,jscexecutor)
include $(REACT_SRC_DIR)/jscexecutor/Android.mk