Skip to content
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

feat(hermes): hermes engine support #4169

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6d80659
feat(hermes): support hermes engine first part
wwwcg Nov 4, 2024
f3850f5
fix(ios): resolve hermes build error
wwwcg Jun 26, 2024
f4dd1dc
feat(hermes): remove obsolete context wrapper
wwwcg Aug 15, 2024
6ac72eb
feat(ios): support dynamic switching hermes and jsc
wwwcg Sep 20, 2024
92d98a5
feat(hermes): engine infrastructure improve
wwwcg Oct 16, 2024
00d7610
feat(hermes): devtools support for ios
wwwcg Oct 25, 2024
352583c
feat(hermes): update engine version and
wwwcg Oct 25, 2024
79f9269
feat(ios): drop v8 engine support
wwwcg Nov 4, 2024
60df1c1
refactor(ios): bridge setup process and update demo
wwwcg Nov 5, 2024
2052d73
chore(hermes): resolve build issue
wwwcg Nov 5, 2024
6f8bb28
chore(ios): remove unnecessary assert
wwwcg Nov 5, 2024
6a71c3b
fix(hermes): resolve context nullptr exception
wwwcg Nov 6, 2024
0581a88
feat(hermes): using embeded hbc code for hermes
wwwcg Nov 7, 2024
f4310de
feat(hermes): resolve bugs and code clean
wwwcg Nov 12, 2024
bdf2207
feat(hermes): update ws url for devtools under hermes engine
wwwcg Nov 14, 2024
8b53bb6
feat(hermes): resolve build issue
wwwcg Nov 14, 2024
229b146
feat(hermes): add ArrayBuffer type support
wwwcg Nov 22, 2024
149ad2a
fix(hermes): resolve rebase issues
wwwcg Dec 16, 2024
cf53e7b
fix(hermes): dynamic load not support for hermes
wwwcg Dec 25, 2024
a02cfb2
chore(hermes): add warning ignore mark
wwwcg Dec 25, 2024
214eb16
feat(hermes): engine ctx bugfix
wwwcg Jan 7, 2025
42475c1
feat(hermes): resolve android build issues
wwwcg Jan 7, 2025
4a1c41b
feat(hermes): resolve android build issue
wwwcg Jan 13, 2025
5706622
fix(hermes): add null pointer check during engine release
wwwcg Jan 16, 2025
2f245e7
feat(hermes): resolve context release issue
wwwcg Jan 17, 2025
ba21ba9
Merge branch 'main' into feature/hermes_engine_v2
wwwcg Jan 23, 2025
434fe2b
feat(hermes): use toLocaleLowerCase since hermes support
wwwcg Jan 23, 2025
53834bd
fix(hermes): resolve build issues
wwwcg Jan 23, 2025
adebc19
feat(hermes): use toLowerCase in hippy js package
wwwcg Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dist
node_modules
xcuserdata
v8forios
hermesforios

*.log
*.iml
Expand Down
2 changes: 2 additions & 0 deletions devtools/devtools-backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ if ("${JS_ENGINE}" STREQUAL "V8")
target_compile_definitions(${PROJECT_NAME} PRIVATE "JS_V8")
elseif ("${JS_ENGINE}" STREQUAL "JSC")
target_compile_definitions(${PROJECT_NAME} PRIVATE "JS_JSC")
elseif ("${JS_ENGINE}" STREQUAL "HERMES")
target_compile_definitions(${PROJECT_NAME} PUBLIC "JS_HERMES")
endif ()
# endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ DevtoolsBackendService::DevtoolsBackendService(const DevtoolsConfig& devtools_co
DevtoolsBackendService::~DevtoolsBackendService() { FOOTSTONE_DLOG(INFO) << kDevToolsTag << "~DevtoolsBackendService"; }

void DevtoolsBackendService::Create() {
#if defined(JS_V8) && !defined(V8_WITHOUT_INSPECTOR)
#if (defined(JS_V8) && !defined(V8_WITHOUT_INSPECTOR)) || defined(JS_HERMES)
data_channel_->GetNotificationCenter()->vm_response_notification =
std::make_shared<DefaultVmResponseAdapter>([WEAK_THIS](const std::string& data) {
DEFINE_AND_CHECK_SELF(DevtoolsBackendService)
Expand Down
2 changes: 1 addition & 1 deletion devtools/devtools-backend/src/module/domain_dispatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ bool DomainDispatch::ReceiveDataFromFrontend(const std::string& data_string) {
}

void DomainDispatch::DispatchToVm(const std::string& data) {
#if defined(JS_V8) && !defined(V8_WITHOUT_INSPECTOR)
#if (defined(JS_V8) && !defined(V8_WITHOUT_INSPECTOR)) || defined(JS_HERMES)
FOOTSTONE_DLOG(INFO) << kDevToolsTag << "JSDebugger, params=" << data.c_str();
auto vm_request = data_channel_->GetProvider()->vm_request_adapter;
if (vm_request) {
Expand Down
2 changes: 2 additions & 0 deletions devtools/devtools-integration/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ if ("${JS_ENGINE}" STREQUAL "V8")
endif ()
elseif ("${JS_ENGINE}" STREQUAL "JSC")
target_compile_definitions(${PROJECT_NAME} PRIVATE "JS_JSC")
elseif ("${JS_ENGINE}" STREQUAL "HERMES")
target_compile_definitions(${PROJECT_NAME} PRIVATE "JS_HERMES")
endif ()
# endregion

Expand Down
49 changes: 2 additions & 47 deletions docs/development/ios-3.0-integration-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,56 +153,11 @@ rootView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizin

Hippy 3.x的一个重要特性是支持了多引擎的便捷切换,目前,可切换的引擎有两个,一是布局引擎,二是JS引擎。默认配置下,Hippy使用布局引擎是[Taitank](https://github.com/Tencent/Taitank),JS引擎是iOS系统内置的`JavaScriptCore`。

如需使用其他布局引擎,如[Yoga](https://github.com/facebook/yoga),或使用其他JS引擎,如V8,可参考如下指引调整Hippy接入配置。

> Hippy3.x提供了iOS环境下默认的v8引擎实现,如需使用其他JS引擎需用户自行实现相关napi接口。
如需使用其他布局引擎,如[Yoga](https://github.com/facebook/yoga),或使用其他JS引擎,可参考如下指引调整Hippy接入配置。

### 4.1 切换JS引擎

如需使用V8引擎,在Podfile文件中添加如下环境变量即可:

```ruby
ENV['js_engine'] = 'v8'
```

修改后的Podfile应该看起来像这样:

```text
#use_frameworks!
platform :ios, '11.0'
ENV['js_engine'] = 'v8' #切换为V8引擎

# TargetName大概率是您的项目名称
target TargetName do

pod 'hippy', 'your_specified_version'

end
```

之后,重新执行`pod install`命令更新项目依赖即可。

如需使用其他第三方JS引擎,需要做如下操作:

#### 1.修改Podfile配置为第三方JS引擎

将Podfile中的js_engine环境变量配置为other,这样在拉取代码时,jsc或者v8的代码将不会被添加到工程中。

```ruby
ENV['js_engine'] = 'other'
```

> Hippy3.0中使用napi抽象了不同JS引擎的接口。其中,JSC与V8的接口进行了实现。用户若使用JSC或者V8,可直接切换,Hippy默认进行了实现。

#### 2.自行实现napi抽象接口

napi将js引擎接口抽象化,由js driver层调用。接入方自行实现napi接口,即可实现对第三方JS引擎的支持。

napi文件位于 `/driver/js/napi*` 目录下。

#### 3.将实现文件添加到工程中

接入方自行将对应的napi实现文件添加到工程中。
TODO: 切换Hermes引擎

## 4.2 切换布局引擎

Expand Down
32 changes: 31 additions & 1 deletion driver/js/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ cmake_minimum_required(VERSION 3.14)

project("js_driver")

add_compile_options(-fno-rtti)

get_filename_component(PROJECT_ROOT_DIR "${PROJECT_SOURCE_DIR}/../.." REALPATH)

include("${PROJECT_ROOT_DIR}/buildconfig/cmake/GlobalPackagesModule.cmake")
Expand Down Expand Up @@ -127,6 +129,18 @@ if ("${JS_ENGINE}" STREQUAL "V8")
endif ()
elseif ("${JS_ENGINE}" STREQUAL "JSC")
target_compile_definitions(${PROJECT_NAME} PUBLIC "JS_JSC")
elseif ("${JS_ENGINE}" STREQUAL "HERMES")
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
set(HERMES_REMOTE_FILENAME "android.tgz")
else ()
message(FATAL_ERROR
"Unsupported system ${CMAKE_SYSTEM_NAME}")
endif ()
InfraPackage_Add(Hermes
REMOTE "global_packages/hermes/${HERMES_COMPONENT}/${HERMES_REMOTE_FILENAME}"
LOCAL "${HERMES_COMPONENT}")
target_link_libraries(${PROJECT_NAME} PUBLIC hermes)
target_compile_definitions(${PROJECT_NAME} PUBLIC "JS_HERMES")
elseif ("${JS_ENGINE}" STREQUAL "JSH")
target_compile_definitions(${PROJECT_NAME} PUBLIC "JS_JSH")
endif ()
Expand Down Expand Up @@ -188,6 +202,7 @@ set(SOURCE_SET
src/modules/event_module.cc
src/modules/scene_builder_module.cc
src/napi/callback_info.cc
src/napi/js_try_catch.cc
src/performance/performance.cc
src/performance/performance_entry.cc
src/performance/performance_frame_timing.cc
Expand Down Expand Up @@ -222,14 +237,29 @@ elseif ("${JS_ENGINE}" STREQUAL "JSC")
src/napi/jsc/jsc_ctx.cc
src/napi/jsc/jsc_try_catch.cc
src/vm/jsc/jsc_vm.cc
src/vm/jsc/native_source_code_ios.cc)
src/vm/jsc/native_source_code_jsc.cc)
elseif ("${JS_ENGINE}" STREQUAL "JSH")
list(APPEND SOURCE_SET
src/napi/jsh/jsh_class_definition.cc
src/napi/jsh/jsh_ctx.cc
src/napi/jsh/jsh_try_catch.cc
src/vm/jsh/jsh_vm.cc
src/vm/jsh/native_source_code_ohos.cc)
elseif("${JS_ENGINE}" STREQUAL "HERMES")
list(APPEND SOURCE_SET
src/napi/hermes/hermes_class_definition.cc
src/napi/hermes/hermes_ctx.cc
src/napi/hermes/hermes_ctx_value.cc
src/napi/hermes/hermes_try_catch.cc
src/vm/hermes/hermes_vm.cc)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
list(APPEND SOURCE_SET src/vm/hermes/native_source_code_hermes_android.cc)
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
list(APPEND SOURCE_SET src/vm/hermes/native_source_code_hermes_ios.cc)
else()
message(FATAL_ERROR
"Unsupported system ${CMAKE_SYSTEM_NAME} by hermes engine")
endif()
endif ()
set(SOURCE_SET_STANDALONE
src/modules/console_module.cc
Expand Down
2 changes: 2 additions & 0 deletions driver/js/examples/hippy-react-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"hippy:build": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.ios.js --config ./scripts/hippy-webpack.android.js --config ./scripts/hippy-webpack.ohos.js",
"web:dev": "npm run hippy:dev & node ./scripts/env-polyfill.js webpack serve --config ./scripts/hippy-webpack.web-renderer.dev.js",
"web:build": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.web-renderer.js",
"hippy:vendor:hermes": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.hermes.ios-vendor.js --config ./scripts/hippy-webpack.hermes.android-vendor.js",
"hippy:build:hermes": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.hermes.ios.js --config ./scripts/hippy-webpack.hermes.android.js"
"ohos:vendor": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.ohos-vendor.js",
"ohos:build": "node ./scripts/env-polyfill.js webpack --config ./scripts/hippy-webpack.ohos.js"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');

const platform = 'android';
const engine = 'hermes';

module.exports = {
mode: 'production',
bail: true,
entry: {
vendor: [path.resolve(__dirname, './vendor.js')],
},
output: {
filename: `[name].${platform}.js`,
path: path.resolve(`./dist/${platform}_${engine}/`),
globalObject: '(0, eval)("this")',
library: 'hippyReactBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
}),
new CaseSensitivePathsPlugin(),
new webpack.DllPlugin({
context: path.resolve(__dirname, '..'),
path: path.resolve(__dirname, `../dist/${platform}/[name]-manifest.json`),
name: 'hippyReactBase',
}),
],
module: {
rules: [
{
test: /\.(js)$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
chrome: 41,
},
},
],
],
plugins: [
['@babel/plugin-proposal-class-properties'],
],
},
},
],
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
// if node_modules path listed below is not your repo directory, change it.
modules: [path.resolve(__dirname, '../node_modules')],
alias: (() => {
const aliases = {};
// If hippy-react was built exist then make a alias
// Remove the section if you don't use it
const hippyReactPath = path.resolve(__dirname, '../../../packages/hippy-react');
if (fs.existsSync(path.resolve(hippyReactPath, 'dist/index.js'))) {
console.warn(`* Using the @hippy/react in ${hippyReactPath}`);
aliases['@hippy/react'] = hippyReactPath;
} else {
console.warn('* Using the @hippy/react defined in package.json');
}

return aliases;
})(),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const HippyDynamicImportPlugin = require('@hippy/hippy-dynamic-import-plugin');
const pkg = require('../package.json');
const manifest = require('../dist/android/vendor-manifest.json');

const platform = 'android';
const engine = 'hermes';

module.exports = {
mode: 'production',
bail: true,
entry: {
index: ['regenerator-runtime', path.resolve(pkg.main)],
},
output: {
filename: `[name].${platform}.js`,
path: path.resolve(`./dist/${platform}_${engine}/`),
globalObject: '(0, eval)("this")',
// CDN path can be configured to load children bundles from remote server
// publicPath: 'https://xxx/hippy/hippyReactDemo/',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
}),
new CaseSensitivePathsPlugin(),
new webpack.DllReferencePlugin({
context: path.resolve(__dirname, '..'),
manifest,
}),
new HippyDynamicImportPlugin(),
// LimitChunkCountPlugin can control dynamic import ability
// Using 1 will prevent any additional chunks from being added
// new webpack.optimize.LimitChunkCountPlugin({
// maxChunks: 1,
// }),
// use SourceMapDevToolPlugin can generate sourcemap file
// new webpack.SourceMapDevToolPlugin({
// test: /\.(js|jsbundle|css|bundle)($|\?)/i,
// filename: '[file].map',
// }),
],
module: {
rules: [
{
test: /\.(jsx?)$/,
use: [
{
loader: 'babel-loader',
options: {
sourceType: 'unambiguous',
presets: [
'@babel/preset-react',
[
'@babel/preset-env',
{
targets: {
chrome: 41,
},
},
],
],
plugins: [
['@babel/plugin-proposal-class-properties'],
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-transform-runtime', { regenerator: true }],
],
},
},
],
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [{
loader: 'url-loader',
options: {
// if you would like to use base64 for picture, uncomment limit: true
// limit: true,
limit: 8192,
fallback: 'file-loader',
name: '[name].[ext]',
outputPath: 'assets/',
},
}],
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
// if node_modules path listed below is not your repo directory, change it.
modules: [path.resolve(__dirname, '../node_modules')],
alias: (() => {
const aliases = {};

// If hippy-react was built exist then make a alias
// Remove the section if you don't use it
const hippyReactPath = path.resolve(__dirname, '../../../packages/hippy-react');
if (fs.existsSync(path.resolve(hippyReactPath, 'dist/index.js'))) {
console.warn(`* Using the @hippy/react in ${hippyReactPath}`);
aliases['@hippy/react'] = hippyReactPath;
} else {
console.warn('* Using the @hippy/react defined in package.json');
}

return aliases;
})(),
},
};
Loading
Loading