GitXplorerGitXplorer
t

hermes-jsi-demos

public
97 stars
3 forks
0 issues

Commits

List of commits on branch master.
Unverified
1fa1c701b3d48b94f5a0a7f630257e9c75a78fcb

Add type check in hostAdd().

ttmikov committed 9 months ago
Unverified
2cf5879a4fa9c18054f619a500221fe3a8911183

evloop: fix task id assignment

ttmikov committed 9 months ago
Unverified
6ce03161543b171be20fa5ec2d683d3629e1c1d0

Add an example with an event loop.

ttmikov committed 9 months ago
Unverified
3332e256b0d4def5e48ceb197d755d2b83d2d3e4

README.md: update links to demos.

ttmikov committed 9 months ago
Unverified
efcf2a2c14af9dfc4f45b9c533b1285f7498965f

Initial commit

ttmikov committed 9 months ago

README

The README file for this repository.

hermes-jsi-demos

This repository contains small demos of using the Hermes JavaScript engine with JSI without React Native or any other framework.

Every demo is constructed as an independent CMake project, which can be copied and customized, but they can also be built together from the top-level directory.

Demos

In order of increasing complexity:

  • hello - a simple "Hello, world!" demo, running a JS script embedded in C++.
  • runner - runs a JS script from a file.
  • host-functions - demonstrates registering host functions into the global object.
  • hf-runner - demonstrate registering host functions from dynamically loaded shared libraries.
  • evloop - demonstrates a simple event loop, which enables setTimeout() and setImmediate(), plus WeakRef.

Building

Pre-requisites

  • CMake 3.20 or later
  • Ninja
  • A C++ compiler
  • git

Building and running the demos has been tested on Linux and macOS, but not on Windows. PRs adding support for Windows are welcome.

On macOS, I recommend installing XCode or the XCode command line tools, and using brew to obtain CMake and Ninja.

Build Hermes

First you need to build hermes. Obtain a clean checkout of Hermes from https://github.com/facebook/hermes.git:

$ git clone https://github.com/facebook/hermes.git 

Create a Hermes build directory somewhere, depending on your preferences, and name it according. Then configure and build Hermes:

mkdir hermes-debug
cd hermes-debug
cmake -G Ninja -DHERMES_BUILD_APPLE_FRAMEWORK=OFF -DCMAKE_BUILD_TYPE=Debug <path-to-hermes-checkout> 
ninja

You can change the build type by specifying -DCMAKE_BUILD_TYPE=Release. -DHERMES_BUILD_APPLE_FRAMEWORK=OFF is important on MacOS, so make sure you don't forget it.

Build the demos

All demos require two CMake defines to be set:

  • HERMES_SRC_DIR - the path to the Hermes checkout.
  • HERMES_BUILD_DIR - the path to the Hermes build directory from above.

Create a build directory for the demos in a location, depending on your preferences, and name it accordingly. Then configure and build the demos:

mkdir demos-debug
cd demos-debug
cmake -G Ninja -DHERMES_SRC_DIR=<path-to-hermes-checkout> \
  -DHERMES_BUILD_DIR=<path-to-hermes-build> \
  <path-to-demos-checkout>
ninja demos

Final Words

This project is built for education purposes, and is not intended to be used in production. Questions, discussions and PRs are highly encouraged.