-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Hermes support to React Native on Android #25613
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e3ffae4
Add Hermes support to React Native
cpojer cd6b247
Fix hermes path when building from source in ReactAndroid/build.gradle
janicduplessis bea7fdb
Fix hermes header include paths when building from source
janicduplessis a30750b
Lint
cpojer 4a6a537
Add BUCK files.
cpojer e45df9a
Generate correct source map if hermes not enabled (#25700)
HazAT 50bbfca
[Android] Generate source maps outside of assets/ (#25710)
motiz88 ac2624b
Possible fix for the CI issue.
cpojer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/BUCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library", "react_native_dep", "rn_xplat_cxx_library") | ||
|
||
rn_android_library( | ||
name = "instrumentation", | ||
srcs = ["HermesMemoryDumper.java"], | ||
visibility = ["PUBLIC"], | ||
deps = [ | ||
react_native_dep("java/com/facebook/proguard/annotations:annotations"), | ||
], | ||
) | ||
|
||
rn_android_library( | ||
name = "impl", | ||
srcs = ["HermesMemoryDumperImpl.java"], | ||
visibility = ["PUBLIC"], | ||
deps = [ | ||
react_native_dep("java/com/facebook/common/appstate:appstate"), | ||
react_native_dep("java/com/facebook/common/errorreporting/memory:memory"), | ||
react_native_dep("java/com/facebook/common/fileupload:fileupload"), | ||
react_native_dep("java/com/facebook/common/identifiers:identifiers"), | ||
react_native_dep("java/com/facebook/common/stringformat:stringformat"), | ||
react_native_dep("java/com/facebook/common/time:time"), | ||
react_native_dep("java/com/facebook/hermes/annotations:annotations"), | ||
react_native_dep("java/com/facebook/inject:inject"), | ||
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), | ||
":instrumentation", | ||
], | ||
) | ||
|
||
rn_xplat_cxx_library( | ||
name = "jni-interface", | ||
srcs = [], | ||
header_namespace = "hermes/jni/instrumentation", | ||
exported_headers = ["HermesMemoryDumper.h"], | ||
visibility = ["PUBLIC"], | ||
deps = [ | ||
react_native_dep("native/fb:fb"), | ||
], | ||
) |
48 changes: 48 additions & 0 deletions
48
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE | ||
* file in the root directory of this source tree. | ||
*/ | ||
#include <fb/fbjni.h> | ||
#include <string> | ||
|
||
namespace facebook { | ||
namespace jsi { | ||
namespace jni { | ||
|
||
namespace jni = ::facebook::jni; | ||
|
||
class HermesMemoryDumper : public jni::JavaClass<HermesMemoryDumper> { | ||
public: | ||
constexpr static auto kJavaDescriptor = | ||
"Lcom/facebook/hermes/instrumentation/HermesMemoryDumper;"; | ||
|
||
bool shouldSaveSnapshot() { | ||
static auto shouldSaveSnapshotMethod = | ||
javaClassStatic()->getMethod<jboolean()>("shouldSaveSnapshot"); | ||
return shouldSaveSnapshotMethod(self()); | ||
} | ||
|
||
std::string getInternalStorage() { | ||
static auto getInternalStorageMethod = | ||
javaClassStatic()->getMethod<jstring()>("getInternalStorage"); | ||
return getInternalStorageMethod(self())->toStdString(); | ||
} | ||
|
||
std::string getId() { | ||
static auto getInternalStorageMethod = | ||
javaClassStatic()->getMethod<jstring()>("getId"); | ||
return getInternalStorageMethod(self())->toStdString(); | ||
} | ||
|
||
void setMetaData(std::string crashId) { | ||
static auto getIdMethod = | ||
javaClassStatic()->getMethod<void(std::string)>("setMetaData"); | ||
getIdMethod(self(), crashId); | ||
} | ||
}; | ||
|
||
} // namespace jni | ||
} // namespace jsi | ||
} // namespace facebook |
14 changes: 14 additions & 0 deletions
14
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE | ||
* file in the root directory of this source tree. | ||
*/ | ||
package com.facebook.hermes.instrumentation; | ||
|
||
public interface HermesMemoryDumper { | ||
boolean shouldSaveSnapshot(); | ||
String getInternalStorage(); | ||
String getId(); | ||
void setMetaData(String crashId); | ||
} |
40 changes: 40 additions & 0 deletions
40
ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
LOCAL_PATH := $(call my-dir) | ||
|
||
include $(CLEAR_VARS) | ||
REACT_NATIVE := $(LOCAL_PATH)/../../../../../../../.. | ||
|
||
LOCAL_MODULE := hermes-executor-release | ||
|
||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) | ||
|
||
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(REACT_NATIVE)/node_modules/hermesvm/android/include $(REACT_NATIVE)/../hermesvm/android/include | ||
|
||
LOCAL_CPP_FEATURES := exceptions | ||
|
||
LOCAL_STATIC_LIBRARIES := libjsireact libjsi | ||
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes | ||
|
||
include $(BUILD_SHARED_LIBRARY) | ||
|
||
|
||
include $(CLEAR_VARS) | ||
REACT_NATIVE := $(LOCAL_PATH)/../../../../../../../.. | ||
|
||
LOCAL_MODULE := hermes-executor-debug | ||
LOCAL_CFLAGS := -DHERMES_ENABLE_DEBUGGER=1 | ||
|
||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) | ||
|
||
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(REACT_NATIVE)/node_modules/hermesvm/android/include $(REACT_NATIVE)/../hermesvm/android/include | ||
|
||
LOCAL_CPP_FEATURES := exceptions | ||
|
||
LOCAL_STATIC_LIBRARIES := libjsireact libjsi libhermes-inspector | ||
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes | ||
|
||
include $(BUILD_SHARED_LIBRARY) |
124 changes: 124 additions & 0 deletions
124
ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library", "react_native_dep", "react_native_target", "rn_xplat_cxx_library") | ||
|
||
rn_android_library( | ||
name = "reactexecutor", | ||
srcs = [ | ||
"HermesExecutor.java", | ||
"HermesExecutorFactory.java", | ||
], | ||
visibility = [ | ||
"PUBLIC", | ||
], | ||
deps = [ | ||
react_native_dep("java/com/facebook/hermes/instrumentation:instrumentation"), | ||
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), | ||
react_native_dep("third-party/java/jsr-305:jsr-305"), | ||
":jni", | ||
":runtimeconfig", | ||
react_native_target("java/com/facebook/react/bridge:bridge"), | ||
], | ||
) | ||
|
||
rn_android_library( | ||
name = "reactexecutor-hermes-snapshot", | ||
srcs = [ | ||
"HermesSnapshotExecutor.java", | ||
"HermesSnapshotExecutorFactory.java", | ||
], | ||
visibility = [ | ||
"PUBLIC", | ||
], | ||
deps = [ | ||
react_native_dep("java/com/facebook/hermes/instrumentation:instrumentation"), | ||
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), | ||
react_native_dep("third-party/java/jsr-305:jsr-305"), | ||
":jni-hermes-snapshot", | ||
":runtimeconfig", | ||
react_native_target("java/com/facebook/react/bridge:bridge"), | ||
], | ||
) | ||
|
||
rn_android_library( | ||
name = "runtimeconfig", | ||
srcs = [ | ||
"RuntimeConfig.java", | ||
], | ||
visibility = [ | ||
"PUBLIC", | ||
], | ||
deps = [ | ||
react_native_dep("java/com/facebook/hermes/instrumentation:instrumentation"), | ||
react_native_dep("third-party/java/jsr-305:jsr-305"), | ||
], | ||
) | ||
|
||
rn_xplat_cxx_library( | ||
name = "jni-interface", | ||
srcs = [], | ||
header_namespace = "hermes/reactexecutor", | ||
exported_headers = glob(["*.h"]), | ||
visibility = ["PUBLIC"], | ||
deps = [ | ||
"fbsource//xplat/hermes/public:public", | ||
], | ||
) | ||
|
||
rn_xplat_cxx_library( | ||
name = "jni-interface-snapshot", | ||
srcs = [], | ||
header_namespace = "hermes/reactexecutor", | ||
exported_headers = glob(["*.h"]), | ||
visibility = ["PUBLIC"], | ||
deps = [ | ||
"fbsource//xplat/hermes-snapshot/public:public", | ||
], | ||
) | ||
|
||
rn_xplat_cxx_library( | ||
name = "jni", | ||
srcs = ["OnLoad.cpp"], | ||
headers = [], | ||
header_namespace = "", | ||
allow_jni_merging = True, | ||
compiler_flags = ["-fexceptions"], | ||
soname = "libhermes-executor.$(ext)", | ||
visibility = [ | ||
react_native_dep("java/com/facebook/hermes/reactexecutor:reactexecutor"), | ||
], | ||
deps = [ | ||
react_native_dep("java/com/facebook/hermes/crashmanager:crashmanager"), | ||
react_native_dep("java/com/facebook/hermes/instrumentation:jni-interface"), | ||
react_native_dep("java/com/facebook/quicklog/jni:qpljsibindings"), | ||
react_native_dep("native/fb:fb"), | ||
"fbsource//xplat/MobileCoreHealth/fbsofterror:fbsofterror", | ||
"fbsource//xplat/folly:memory", | ||
"fbsource//xplat/hermes/API:HermesAPI", | ||
":jni-interface", | ||
react_native_target("jni/react/jni:jni"), | ||
"fbsource//xplat/ReactNative/react/jsi:HermesExecutorFactory", | ||
], | ||
) | ||
|
||
rn_xplat_cxx_library( | ||
name = "jni-hermes-snapshot", | ||
srcs = ["OnLoadSnapshot.cpp"], | ||
headers = [], | ||
header_namespace = "", | ||
allow_jni_merging = True, | ||
compiler_flags = ["-fexceptions"], | ||
soname = "libhermes-executor-snapshot.$(ext)", | ||
visibility = [ | ||
react_native_dep("java/com/facebook/hermes/reactexecutor:reactexecutor"), | ||
], | ||
deps = [ | ||
react_native_dep("java/com/facebook/hermes/instrumentation:jni-interface"), | ||
react_native_dep("java/com/facebook/quicklog/jni:qpljsibindings"), | ||
react_native_dep("native/fb:fb"), | ||
"fbsource//xplat/MobileCoreHealth/fbsofterror:fbsofterror", | ||
"fbsource//xplat/folly:memory", | ||
"fbsource//xplat/hermes-snapshot/API:HermesAPI", | ||
":jni-interface-snapshot", | ||
react_native_target("jni/react/jni:jni"), | ||
"fbsource//xplat/ReactNative/react/jsi:HermesSnapshotExecutorFactory", | ||
], | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be wrapped in an
if (enableHermes)
? We don't need both hermes and jsc.