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

Static Hermes for React Native #3

Closed
wants to merge 80 commits into from
Closed

Static Hermes for React Native #3

wants to merge 80 commits into from

Conversation

piaskowyk
Copy link
Member

@piaskowyk piaskowyk commented Nov 18, 2024

Summary

This PR introduces necessary changes to let React Native uses latest version of static Hermes.

Explanation

Part 1

set(OVERRIDE_HERMES_MOBILE_BUILD OFF CACHE BOOL "Workaround for Android builds that use ES types defined conditionally")
if (OVERRIDE_HERMES_MOBILE_BUILD)
  set(HERMES_IS_MOBILE_BUILD OFF)
endif()

The HERMES_IS_MOBILE_BUILD flag is only set when the HERMES_IS_ANDROID flag is active. However, these two have different roles. To correctly build for Android, I need the flexibility to set these flags separately. This is crucial because the HERMES_IS_MOBILE_BUILD flag might lead to build failures if there are undeclared types being used - an issue we've already flagged to the Hermes team (I can create an issue with a description if you wants)

Part 2

append("/d2UndefIntOverflow-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)

It seems like this flag doesn’t exist anymore in the MSVC 16 compiler.
CI logs - https://github.com/piaskowyk/react-native/actions/runs/11815096269/job/32915591004

fatal error C1007: unrecognized flag '-UndefIntOverflow-' in 'p2'

Part 3

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
  # MSVC needs C++20
  set(CMAKE_CXX_STANDARD 20)
else()
  set(CMAKE_CXX_STANDARD 17)
endif()

Some of the new syntax in static Hermes requires the newer C++ standard on MSVC.

Part 4

# Changes in lib/CMakeLists.txt

These updates are necessary to successfully build the Hermes Framework for iOS.

Part 5

namespace hermes {
namespace hbc {
namespace {

class BytecodeSerializer {
-  friend void visitBytecodeSegmentsInOrder<BytecodeSerializer>(
+  friend void hermes::hbc::visitBytecodeSegmentsInOrder<BytecodeSerializer>(

Due to additional additional anonymous namespace, the MSVC wasn't able to recognise proper symbol without explicite definition.

Test Plan

Build RNTester app from here - https://github.com/piaskowyk/react-native/tree/%40piaskowyk/build-static-hermes

@piaskowyk piaskowyk closed this Nov 18, 2024
@piaskowyk piaskowyk deleted the static-hermes branch November 27, 2024 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants