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

Build sail on Windows? #816

Open
wanghuibin0 opened this issue Dec 6, 2024 · 3 comments
Open

Build sail on Windows? #816

wanghuibin0 opened this issue Dec 6, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@wanghuibin0
Copy link

wanghuibin0 commented Dec 6, 2024

Due to my work environment, I need to compile Sail on Windows, but I'm running into some issues.

I know OCaml supports Windows, and I’ve successfully set up the OCaml development environment following the official steps.
However, when I try to compile Sail, I’m encountering problems. Some libraries that Sail depends on, like linenoise, seem to not work properly on Windows. When I try to install it, the compilation fails. I’ve attached the error message below.

Has anyone run into similar issues? Has anyone successfully built Sail on Windows? If so, I’d love to hear about your experience!

C:\Users\fight>opam install linenoise
The following actions will be performed:
=== install 2 packages
  ∗ dune      3.17.0 [required by linenoise]
  ∗ linenoise 1.5.1

Proceed with ∗ 2 installations? [y/n]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
⬇ retrieved linenoise.1.5.1  (https://opam.ocaml.org/cache)
⬇ retrieved dune.3.17.0  (https://opam.ocaml.org/cache)
∗ installed dune.3.17.0
[ERROR] The compilation of linenoise.1.5.1 failed at "dune build @install -p linenoise -j 19".

#=== ERROR while compiling linenoise.1.5.1 ====================================#
# context     2.3.0 | win32/x86_64 | ocaml.5.2.1 | https://opam.ocaml.org#fa9b494582b7d5754eebf54eac25d1bc7cd62cb0
# path        ~\AppData\Local\opam\default\.opam-switch\build\linenoise.1.5.1
# command     ~\AppData\Local\opam\default\bin\dune.exe build @install -p linenoise -j 19
# exit-code   1
# env-file    ~\AppData\Local\opam\log\linenoise-10612-41d9a6.env
# output-file ~\AppData\Local\opam\log\linenoise-10612-41d9a6.out
### output ###
# File "src/dune", line 8, characters 11-24:
# 8 |   (c_names linenoise_src linenoise_stubs))
#                ^^^^^^^^^^^^^
# (cd _build/default/src && C:\Users\fight\AppData\Local\opam\default\bin\x86_64-w64-mingw32-gcc.exe -O2 -fno-strict-aliasing -fwrapv -mms-bitfields -O2 -fno-strict-aliasing -fwrapv -mms-bitfields -g -I C:/Users/fight/AppData/Local/opam/default/lib/ocaml -o linenoise_src.o -c linenoise_src.c)
# linenoise_src.c:103:10: fatal error: termios.h: No such file or directory
#   103 | #include <termios.h>
#       |          ^~~~~~~~~~~
# compilation terminated.



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
┌─ The following actions failed
│ λ build linenoise 1.5.1
└─
┌─ The following changes have been performed
│ ∗ install dune 3.17.0
└─

It seems that termios.h is not available in MinGW environment. But ocaml seems to work with MinGW toolchain. How can I solve this issue?

@Alasdair
Copy link
Collaborator

Alasdair commented Dec 6, 2024

I know people have had success using WSL if that is an option for you?

We could make our readline editing support in the REPL optional. In general I suspect windows support wouldn't be that hard as we don't have many dependencies, I'd just need access to a Windows machine to actually try it...

@wanghuibin0
Copy link
Author

I know people have had success using WSL if that is an option for you?

We could make our readline editing support in the REPL optional. In general I suspect windows support wouldn't be that hard as we don't have many dependencies, I'd just need access to a Windows machine to actually try it...

Thanks for your reply.

WSL definitely works well for building sail, but I have some special need that force me build sail on native Windows.
So I will explore how to remove those dependencies that are not supported on native Windows.

@Alasdair Alasdair added the enhancement New feature or request label Dec 17, 2024
@trdthg
Copy link
Contributor

trdthg commented Dec 24, 2024

HI, out of curiosity, I also tried it and made some discoveries

First, I compiled ocaml-linenoise successfully by cloning it locally and adding some cflags in dune

You can search for the location of termio.h on your computer.

 (library
   (name linenoise)
   (public_name linenoise)
   (modules LNoise)
   (wrapped false)
   (flags :standard -warn-error -3)
+  (c_flags -I C:\Users\user\AppData\Local\opam\.cygwin\root\usr\include)
   (c_names linenoise_src linenoise_stubs))

But the troublesome things had just begin; the next compilation failure is lem, and there is already a related issue here rems-project/lem#16

I encountered many issues, mainly related to missing dependencies. By doing a few things, I still managed to complete the compilation

The first step is to add two library path in lem/src/Makefile (there may be better ways, but I am not very familiar with ocamlbuild yet), one for -lgmp and the other for -lgcc_em

all:
	ocamlbuild -use-ocamlfind \
		-cflag -g \
		-cflag -I -cflag /cygdrive/c/Users/user/AppData/Local/opam/.cygwin/root/usr/include \
		-lflag -ccopt -lflag "-L /cygdrive/c/Users/user/AppData/Local/opam/.cygwin/root/usr/x86_64-w64-mingw32/sys-root/mingw/lib -L /cygdrive/c/Users/trdthg/AppData/Local/opam/.cygwin/root/lib/gcc/x86_64-w64-mingw32/12" \
		main.native

In addition, there will be two path not found issues when running this command,mingw/lib and the mingw/sys-root (I didn't keep the complete error message),I found the correct path and manually created the symbolic link. Finally able to compile successfully.

user@LAPTOP /cygdrive/c/Users/user/repo/lem/library
$ file ../src/_build/main.native
../src/_build/main.native: PE32+ executable (console) x86-64, for MS Windows, 22 sections

However, the compiled binary is not available; when you run lem, it only reports 127

(I feel that building on Windows is not a good choice 😶)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants