Building Static Hermes on Windows
Problem
Hello and congratulations on your progress with Static Hermes.
I managed to build and run the static_h branch on Linux, everything is perfect there. I am unable to build it on Windows, which I think is expected as of now. Is there a plan to add Windows support? What needs to be done to make it happen?
Some of the errors occurring right now:
fatal error C1007: unrecognized flag '-UndefIntOverflow-' in 'p2'
hermes\include\hermes\IR\IR.h(2076,17): error C7555: use of designated initializers
requires at least '/std:c++20'
Getting past those:
hermes\lib\IR\IR.cpp(574,17): error C2248: 'hermes::Value::operator delete': cannot
access private member declared in class 'hermes::Value'
...
Thanks for your time.
Hi, this is a very good question. Static Hermes will support Windows but only via Clang, not MSVC. Since Static Hermes will rely on LLVM as a backend, the C output is just temporary, so it is not really worth it to support building the compiler with MSVC, when everything else (including parts of the Static Hermes runtime itself, which are written in JS) relies on LLVM.
This is not set in stone, but is the plan for now.
EDIT: can you try building it on Windows with Clang?
can you try building it on Windows with Clang?
Thanks for the tip!
-
I installed
C++ Clang tools for Windows (16.0.5 - x64/x86)via Visual Studio Installer -
Used the following commands to build:
cmake -S hermes -B build -G 'Visual Studio 17 2022' -T ClangCL -A x64
cmake --build ./build
- This leads to errors / warnings:
clang-cl : warning : unknown argument ignored in clang-cl: '-fvisibility=hidden' [-Wunknown-argument]
clang-cl : warning : unknown argument ignored in clang-cl: '-fno-strict-overflow' [-Wunknown-argument]
clang-cl : warning : unknown argument ignored in clang-cl: '-fno-exceptions' [-Wunknown-argument]
clang-cl : warning : unknown argument ignored in clang-cl: '-fno-rtti' [-Wunknown-argument]
hermes\lib\IR\IR.cpp(574,17): error : 'operator delete' is a private member of 'hermes::Value'
hermes\lib\VM\StaticH.cpp(328,3): error : use of undeclared identifier '_longjmp'; did you mean 'longjmp'?
-
The hacky way I got past these (just for testing):
- Modified
CMakeLists.txtto useMSVCsections instead ofGCC_COMPATIBLE - In
lib/VM/StaticH.cppreplaced_longjmpwithlongjmp - In
shermes/compile.cppcommented out#include <dlfcn.h>anddlopen()call, removeddllib fromshermes/CMakeLists.txt
- Modified
-
Now the binaries and libs compile successfully
-
Set the
ccenv variable and pointed it toclang.exe -
Used
.\shermes.exe -c -typed .\test.tsto producetest.o -
Linked
test.owith my project together withhermesvm_a.libandjsi.lib -
Finally I call the
main()function contained intest.oand it works!
@luboslenco great! Nice job!! It is very good to know that it can build and even run!
We need to figure out how to automatically detect this particular configuration - Clang on Windows with MSVC-compatible CLI, but there shouldn't be any major problems, since Hermes itself compiles and is widely used on Windows.
I don't think we will add it to our CI just yet, but we likely will before the middle of the year.
Just a side note, with mostly straightforward build tweaks I was able to run Static Hermes on Android, iOS, Windows (+ macOS and Linux). :slightly_smiling_face:
Just a side note, with mostly straightforward build tweaks I was able to run Static Hermes on Android, iOS, Windows (+ macOS and Linux). 🙂
i am trying build static hermers for iOS on macos, but i can not build success. can you show me your build commands?
Sorry about the delay, here are the build commands I have used:
cmake -S hermes -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DHERMES_UNICODE_LITE=1 -DHERMES_ENABLE_TEST_SUITE=0
cmake --build ./build
cd hermes
./utils/build-ios-framework.sh