haskell / entropy

Easy entropy source for Haskell users.
Other
24 stars 49 forks source link

Having some trouble install entropy by stack #68

Closed ych817 closed 1 year ago

ych817 commented 2 years ago

Greetings !

I got some trouble while building entropy on windows :

PS D:\study\Haskell\CodeArena\animate> stack install entropy
entropy> configure
entropy> [1 of 2] Compiling Main             ( C:\\Users\Ziyan Chen\AppData\Local\Temp\stack-90f2c3a41cbee11a\entropy-0.4.1.7\Setup.hs, C:\\Users\Ziyan Chen\AppData\Local\Temp\stack-90f2c3a41cbee11a\entropy-0.4.1.7\.stack-work\dist\274b403a\setup\Main.o )
entropy> [2 of 2] Compiling StackSetupShim   ( C:\\Users\Ziyan Chen\AppData\Roaming\stack\setup-exe-src\setup-shim-Z6RU0evB.hs, C:\\Users\Ziyan Chen\AppData\Local\Temp\stack-90f2c3a41cbee11a\entropy-0.4.1.7\.stack-work\dist\274b403a\setup\StackSetupShim.o )
entropy> Linking C:\\Users\\Ziyan Chen\\AppData\\Local\\Temp\\stack-90f2c3a41cbee11a\\entropy-0.4.1.7\\.stack-work\\dist\\274b403a\\setup\\setup.exe ...
entropy> Configuring entropy-0.4.1.7...
entropy> build
entropy> Result of RDRAND Test: True
entropy>
entropy> C:\Users\Ziyan Chen\AppData\Local\Temp\stack-90f2c3a41cbee11a\entropy-0.4.1.7\testLibcGetrandom-14500\testLibcGetrandom.c:3:10: error:
entropy>      fatal error: sys/random.h: No such file or directory
entropy>         3 | #include <sys/random.h>
entropy>           |          ^~~~~~~~~~~~~~
entropy>   |
entropy> 3 | #include <sys/random.h>
entropy>   |          ^
entropy> compilation terminated.
entropy> `gcc.exe' failed in phase `C Compiler'. (Exit code: 1)
entropy> Result of libc getrandom() Test: False
entropy>
entropy> C:\Users\Ziyan Chen\AppData\Local\Temp\stack-90f2c3a41cbee11a\entropy-0.4.1.7\testSyscallGetrandom-14500\testSyscallGetrandom.c:4:10: error:
entropy>      fatal error: sys/syscall.h: No such file or directory
entropy>         4 | #include <sys/syscall.h>
entropy>           |          ^~~~~~~~~~~~~~~
entropy>   |
entropy> 4 | #include <sys/syscall.h>
entropy>   |          ^
entropy> compilation terminated.
entropy> `gcc.exe' failed in phase `C Compiler'. (Exit code: 1)
entropy> Result of syscall getrandom() Test: False
entropy> testGetentropy-14500\testGetentropy.c: In function 'main':
entropy>
entropy> C:\Users\Ziyan Chen\AppData\Local\Temp\stack-90f2c3a41cbee11a\entropy-0.4.1.7\testGetentropy-14500\testGetentropy.c:6:12: error:
entropy>      warning: implicit declaration of function 'getentropy' [-Wimplicit-function-declaration]
entropy>         6 |     return getentropy(&tmp, sizeof(tmp));
entropy>           |            ^~~~~~~~~~
entropy>   |
entropy> 6 |     return getentropy(&tmp, sizeof(tmp));
entropy>   |            ^
entropy> C://Users//Ziyan Chen//AppData//Local//Programs//stack//x86_64-windows//ghc-8.10.7//mingw//bin/ld.exe: testGetentropy-14500\testGetentropy.o:testGetentropy.c:(.text+0x1a): undefined reference to `getentropy'
entropy> collect2.exe: error: ld returned 1 exit status
entropy> `gcc.exe' failed in phase `Linker'. (Exit code: 1)
entropy> Result of getentropy() Test: False
entropy> Preprocessing library for entropy-0.4.1.7..
entropy> Building library for entropy-0.4.1.7..
entropy> [1 of 2] Compiling System.EntropyWindows
entropy>
entropy> System\EntropyWindows.hs:100:1: warning: [-Wunsupported-calling-conventions]
entropy>     <stderr>: commitAndReleaseBuffer: invalid argument (invalid character)

It says " sys/random.h : no such file or directory " and " sys/syscall.h : no such file or directory " . So :

I tried to find some libraries on MSYS2 package website and I found nothing .......... therefore I downloaded these 2 files from the internet and move them to .....\msys64\usr\include\sys\ , but it doesn't work . Would you mind giving me some suggestions ? Thanks .

ysangkok commented 2 years ago

The error you see related to sys/syscall.h is expected. This file is compiled to see if you're on a system that provides this method of entropy. The test concludes that the method isn't available, which is fine. Thie is what Result of [...]: False means.

You should never copy random files into your msys installation, since msys uses a package manager to install things.

I would recommend that you uninstall everything related to Haskell, Msys and GHC, and once you have a clean system, use GHCup to install Stack. It would be best to avoid Stack, though.

If I install GHCup, msys (using ghcup) and Stack, and I then use stack repl --package entropy, it installs the package successfully:

image

As you can see, I also get these errors, but they don't abort installation. What made your installation abort was related to the calling convention, which is probably related to the GHC version. Be aware that Windows support in GHC was pretty broken before GHC 9.4.1, as you can see here: https://www.haskell.org/ghc/blog/20220807-ghc-9.4.1-released.html

Anyway, I do manage to get the package running on GHC 9.0.2, which is the version that Stack uses by default. But I'd recommend moving to GHC 9.4.1.

If you get the repl running, you can test that the library works by using e.g.

ghci> :m +System.Entropy
ghci> getEntropy 8
"l|\154>\142\192\164I"
ych817 commented 2 years ago

Oh It's been long time since I post this issue ... My old computer is broken and I'm now using WSL2 on my new computer as my coding platform , and it works very well . Still appreciate your reply , which provides a huge amount of detail . Thank you .