vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.69k stars 2.15k forks source link

Compiling examples/pico/pico.v still fails on Windows #18291

Closed TimmieTudor closed 1 year ago

TimmieTudor commented 1 year ago

Describe the bug

I am trying to run the pico.v example from v/examples/pico/pico.v, but it doesn't work on Windows

Expected Behavior

I expected the pico.v file to compile and run correctly without any issues.

Current Behavior

When I try to run the pico.v example using: v run pico.v I get the following output: C:/Users/tudor/Documents/v_windows_1/v/thirdparty/picohttpparser/picohttpparser.c:19: warning: assignment from incompatible pointer type C:/Users/tudor/Documents/v_windows_1/v/thirdparty/picohttpparser/picohttpparser.c:19: warning: assignment from incompatible pointer type

In file included from C:/Users/tudor/Documents/v_windows_1/v/thirdparty/picoev/picoev.c:8: C:/Users/tudor/Documents/v_windows_1/v/thirdparty/picoev/src/picoev_select.c:75: warning: function might return no value: 'picoev_w32_init' C:/Users/tudor/Documents/v_windows_1/v/thirdparty/picoev/src/picoev.h:143: warning: cast between pointer and integer of different size C:/Users/tudor/Documents/v_windows_1/v/thirdparty/picoev/src/picoev.h:143: warning: cast between pointer and integer of different size

builder error: 'netinet/tcp.h' not found

Reproduction Steps

The code inside the v/examples/pico/pico.v file:

import json
import picoev
import picohttpparser

const (
    port = 8088
)

struct Message {
    message string
}

[inline]
fn json_response() string {
    msg := Message{
        message: 'Hello, World!'
    }
    return json.encode(msg)
}

[inline]
fn hello_response() string {
    return 'Hello, World!'
}

fn callback(data voidptr, req picohttpparser.Request, mut res picohttpparser.Response) {
    if picohttpparser.cmpn(req.method, 'GET ', 4) {
        if picohttpparser.cmp(req.path, '/t') {
            res.http_ok()
            res.header_server()
            res.header_date()
            res.plain()
            res.body(hello_response())
        } else if picohttpparser.cmp(req.path, '/j') {
            res.http_ok()
            res.header_server()
            res.header_date()
            res.json()
            res.body(json_response())
        } else {
            res.http_404()
        }
    } else {
        res.http_405()
    }
    res.end()
}

fn main() {
    println('Starting webserver on http://127.0.0.1:${port}/ ...')
    picoev.new(port: port, cb: &callback).serve()
}

Reproduction steps in Command Prompt: C:\Users\tudor\Documents\v_windows_1\v\examples\pico>v run pico.v

Possible Solution

The header file <netinet/tcp.h> is required by picoev, but it was not found. Perhaps you can add it in V's thirdparty folder? Or you can explain me where to get the header file from. That is the only possible solution I can think of at the moment.

Additional Information/Context

As I said, the header file <netinet/tcp.h> is not available on my machine.

V version

V 0.3.4 80d404c

Environment details (OS name and version, etc.)

V full version: V 0.3.4 e2f18fc.80d404c OS: windows, Microsoft Windows 10 Home v19045 64-bit Processor: 4 cpus, 64bit, little endian,

getwd: C:\Users\tudor\Documents\v_windows_1\v\examples\pico vexe: C:\Users\tudor\Documents\v_windows_1\v\v.exe vexe mtime: 2023-05-28 08:25:53

vroot: OK, value: C:\Users\tudor\Documents\v_windows_1\v VMODULES: OK, value: C:\Users\tudor.vmodules VTMP: OK, value: C:\Users\tudor\AppData\Local\Temp\v_0

Git version: git version 2.39.0.windows.1 Git vroot status: weekly.2023.15-207-g80d404c2 .git/config present: true

CC version: Error: exec failed (CreateProcess) with code 2: The system cannot find the file specified. cmd: cc --version thirdparty/tcc: N/A

medvednikov commented 1 year ago

pico.v is unlikely to ever support windows

this system is just not well fit for such low level networking optimizations (epoll, io_uring)

Casper64 commented 1 year ago

@medvednikov why not? There is an option for using select in pico, it is even included in the source code.

I managed to get it to compile on windows yesterday and integrate it successfully with vweb. I am getting a runtime access violation error on windows, but that is probably my fault.

Casper64 commented 1 year ago

It might not be as fast, but at least you could test it on windows and then deploy on linux.

medvednikov commented 1 year ago

@Casper64 then you did something I thought was impossible. I had no idea Windows supported select.

TimmieTudor commented 1 year ago

I have also seen a picoev_select.c file in the C code of picoev, which seems to support Windows.

paulie-g commented 1 year ago

@Casper64 then you did something I thought was impossible. I had no idea Windows supported select.

Winsock(now Winsock 2 - so good, they made it twice) does for BSD-like sockets. I don't recall what the two iterations of a POSIX subsystem for Windows did before they were nuked, presumably it was kludged somehow.