Skip to content

Commit 1651b43

Browse files
MrScriptXDan Liebaultjiacai2050Copilot
authored
fix illegal instructions on Windows (#43)
Close #28 It was a curl bug that was fixed in later version. I updated curl to the latest version as of now (8.18.0) --------- Co-authored-by: Dan Liebault <d.liebault@systancia.com> Co-authored-by: jiacai2050 <dev@liujiacai.net> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 357de59 commit 1651b43

6 files changed

Lines changed: 87 additions & 39 deletions

File tree

.github/workflows/CI.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
os: [ubuntu-latest, macos-latest]
23+
os: [ubuntu-latest, macos-latest, windows-latest]
2424
steps:
2525
- uses: actions/checkout@v4
2626
- uses: mlugg/setup-zig@v2
27+
- name: Run lint
28+
if: matrix.os == 'ubuntu-latest'
29+
run: |
30+
make lint
2731
- name: Run tests
2832
run: |
2933
make test run

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ run:
1414
zig build run-multi -freference-trace $(ARGS)
1515
zig build run-header -freference-trace $(ARGS)
1616

17+
fix:
18+
zig fmt .
19+
1720
lint:
1821
zig fmt --check .
1922

20-
test: lint
23+
test:
2124
zig build test $(ARGS)
2225

2326
docs:
@@ -30,4 +33,4 @@ clean:
3033
serve:
3134
cd server && go run main.go
3235

33-
.PHONY: run lint test docs clean serve
36+
.PHONY: run fix lint test docs clean serve

README.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Zig bindings for [[https://curl.haxx.se/libcurl/][libcurl]], a free and easy-to-
1515
The vendored libraries consist of:
1616
| Library | Version |
1717
|---------+---------|
18-
| libcurl | [[https://github.com/curl/curl/tree/curl-8_8_0][8.8.0]] |
18+
| libcurl | [[https://github.com/curl/curl/tree/curl-8_18_0][8.18.0]] |
1919
| zlib | [[https://github.com/madler/zlib/tree/v1.3.1][1.3.1]] |
2020
| mbedtls | [[https://github.com/Mbed-TLS/mbedtls/tree/v3.6.0][3.6.0]] |
2121

build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"LICENSE",
1212
},
1313
.dependencies = .{
14+
// https://github.com/curl/curl/releases/tag/curl-8_18_0
1415
.curl = .{
15-
// https://github.com/curl/curl/releases/tag/curl-8_8_0
16-
.url = "https://github.com/curl/curl/releases/download/curl-8_8_0/curl-8.8.0.tar.gz",
17-
.hash = "N-V-__8AAHipPQF9UuLPiaV1CtJzZIxvTN61tMGdFx8LGjIV",
16+
.url = "https://github.com/curl/curl/releases/download/curl-8_18_0/curl-8.18.0.tar.gz",
17+
.hash = "N-V-__8AALp9QAGn6CCHZ6fK_FfMyGtG824LSHYHHasM3w-y",
1818
.lazy = true,
1919
},
2020
// https://github.com/madler/zlib/releases/tag/v1.3.1

libs/curl.zig

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,56 @@ pub fn create(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bui
200200
lib.root_module.addCMacro("USE_THREADS_POSIX", "1");
201201
lib.root_module.addCMacro("USE_UNIX_SOCKETS", "1");
202202
lib.root_module.addCMacro("_FILE_OFFSET_BITS", "64");
203+
204+
const system_name = getCurlOS(target) orelse blk: {
205+
const arch = @tagName(target.result.cpu.arch);
206+
const os = @tagName(target.result.os.tag);
207+
break :blk std.fmt.allocPrint(b.allocator, "{s}-pc-{s}", .{ arch, os }) catch unreachable;
208+
};
209+
const curl_os = std.fmt.allocPrint(b.allocator, "\"{s}\"", .{system_name}) catch unreachable;
210+
lib.root_module.addCMacro("CURL_OS", curl_os);
211+
203212
return lib;
204213
}
205214

215+
// define CURL_OS based on target platform
216+
// current unsupported platform : Itanium, RiscOS, OS/400
217+
fn getCurlOS(target: std.Build.ResolvedTarget) ?[]const u8 {
218+
switch (target.result.os.tag) {
219+
.windows => {
220+
switch (target.result.cpu.arch) {
221+
.x86 => return "i386-pc-win32",
222+
.x86_64 => return "x86_64-pc-win32",
223+
.thumb => return "thumbv7a-pc-win32",
224+
.aarch64 => return "aarch64-pc-win32",
225+
else => return "unknown-pc-win32",
226+
}
227+
},
228+
.linux => {
229+
switch (target.result.cpu.arch) {
230+
.x86_64 => return "x86_64-pc-linux-gnu",
231+
.aarch64 => return "aarch64-pc-linux-gnu",
232+
else => return "Linux",
233+
}
234+
},
235+
.macos => return "mac",
236+
.freebsd => return "freebsd",
237+
else => {
238+
return null;
239+
},
240+
}
241+
}
242+
206243
const srcs = &.{
244+
"lib/cw-pause.c",
245+
"lib/curlx/winapi.c",
246+
"lib/curlx/strerr.c",
207247
"lib/cookie.c",
208248
"lib/http_chunks.c",
209249
"lib/escape.c",
210-
"lib/version_win32.c",
250+
"lib/curlx/version_win32.c",
211251
"lib/url.c",
212-
"lib/base64.c",
252+
"lib/curlx/base64.c",
213253
"lib/mqtt.c",
214254
"lib/setopt.c",
215255
"lib/telnet.c",
@@ -229,57 +269,63 @@ const srcs = &.{
229269
"lib/bufref.c",
230270
"lib/slist.c",
231271
"lib/curl_trc.c",
272+
"lib/ratelimit.c",
273+
"lib/strequal.c",
232274
"lib/vtls/rustls.c",
233275
"lib/vtls/mbedtls.c",
234276
"lib/vtls/wolfssl.c",
235277
"lib/vtls/schannel.c",
236278
"lib/vtls/gtls.c",
237-
"lib/vtls/sectransp.c",
238279
"lib/vtls/vtls.c",
239-
"lib/vtls/mbedtls_threadlock.c",
240280
"lib/vtls/schannel_verify.c",
241281
"lib/vtls/hostcheck.c",
242-
"lib/vtls/bearssl.c",
243282
"lib/vtls/openssl.c",
244283
"lib/vtls/x509asn1.c",
245284
"lib/vtls/keylog.c",
285+
"lib/vtls/vtls_scache.c",
286+
"lib/cshutdn.c",
287+
"lib/multi_ev.c",
288+
"lib/curlx/wait.c",
289+
"lib/uint-spbset.c",
290+
"lib/uint-bset.c",
246291
"lib/file.c",
247292
"lib/socks_gssapi.c",
248293
"lib/select.c",
249294
"lib/socketpair.c",
250295
"lib/curl_memrchr.c",
251296
"lib/cfilters.c",
252-
"lib/strtok.c",
297+
"lib/cf-ip-happy.c",
298+
"lib/multi_ntfy.c",
299+
"lib/uint-table.c",
300+
"lib/curlx/strparse.c",
253301
"lib/version.c",
254-
"lib/fopen.c",
302+
"lib/curlx/fopen.c",
303+
"lib/curl_fopen.c",
255304
"lib/http_aws_sigv4.c",
256305
"lib/mprintf.c",
257-
"lib/curl_path.c",
258306
"lib/parsedate.c",
259-
"lib/rename.c",
260307
"lib/ftplistparser.c",
261308
"lib/content_encoding.c",
262309
"lib/mime.c",
263310
"lib/rand.c",
264-
"lib/curl_des.c",
265311
"lib/curl_ntlm_core.c",
266312
"lib/pop3.c",
267313
"lib/curl_sspi.c",
268314
"lib/smb.c",
269315
"lib/conncache.c",
270-
"lib/inet_pton.c",
316+
"lib/curlx/inet_pton.c",
271317
"lib/if2ip.c",
272318
"lib/openldap.c",
273319
"lib/http_digest.c",
274320
"lib/cf-h1-proxy.c",
275-
"lib/asyn-thread.c",
321+
"lib/asyn-ares.c",
322+
"lib/asyn-thrdd.c",
276323
"lib/strerror.c",
277324
"lib/ftp.c",
278325
"lib/strdup.c",
326+
"lib/curlx/strcopy.c",
279327
"lib/memdebug.c",
280-
"lib/speedcheck.c",
281328
"lib/vquic/curl_ngtcp2.c",
282-
"lib/vquic/curl_msh3.c",
283329
"lib/vquic/vquic.c",
284330
"lib/vquic/curl_quiche.c",
285331
"lib/getinfo.c",
@@ -303,41 +349,37 @@ const srcs = &.{
303349
"lib/hostip4.c",
304350
"lib/curl_rtmp.c",
305351
"lib/amigaos.c",
306-
"lib/share.c",
307-
"lib/warnless.c",
308-
"lib/hostsyn.c",
352+
"lib/curl_share.c",
353+
"lib/curlx/warnless.c",
309354
"lib/md5.c",
310-
"lib/strtoofft.c",
311355
"lib/altsvc.c",
312356
"lib/formdata.c",
313-
"lib/dynbuf.c",
357+
"lib/curlx/dynbuf.c",
314358
"lib/curl_addrinfo.c",
315-
"lib/hostasyn.c",
316359
"lib/doh.c",
317360
"lib/request.c",
318361
"lib/cw-out.c",
319362
"lib/curl_sha512_256.c",
320363
"lib/vtls/cipher_suite.c",
321364
"lib/easygetopt.c",
322365
"lib/ldap.c",
323-
"lib/nonblock.c",
366+
"lib/curlx/nonblock.c",
324367
"lib/idn.c",
325368
"lib/pingpong.c",
326369
"lib/imap.c",
327370
"lib/vssh/libssh.c",
328-
"lib/vssh/wolfssh.c",
329371
"lib/vssh/libssh2.c",
372+
"lib/vssh/vssh.c",
330373
"lib/splay.c",
331-
"lib/krb5.c",
332374
"lib/progress.c",
333375
"lib/cf-haproxy.c",
334376
"lib/easyoptions.c",
335377
"lib/curl_range.c",
336378
"lib/curl_endian.c",
337379
"lib/http_proxy.c",
338-
"lib/inet_ntop.c",
339-
"lib/timeval.c",
340-
"lib/asyn-ares.c",
380+
"lib/curlx/inet_ntop.c",
381+
"lib/curlx/timeval.c",
382+
"lib/asyn-base.c",
341383
"lib/rtsp.c",
342384
"lib/sha256.c",
343385
"lib/curl_threads.c",
@@ -355,19 +397,18 @@ const srcs = &.{
355397
"lib/psl.c",
356398
"lib/ws.c",
357399
"lib/hostip6.c",
358-
"lib/curl_multibyte.c",
400+
"lib/curlx/multibyte.c",
359401
"lib/netrc.c",
360402
"lib/llist.c",
361403
"lib/urlapi.c",
362404
"lib/strcase.c",
363405
"lib/sendf.c",
364-
"lib/timediff.c",
406+
"lib/curlx/timediff.c",
365407
"lib/http.c",
366408
"lib/cf-h2-proxy.c",
367409
"lib/socks.c",
368410
"lib/http_negotiate.c",
369411
"lib/transfer.c",
370-
"lib/c-hyper.c",
371412
"lib/hmac.c",
372413
"lib/fileinfo.c",
373414
};

src/MultiPart.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ pub const NonCopyingData = struct {
7777
return to_read;
7878
}
7979

80-
pub fn seek(user_data: ?*anyopaque, offset: c_long, origin: c_int) callconv(.c) c_int {
81-
var source: *DataWithOffset = @ptrCast(@alignCast(user_data orelse return c.CURL_READFUNC_ABORT));
80+
pub fn seek(user_data: ?*anyopaque, offset: c.curl_off_t, origin: c_int) callconv(.c) c_int {
81+
var source: *DataWithOffset = @ptrCast(@alignCast(user_data orelse return c.CURL_SEEKFUNC_FAIL));
8282
const new_pos = switch (origin) {
8383
c.SEEK_SET => offset,
84-
c.SEEK_CUR => offset + @as(c_long, @intCast(source.offset)),
84+
c.SEEK_CUR => offset + @as(c.curl_off_t, @intCast(source.offset)),
8585
else => return c.CURL_SEEKFUNC_FAIL,
8686
};
8787
if (new_pos < 0) {

0 commit comments

Comments
 (0)