Skip to content

Commit 0645f9f

Browse files
committed
Add Linux build support and fix cross-platform compatibility
- Fix Hermes include path case sensitivity (public vs Public) for Linux - Add ICU library linking required for Hermes on Linux - Propagate C/C++ compiler settings to Hermes external project build - Set CC environment variable when invoking shermes for consistent compiler usage - Add Threads::Threads linking to sokol with proper platform handling - Suppress C99 designator warnings for GNU/Clang compilers in C++ files - Fix struct field initialization order in imgui-runtime.cpp - Add CMake check for node_modules directory with clear error message - Update README with Linux dependencies (X11, OpenGL, ICU) - Update README with Clang compiler requirement and Node.js installation via snap - Mark Linux as tested on Ubuntu 24.04.3 LTS in README - Add commit message style guidelines to CLAUDE.md
1 parent caae199 commit 0645f9f

File tree

9 files changed

+51
-9
lines changed

9 files changed

+51
-9
lines changed

CLAUDE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ When implementing changes:
2323

2424
Never commit code immediately after implementation. The user must review and test first.
2525

26+
**⚠️ COMMIT MESSAGE STYLE**
27+
28+
Write commit messages that are factual and technical:
29+
- State what was changed, not how you feel about it
30+
- Use objective language without emotion, opinions, or exaggeration
31+
- Avoid words like "awesome", "amazing", "great", "excellent", "beautiful"
32+
- Be concise and descriptive
33+
- Focus on the technical change and its purpose
34+
- Wrap lines at 72 characters
35+
36+
Good examples:
37+
- "Add ICU library linking for Linux compatibility"
38+
- "Fix case-sensitive filesystem issue in Hermes includes"
39+
- "Pass compiler settings to Hermes external project"
40+
41+
Bad examples:
42+
- "Amazing fix for the awesome Linux build!"
43+
- "Greatly improve the build system"
44+
- "Make things work better"
45+
2646
## Project Overview
2747

2848
This project implements a custom React reconciler that renders to DearImGUI using Static Hermes. The goal is to use React's declarative component model and JSX syntax to describe ImGUI interfaces, while learning how React works internally.

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ project(imgui-react-runtime)
33

44
set(CMAKE_CXX_STANDARD 17)
55

6+
# Suppress C99 designator warnings for C++ files with GCC/Clang
7+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
8+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-c99-designator>)
9+
endif()
10+
611
# Validate required variables
712
if(NOT CMAKE_BUILD_TYPE)
813
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be set (e.g., Debug or Release)")
@@ -50,7 +55,7 @@ file(GLOB RECONCILER_FILES
5055
# Hermes include directories
5156
include_directories(${HERMES_BUILD}/lib/config)
5257
include_directories(${HERMES_SRC}/include)
53-
include_directories(${HERMES_SRC}/Public)
58+
include_directories(${HERMES_SRC}/public)
5459
include_directories(${HERMES_SRC}/API)
5560
include_directories(${HERMES_SRC}/API/jsi)
5661

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ This project uses typed mode for the ImGui FFI layer (`lib/imgui-unit/`) and unt
9797
### Supported Platforms
9898

9999
- **macOS** ✅ Fully tested and supported
100-
- **Linux** 🔨 Expected to work with minimal changes (untested)
100+
- **Linux** ✅ Tested on Ubuntu 24.04.3 LTS
101101
- **Windows** ⏳ Coming soon (waiting for Static Hermes Windows support)
102102

103103
### Build Requirements
104104

105105
You'll need:
106106

107-
- **Node.js and npm** - For esbuild bundler and React dependencies
107+
- **Node.js and npm** (Node 20 or later recommended) - For esbuild bundler and React dependencies
108108
- macOS: `brew install node` or download from [nodejs.org](https://nodejs.org/)
109-
- Linux: `apt-get install nodejs npm` or `yum install nodejs npm`
109+
- Linux: `snap install node --classic` (recommended) or `apt-get install nodejs npm`
110110
- **C++ Compiler**
111111
- **Clang** (recommended) - Officially supported by Static Hermes
112112
- GCC also works but Clang is the tested configuration
@@ -118,6 +118,9 @@ You'll need:
118118
- **Ninja** - Fast build system
119119
- macOS: `brew install ninja`
120120
- Linux: `apt-get install ninja-build` or `yum install ninja-build`
121+
- **Graphics libraries** - Required for Sokol (window management and OpenGL rendering)
122+
- macOS: (no additional packages needed)
123+
- Linux: `apt-get install libx11-dev libxi-dev libxcursor-dev libgl1-mesa-dev libicu-dev`
121124

122125
**That's it!** The project has **no other dependencies**. The CMake build process automatically downloads and builds Static Hermes on first configure.
123126

@@ -132,7 +135,12 @@ cd imgui-react-runtime
132135
npm install
133136

134137
# Configure (downloads and builds Hermes automatically on first run)
135-
cmake -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -G Ninja
138+
# On Linux, explicitly specify Clang as the compiler:
139+
cmake -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -G Ninja \
140+
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
141+
142+
# On macOS, Clang is the default, so just:
143+
# cmake -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -G Ninja
136144

137145
# Build all examples
138146
cmake --build cmake-build-debug

cmake/HermesExternal.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ else()
8787
-DCMAKE_BUILD_TYPE=Release
8888
-DHERMES_ENABLE_TEST_SUITE=OFF
8989
-DHERMES_BUILD_APPLE_FRAMEWORK=OFF
90+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
91+
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
9092
)
9193

9294
# Add Hermes as external project

cmake/hermes.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function(hermes_compile_native)
8989
# Create custom command
9090
add_custom_command(
9191
OUTPUT ${ARG_OUTPUT}
92-
COMMAND ${SHERMES} ${COMPILER_FLAGS}
92+
COMMAND ${CMAKE_COMMAND} -E env CC=${CMAKE_C_COMPILER} ${SHERMES} ${COMPILER_FLAGS}
9393
DEPENDS ${ARG_SOURCES} ${ARG_DEPENDS}
9494
WORKING_DIRECTORY ${ARG_WORKING_DIRECTORY}
9595
COMMENT ${ARG_COMMENT}

cmake/react-imgui.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ function(add_react_imgui_app)
7575
${CMAKE_CURRENT_SOURCE_DIR}/*.js
7676
)
7777

78+
# Check if npm install has been run
79+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/node_modules")
80+
message(FATAL_ERROR "node_modules/ directory not found. Please run 'npm install' in the project root before building.")
81+
endif()
82+
7883
# Build dependency list
7984
set(REACT_UNIT_DEPS
8085
${RECONCILER_FILES}

external/sokol/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ else ()
3434
add_library(sokol STATIC sokol.c ${SOKOL_HEADERS})
3535
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
3636
target_link_libraries(sokol INTERFACE X11 Xi Xcursor GL dl m)
37-
find_package(Threads)
38-
target_link_libraries(sokol PUBLIC Threads::Threads)
3937
endif ()
4038
endif ()
39+
40+
find_package(Threads REQUIRED)
41+
target_link_libraries(sokol PUBLIC Threads::Threads)
4142
target_link_libraries(sokol PUBLIC cimgui)
4243
target_include_directories(sokol INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
4344
target_compile_definitions(sokol PUBLIC ${SOKOL_DEFINES})

lib/imgui-runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ target_link_libraries(imgui-runtime
1616
sokol stb cimgui imgui-unit jslib-unit
1717
$<$<CONFIG:Release>:hermesvm_a jsi boost_context>
1818
$<$<CONFIG:Debug>:hermesvm>
19+
$<$<PLATFORM_ID:Linux>:icuuc icui18n icudata>
1920
)
2021
target_include_directories(imgui-runtime INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})

lib/imgui-runtime/imgui-runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ extern "C" const simgui_image_t *image_simgui_image(int index) {
142142
}
143143

144144
static void app_init() {
145-
sg_desc desc = {.context = sapp_sgcontext(), .logger.func = slog_func};
145+
sg_desc desc = {.logger.func = slog_func, .context = sapp_sgcontext()};
146146
sg_setup(&desc);
147147
simgui_setup(simgui_desc_t{});
148148

0 commit comments

Comments
 (0)