ghcjs / ghcjs

Haskell to JavaScript compiler, based on GHC
MIT License
2.6k stars 187 forks source link

network-2.6.0.2 not working #305

Open herbmaster opened 9 years ago

herbmaster commented 9 years ago

I tried to run a project and got an error that h$getprotobyname is not there:

$ cabal run
uncaught exception in Haskell main thread:
ReferenceError: h$getprotobyname is not defined
      at h$$bzB (.jsexe/all.js:159555:11)
      at Object.h$mainLoop (.jsexe/all.js:9527:25)
      at processImmediate [as _immediateCallback] (timers.js:354:15)

As getprotobyname is a system call, I assume, it is called via the FFI and the implementation is missing. As suggested, I create this ticket.

luite commented 9 years ago

Since browsers don't allow JavaScript programs to open sockets directly, only through WebSocket, much of the network package would only be usable on node.js. Adding support to the package has been a lower priority for this reason.

If you want to have a go at adding the required JS implementations I'd be happy to help out when you get stuck. I believe there are some blocking calls in foreign imports where node.js only has a nonblocking variant available. You'd probably want to use the ghcjs_HOST_OS macro to conditionally replace those calls with foreign import javascript.

herbmaster commented 9 years ago

Thanks for the explanation. It was my understanding that ghcjs is there to compile Haskell applications for usage with node.js. Obviously you had broader variety of operational scenarios in mind.

I am currently looking for ways to port my application to ARM-based platforms. As this is not officially supported by GHC, it looked for an alternative in case of strange compiler bugs which I would probably not be able to solve. So compiling it to a platform which is widely supported seemed like a good alternative, so I just wanted to try this out.

However, I have never written a single line of JavaScript and currently don't have the time to look into this. Thank for your support offer, and maybe I will come back to it in half a year or so. Godspeed to you and your project. It is a really intriguing idea.

cartazio commented 9 years ago

ARM 32bit IS supported by ghc arm 64 support is available for those riding on the bleeding edge, though @bgamari and @erikd can opine more on ARM support than I

bgamari commented 9 years ago

@herbmaster I suspect you'd be better off just using GHC's native LLVM backend. 7.10 should work quite well on ARM.

erikd commented 9 years ago

GHC from git HEAD (with LLVM 3.6) allows building of a cross compiler targeting Arm64 (also known as AArch64). The cross-comiled binaries run under the QEMU user space emulation, but I haven't gone as far as trying to build more than that because I don't have any Arm64 hardware to run it on.

For Am32 I agree completely with @bgamari. I have built GHC from source on Arm32 running Linux. Even on the quad CPU Arm board I have (Radxa) it takes 8-10 hours to compile.

agocorona commented 8 years ago

Luite:

I would like to try to implement the foreign import javascript calls. But first I want to know: It is possible to compile Network with GHCJS without modifications?

I have this error:

\GHC7D97.tmp: The program 'gcc' is required but it could not be found.

when compiling network.

but indeed I have gcc in the PATH variable and it executes well in the shell...

The error reported in the first message seems to imply that network has been compiled with ghcjs....

The foreign calls apparently are in Network/BSD.hsc

But there are four other modules that use FFI. I don´t know if it is feasible.

network depend on the unix package that probably will have many FFI calls, and it does not compile with ghcjs (In my box it reports that there is no gcc)

luite commented 8 years ago

I suspect this is a problem with the modified hsc2hs version that GHCJS ships. It should be possible to make it work, perhaps just something in the program needs to be updated. What platform are you building on?

For GHCJS it might be even better if you remove the dependency on the hsc file altogether (using source dirs dependent on the compiler), since having preprocessor conditionals in the result requires an awkward double hash syntax, for example:

https://github.com/ghcjs/ghcjs-boot/blob/78099888090b46136a52800719d77b4003cd8e68/patches/unix.patch#L58-L61

You'll probably want foreign import javascript interruptible to implement getHostByName and the like, since node.js does not have blocking variants, and therefore writing a JS implementation for the foreign import ccall convention is not possible.

agocorona commented 8 years ago

I use windows 10, ghc 7.10.2

I was thinking in making network working in the client side. since my user case is an applicantion that may run server or client side.

alios commented 8 years ago

Would it make sense / possible to implement WebSockets as a new Protocol Family (unsure on the term) which could be used with network?

Without beeing it the details I'd like the idea to:

.... and then implement routing on the server an have fun with running server/p2p services in the browser :smiling_imp:

agocorona commented 8 years ago

It is possible since as far as I know, and I´m thinking aloud, the server side handle the connection trough a socket. The protocol should handle the initial HTTP frames of the connection.

I think that websockets is fixed as a TCP connection, since it uses the same socket opened by HTTP which is a TCP socket.

The advantage of this is that programs can run server side or client side unmodified and this is great for cloud and web programming.

t1m0thyj commented 5 years ago

I'm really sad that GHCJS doesn't support the networking module, spent the past few hours figuring out how to set it up in Ubuntu so I could compile a Discord bot written in Haskell to run on my Raspberry Pi, but now I get the same error:

uncaught exception in Haskell thread: ReferenceError: h$getprotobyname is not defined

Although its been 3 years since this issue was active, I'm assuming the situation is still the same, that networking isn't really supported.