hermes icon indicating copy to clipboard operation
hermes copied to clipboard

Building Static Hermes on Windows

Open luboslenco opened this issue 1 year ago • 5 comments

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.

luboslenco avatar Jan 12 '24 13:01 luboslenco

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?

tmikov avatar Jan 12 '24 17:01 tmikov

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.txt to use MSVC sections instead of GCC_COMPATIBLE
    • In lib/VM/StaticH.cpp replaced _longjmp with longjmp
    • In shermes/compile.cpp commented out #include <dlfcn.h> and dlopen() call, removed dl lib from shermes/CMakeLists.txt
  • Now the binaries and libs compile successfully

  • Set the cc env variable and pointed it to clang.exe

  • Used .\shermes.exe -c -typed .\test.ts to produce test.o

  • Linked test.o with my project together with hermesvm_a.lib and jsi.lib

  • Finally I call the main() function contained in test.o and it works!

luboslenco avatar Jan 13 '24 10:01 luboslenco

@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.

tmikov avatar Jan 13 '24 17:01 tmikov

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:

luboslenco avatar Jan 23 '24 10:01 luboslenco

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?

NickNameWolf avatar Apr 10 '24 02:04 NickNameWolf

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

luboslenco avatar Jun 15 '24 18:06 luboslenco