From 6370b86c1f37278fc02b9282dca6eb1e45bc0e3c Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Thu, 18 Oct 2018 00:47:06 -0700 Subject: [PATCH] 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 --- ReactAndroid/build.gradle | 3 +- .../com/facebook/react/jscexecutor/Android.mk | 16 ++++ ReactAndroid/src/main/jni/Application.mk | 14 +++- .../src/main/jni/react/jni/Android.mk | 78 +++++++++++-------- ReactCommon/cxxreact/Android.mk | 29 +------ ReactCommon/jsi/Android.mk | 15 ++++ ReactCommon/jsiexecutor/Android.mk | 17 ++++ ReactCommon/jsinspector/Android.mk | 3 +- 8 files changed, 113 insertions(+), 62 deletions(-) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/jscexecutor/Android.mk create mode 100644 ReactCommon/jsi/Android.mk create mode 100644 ReactCommon/jsiexecutor/Android.mk diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index f3ca375b1..70a38af77 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -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() } diff --git a/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/Android.mk b/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/Android.mk new file mode 100644 index 000000000..9b7404543 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/Android.mk @@ -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) diff --git a/ReactAndroid/src/main/jni/Application.mk b/ReactAndroid/src/main/jni/Application.mk index 7c15b8852..0e3d85e32 100644 --- a/ReactAndroid/src/main/jni/Application.mk +++ b/ReactAndroid/src/main/jni/Application.mk @@ -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 diff --git a/ReactAndroid/src/main/jni/react/jni/Android.mk b/ReactAndroid/src/main/jni/react/jni/Android.mk index 5fce5384b..d76dd0fc2 100644 --- a/ReactAndroid/src/main/jni/react/jni/Android.mk +++ b/ReactAndroid/src/main/jni/react/jni/Android.mk @@ -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 .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,), you search the directories in +# NDK_MODULE_PATH. (This variable is defined in Application.mk). If you find a +# /Android.mk you in a directory , you run: +# include //Android.mk +# +# What does it mean to include an Android.mk file? +# Whenever you encounter an include //Android.mk, you +# tell andorid-ndk to compile the module in / according +# to the specification inside //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 diff --git a/ReactCommon/cxxreact/Android.mk b/ReactCommon/cxxreact/Android.mk index 3359c5c1d..4a5a04373 100644 --- a/ReactCommon/cxxreact/Android.mk +++ b/ReactCommon/cxxreact/Android.mk @@ -4,28 +4,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := reactnative -LOCAL_SRC_FILES := \ - CxxNativeModule.cpp \ - Instance.cpp \ - JSBigString.cpp \ - JSBundleType.cpp \ - JSCExecutor.cpp \ - JSCLegacyTracing.cpp \ - JSCMemory.cpp \ - JSCNativeModules.cpp \ - JSCPerfStats.cpp \ - JSCSamplingProfiler.cpp \ - JSCTracing.cpp \ - JSCUtils.cpp \ - JSDeltaBundleClient.cpp \ - JSExecutor.cpp \ - JSIndexedRAMBundle.cpp \ - MethodCall.cpp \ - ModuleRegistry.cpp \ - NativeToJsBridge.cpp \ - Platform.cpp \ - RAMBundleRegistry.cpp \ - ReactMarker.cpp \ +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) @@ -35,8 +14,8 @@ LOCAL_CFLAGS := \ LOCAL_CFLAGS += -fexceptions -frtti -LOCAL_STATIC_LIBRARIES := jschelpers -LOCAL_SHARED_LIBRARIES := libfb libfolly_json libjsc libglog +LOCAL_STATIC_LIBRARIES := boost +LOCAL_SHARED_LIBRARIES := jsinspector libfolly_json glog include $(BUILD_STATIC_LIBRARY) @@ -44,6 +23,4 @@ $(call import-module,fb) $(call import-module,folly) $(call import-module,jsc) $(call import-module,glog) -$(call import-module,jschelpers) $(call import-module,jsinspector) -$(call import-module,privatedata) diff --git a/ReactCommon/jsi/Android.mk b/ReactCommon/jsi/Android.mk new file mode 100644 index 000000000..1b27989ff --- /dev/null +++ b/ReactCommon/jsi/Android.mk @@ -0,0 +1,15 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := jsi + +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) + +LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) + +LOCAL_CFLAGS := -fexceptions -frtti -O3 +LOCAL_SHARED_LIBRARIES := libfolly_json libjsc glog + +include $(BUILD_STATIC_LIBRARY) diff --git a/ReactCommon/jsiexecutor/Android.mk b/ReactCommon/jsiexecutor/Android.mk new file mode 100644 index 000000000..8580c9f4b --- /dev/null +++ b/ReactCommon/jsiexecutor/Android.mk @@ -0,0 +1,17 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := jsireact + +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/jsireact/*.cpp) + +LOCAL_C_INCLUDES := $(LOCAL_PATH) +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) + +LOCAL_CFLAGS := -fexceptions -frtti -O3 + +LOCAL_STATIC_LIBRARIES := libjsi reactnative +LOCAL_SHARED_LIBRARIES := libfolly_json glog + +include $(BUILD_STATIC_LIBRARY) diff --git a/ReactCommon/jsinspector/Android.mk b/ReactCommon/jsinspector/Android.mk index d5fe4ef12..2e36c2274 100644 --- a/ReactCommon/jsinspector/Android.mk +++ b/ReactCommon/jsinspector/Android.mk @@ -4,8 +4,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := jsinspector -LOCAL_SRC_FILES := \ - InspectorInterfaces.cpp +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)