diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d782cab..4003515 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -20,10 +20,14 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v4 - uses: mlugg/setup-zig@v2 + - name: Run lint + if: matrix.os == 'ubuntu-latest' + run: | + make lint - name: Run tests run: | make test run diff --git a/Makefile b/Makefile index d9c34ff..561de7a 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,13 @@ run: zig build run-multi -freference-trace $(ARGS) zig build run-header -freference-trace $(ARGS) +fix: + zig fmt . + lint: zig fmt --check . -test: lint +test: zig build test $(ARGS) docs: @@ -30,4 +33,4 @@ clean: serve: cd server && go run main.go -.PHONY: run lint test docs clean serve +.PHONY: run fix lint test docs clean serve diff --git a/README.org b/README.org index 17c8fb5..bff0136 100644 --- a/README.org +++ b/README.org @@ -15,7 +15,7 @@ Zig bindings for [[https://curl.haxx.se/libcurl/][libcurl]], a free and easy-to- The vendored libraries consist of: | Library | Version | |---------+---------| -| libcurl | [[https://github.com/curl/curl/tree/curl-8_8_0][8.8.0]] | +| libcurl | [[https://github.com/curl/curl/tree/curl-8_18_0][8.18.0]] | | zlib | [[https://github.com/madler/zlib/tree/v1.3.1][1.3.1]] | | mbedtls | [[https://github.com/Mbed-TLS/mbedtls/tree/v3.6.0][3.6.0]] | diff --git a/build.zig.zon b/build.zig.zon index cefb69b..3adae2e 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -11,10 +11,10 @@ "LICENSE", }, .dependencies = .{ + // https://github.com/curl/curl/releases/tag/curl-8_18_0 .curl = .{ - // https://github.com/curl/curl/releases/tag/curl-8_8_0 - .url = "https://github.com/curl/curl/releases/download/curl-8_8_0/curl-8.8.0.tar.gz", - .hash = "N-V-__8AAHipPQF9UuLPiaV1CtJzZIxvTN61tMGdFx8LGjIV", + .url = "https://github.com/curl/curl/releases/download/curl-8_18_0/curl-8.18.0.tar.gz", + .hash = "N-V-__8AALp9QAGn6CCHZ6fK_FfMyGtG824LSHYHHasM3w-y", .lazy = true, }, // https://github.com/madler/zlib/releases/tag/v1.3.1 diff --git a/libs/curl.zig b/libs/curl.zig index 01b0d4a..8d29b51 100644 --- a/libs/curl.zig +++ b/libs/curl.zig @@ -200,16 +200,56 @@ pub fn create(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bui lib.root_module.addCMacro("USE_THREADS_POSIX", "1"); lib.root_module.addCMacro("USE_UNIX_SOCKETS", "1"); lib.root_module.addCMacro("_FILE_OFFSET_BITS", "64"); + + const system_name = getCurlOS(target) orelse blk: { + const arch = @tagName(target.result.cpu.arch); + const os = @tagName(target.result.os.tag); + break :blk std.fmt.allocPrint(b.allocator, "{s}-pc-{s}", .{ arch, os }) catch unreachable; + }; + const curl_os = std.fmt.allocPrint(b.allocator, "\"{s}\"", .{system_name}) catch unreachable; + lib.root_module.addCMacro("CURL_OS", curl_os); + return lib; } +// define CURL_OS based on target platform +// current unsupported platform : Itanium, RiscOS, OS/400 +fn getCurlOS(target: std.Build.ResolvedTarget) ?[]const u8 { + switch (target.result.os.tag) { + .windows => { + switch (target.result.cpu.arch) { + .x86 => return "i386-pc-win32", + .x86_64 => return "x86_64-pc-win32", + .thumb => return "thumbv7a-pc-win32", + .aarch64 => return "aarch64-pc-win32", + else => return "unknown-pc-win32", + } + }, + .linux => { + switch (target.result.cpu.arch) { + .x86_64 => return "x86_64-pc-linux-gnu", + .aarch64 => return "aarch64-pc-linux-gnu", + else => return "Linux", + } + }, + .macos => return "mac", + .freebsd => return "freebsd", + else => { + return null; + }, + } +} + const srcs = &.{ + "lib/cw-pause.c", + "lib/curlx/winapi.c", + "lib/curlx/strerr.c", "lib/cookie.c", "lib/http_chunks.c", "lib/escape.c", - "lib/version_win32.c", + "lib/curlx/version_win32.c", "lib/url.c", - "lib/base64.c", + "lib/curlx/base64.c", "lib/mqtt.c", "lib/setopt.c", "lib/telnet.c", @@ -229,57 +269,63 @@ const srcs = &.{ "lib/bufref.c", "lib/slist.c", "lib/curl_trc.c", + "lib/ratelimit.c", + "lib/strequal.c", "lib/vtls/rustls.c", "lib/vtls/mbedtls.c", "lib/vtls/wolfssl.c", "lib/vtls/schannel.c", "lib/vtls/gtls.c", - "lib/vtls/sectransp.c", "lib/vtls/vtls.c", - "lib/vtls/mbedtls_threadlock.c", "lib/vtls/schannel_verify.c", "lib/vtls/hostcheck.c", - "lib/vtls/bearssl.c", "lib/vtls/openssl.c", "lib/vtls/x509asn1.c", "lib/vtls/keylog.c", + "lib/vtls/vtls_scache.c", + "lib/cshutdn.c", + "lib/multi_ev.c", + "lib/curlx/wait.c", + "lib/uint-spbset.c", + "lib/uint-bset.c", "lib/file.c", "lib/socks_gssapi.c", "lib/select.c", "lib/socketpair.c", "lib/curl_memrchr.c", "lib/cfilters.c", - "lib/strtok.c", + "lib/cf-ip-happy.c", + "lib/multi_ntfy.c", + "lib/uint-table.c", + "lib/curlx/strparse.c", "lib/version.c", - "lib/fopen.c", + "lib/curlx/fopen.c", + "lib/curl_fopen.c", "lib/http_aws_sigv4.c", "lib/mprintf.c", - "lib/curl_path.c", "lib/parsedate.c", - "lib/rename.c", "lib/ftplistparser.c", "lib/content_encoding.c", "lib/mime.c", "lib/rand.c", - "lib/curl_des.c", "lib/curl_ntlm_core.c", "lib/pop3.c", "lib/curl_sspi.c", "lib/smb.c", "lib/conncache.c", - "lib/inet_pton.c", + "lib/curlx/inet_pton.c", "lib/if2ip.c", "lib/openldap.c", "lib/http_digest.c", "lib/cf-h1-proxy.c", - "lib/asyn-thread.c", + "lib/asyn-ares.c", + "lib/asyn-thrdd.c", "lib/strerror.c", "lib/ftp.c", "lib/strdup.c", + "lib/curlx/strcopy.c", "lib/memdebug.c", - "lib/speedcheck.c", "lib/vquic/curl_ngtcp2.c", - "lib/vquic/curl_msh3.c", "lib/vquic/vquic.c", "lib/vquic/curl_quiche.c", "lib/getinfo.c", @@ -303,16 +349,13 @@ const srcs = &.{ "lib/hostip4.c", "lib/curl_rtmp.c", "lib/amigaos.c", - "lib/share.c", - "lib/warnless.c", - "lib/hostsyn.c", + "lib/curl_share.c", + "lib/curlx/warnless.c", "lib/md5.c", - "lib/strtoofft.c", "lib/altsvc.c", "lib/formdata.c", - "lib/dynbuf.c", + "lib/curlx/dynbuf.c", "lib/curl_addrinfo.c", - "lib/hostasyn.c", "lib/doh.c", "lib/request.c", "lib/cw-out.c", @@ -320,24 +363,23 @@ const srcs = &.{ "lib/vtls/cipher_suite.c", "lib/easygetopt.c", "lib/ldap.c", - "lib/nonblock.c", + "lib/curlx/nonblock.c", "lib/idn.c", "lib/pingpong.c", "lib/imap.c", "lib/vssh/libssh.c", - "lib/vssh/wolfssh.c", "lib/vssh/libssh2.c", + "lib/vssh/vssh.c", "lib/splay.c", - "lib/krb5.c", "lib/progress.c", "lib/cf-haproxy.c", "lib/easyoptions.c", "lib/curl_range.c", "lib/curl_endian.c", "lib/http_proxy.c", - "lib/inet_ntop.c", - "lib/timeval.c", - "lib/asyn-ares.c", + "lib/curlx/inet_ntop.c", + "lib/curlx/timeval.c", + "lib/asyn-base.c", "lib/rtsp.c", "lib/sha256.c", "lib/curl_threads.c", @@ -355,19 +397,18 @@ const srcs = &.{ "lib/psl.c", "lib/ws.c", "lib/hostip6.c", - "lib/curl_multibyte.c", + "lib/curlx/multibyte.c", "lib/netrc.c", "lib/llist.c", "lib/urlapi.c", "lib/strcase.c", "lib/sendf.c", - "lib/timediff.c", + "lib/curlx/timediff.c", "lib/http.c", "lib/cf-h2-proxy.c", "lib/socks.c", "lib/http_negotiate.c", "lib/transfer.c", - "lib/c-hyper.c", "lib/hmac.c", "lib/fileinfo.c", }; diff --git a/src/MultiPart.zig b/src/MultiPart.zig index 92b66be..64b6d39 100644 --- a/src/MultiPart.zig +++ b/src/MultiPart.zig @@ -77,11 +77,11 @@ pub const NonCopyingData = struct { return to_read; } - pub fn seek(user_data: ?*anyopaque, offset: c_long, origin: c_int) callconv(.c) c_int { - var source: *DataWithOffset = @ptrCast(@alignCast(user_data orelse return c.CURL_READFUNC_ABORT)); + pub fn seek(user_data: ?*anyopaque, offset: c.curl_off_t, origin: c_int) callconv(.c) c_int { + var source: *DataWithOffset = @ptrCast(@alignCast(user_data orelse return c.CURL_SEEKFUNC_FAIL)); const new_pos = switch (origin) { c.SEEK_SET => offset, - c.SEEK_CUR => offset + @as(c_long, @intCast(source.offset)), + c.SEEK_CUR => offset + @as(c.curl_off_t, @intCast(source.offset)), else => return c.CURL_SEEKFUNC_FAIL, }; if (new_pos < 0) {