如果你想从源码构建 Hermes 或将其集成到 React Native 应用中,本文将指导你完成基本的构建步骤。
前置要求
- 典型的原生开发工具
- CMake 支持
- Ninja 构建系统
macOS/Linux 构建
mkdir hermes_workingdir
cd hermes_workingdir
git clone https://github.com/facebook/hermes.git
cmake -S hermes -B build -G Ninja
cmake --build ./build
Windows 构建
mkdir hermes_workingdir
cd hermes_workingdir
git -c core.autocrlf=false clone https://github.com/facebook/hermes.git
cmake -S hermes -B build -G 'Visual Studio 16 2019' -A x64
cmake --build ./build
运行 JavaScript
构建完成后,可以使用 Hermes CLI 运行 JavaScript:
echo "'use strict'; function hello() { print('Hello World'); } hello();" | ./bin/hermes
详细文档
- 构建和运行 Hermes:doc/BuildingAndRunning.md
- 在 React Native 中使用自定义 Hermes 构建:doc/ReactNativeIntegration.md