Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
jiacai2050 marked this conversation as resolved.
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Comment on lines 20 to +23

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test target no longer depends on the lint target. While this might speed up local testing, it also means that tests could be run on code that doesn't adhere to the project's formatting standards. It's generally a good practice to ensure code is linted before running tests to maintain code quality and consistency. Consider re-adding lint as a dependency for the test target.

zig build test $(ARGS)

docs:
Expand All @@ -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
2 changes: 1 addition & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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]] |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The curl version 8.18.0 appears to be a typo as this version does not exist in the official curl repository, and the link is broken. Based on the file changes in libs/curl.zig, the intended version seems to be 8.9.0 or newer. Please update this to the correct version to avoid confusing users.

| libcurl | [[https://github.com/curl/curl/tree/curl-8_9_0][8.9.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]] |

Expand Down
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"LICENSE",
},
.dependencies = .{
// https://github.com/curl/curl/releases/tag/curl-8_18_0
.curl = .{

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update here directly

// 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",
Comment thread
MrScriptX marked this conversation as resolved.
Comment on lines +16 to +17

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The specified curl version 8.18.0 appears to be a typo, as this version does not exist. The download URL is broken, which will cause the build to fail. Based on the source file changes, the intended version is likely 8.9.0 or newer. Please correct the version, URL, and hash to point to a valid curl release.

For example, for version 8.9.0, the URL would be:
https://github.com/curl/curl/releases/download/curl-8_9_0/curl-8.9.0.tar.gz

You will need to update the hash accordingly.

.lazy = true,
},
// https://github.com/madler/zlib/releases/tag/v1.3.1
Expand Down
99 changes: 70 additions & 29 deletions libs/curl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Comment thread
MrScriptX marked this conversation as resolved.
.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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For unhandled Windows architectures, returning null would be more consistent and informative. This would trigger the fallback logic in the caller, which constructs a system name like {arch}-pc-windows, providing more detail than the generic "unknown-pc-win32".

                else => return null,

}
},
Comment thread
jiacai2050 marked this conversation as resolved.
.linux => {
switch (target.result.cpu.arch) {
.x86_64 => return "x86_64-pc-linux-gnu",
.aarch64 => return "aarch64-pc-linux-gnu",
else => return "Linux",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For unhandled Linux architectures, returning null would be more consistent and informative. This would trigger the fallback logic in the caller, which constructs a system name like {arch}-pc-linux, providing more detail than the generic "Linux".

                else => return null,

}
},
.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",
Expand All @@ -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",
Comment thread
MrScriptX marked this conversation as resolved.
"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",
Expand All @@ -303,41 +349,37 @@ 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",
"lib/curl_sha512_256.c",
"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",
Expand All @@ -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",
};
6 changes: 3 additions & 3 deletions src/MultiPart.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Comment on lines +80 to +81

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While changing offset's type to c.curl_off_t is correct, a related issue on line 84 could lead to bugs.

On line 84: c.SEEK_CUR => offset + @as(c_long, @intCast(source.offset))

The cast of source.offset (a usize) to c_long can cause truncation on platforms where usize is 64-bit and c_long is 32-bit (e.g., 64-bit Windows). This can lead to incorrect seek behavior for data larger than 4GB.

To prevent this, source.offset should be cast to c.curl_off_t to match the type of offset:

c.SEEK_CUR => offset + @as(c.curl_off_t, @intCast(source.offset)),

Since line 84 is not in the diff, I cannot provide a direct suggestion, but I strongly recommend applying this fix to prevent potential issues with large data slices.

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) {
Expand Down