4 ms·
Looks like its still lacking in network support: https://github.com/ziglang/zig/issues/2007 https://github.com/ziglang/zig/issues/2007 I wonder though, does i
by svnpenn 7y ago
Looks like its still lacking in network support:
https://github.com/ziglang/zig/issues/2007 https://github.com/ziglang/zig/issues/2007
I wonder though, does it already have socket support? that could be a stopgap for me. Edit, looks like it doesnt have sockets either:
https://github.com/ziglang/zig/issues/1271 https://github.com/ziglang/zig/issues/1271
Edit 2, looks like it does:
https://github.com/ziglang/zig/blob/5026db1d/lib/std/net.zig#L219-L247 https://github.com/ziglang/zig/blob/5026db1d/lib/std/net.zig...
https://github.com/ziglang/zig/blob/5026db1d/lib/std/os.zig#L1724-L1748 https://github.com/ziglang/zig/blob/5026db1d/lib/std/os.zig#...
- rhodysurf 7y agoYou can use any c libraries networking or socket implementations in zig but I think thats as far as it goes at the moment.
- donpdonp 7y agozig's C-interoperability is second to none and using libcurl works great for networking. example: https://github.com/donpdonp/zootdeck/blob/master/src/net.zig https://github.com/donpdonp/zootdeck/blob/master/src/net.zig
- svnpenn 7y agoCan you though? I cant get cURL to work: https://github.com/ziglang/zig/issues/988 https://github.com/ziglang/zig/issues/988
- yellowapple 7y agoAfter a few minutes of trial and error (mostly around convincing Zig's type checker that various things are indeed enum members, and fixing cases where the C version outright ignores return values), I was able to produce a working example: // curl-test.zig // Direct hand-translation from curl's simple.c example usingnamespace @cImport({ @cInclude("stdio.h"); @cInclude("curl/curl.h"); }); pub fn main() anyerror!void { var curl = curl_easy_init(); var res: CURLcode = undefined; if(curl != null) { _ = curl_easy_setopt(curl, CURLoption.CURLOPT_URL, c"https://example.com"); _ = curl_easy_setopt(curl, CURLoption.CURLOPT_FOLLOWLOCATION, c_long(1)); res = curl_easy_perform(curl); if(res != CURLcode.CURLE_OK) { _ = fprintf(stderr, c"curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } curl_easy_cleanup(curl); } } Buildable with "zig build-exe curl-test.zig --library c --library curl" (I have to add "-isystem /usr/include --library-path /usr/lib64" to the end of that on Slackware64 14.2; YMMV). Should produce a runnable "curl-test" (or "curl-test.exe") binary executable in the current dir.