From 2ee9754af7f56a6ce51934883299cc342b4bb4a7 Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Sun, 21 Jan 2024 13:02:15 +0800 Subject: [PATCH] vendor libs --- .gitignore | 6 +- Makefile | 3 + README.org | 10 +- build.zig | 29 ++-- build.zig.zon | 8 +- libcurl.zig | 352 +++++++++++++++++++++++++++++++++++++++++++++++ libs/download.sh | 18 +++ mbedtls.zig | 131 ++++++++++++++++++ zlib.zig | 32 +++++ 9 files changed, 569 insertions(+), 20 deletions(-) create mode 100644 libcurl.zig create mode 100755 libs/download.sh create mode 100644 mbedtls.zig create mode 100644 zlib.zig diff --git a/.gitignore b/.gitignore index 7dc019d..c242e16 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,8 @@ docgen_tmp/ Vagrantfile zig-linux* docs -libroot* \ No newline at end of file +libroot* +.DS_Store + +libs/* +!libs/download.sh diff --git a/Makefile b/Makefile index e88a733..68c6967 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ +prepare: + ./libs/download.sh + run: zig build run-basic -freference-trace zig build run-advanced -freference-trace diff --git a/README.org b/README.org index 8bb0c28..d0afd90 100644 --- a/README.org +++ b/README.org @@ -1,6 +1,6 @@ #+TITLE: zig-curl #+DATE: 2023-09-16T23:16:15+0800 -#+LASTMOD: 2023-12-23T11:51:43+0800 +#+LASTMOD: 2024-01-21T11:56:14+0800 #+OPTIONS: toc:nil num:nil #+STARTUP: content @@ -15,9 +15,11 @@ This package is in its early stage, although the core functionality works right #+end_quote The builtin libcurl consists of: -- curl 8.1.1 -- mbedtls 3.4.0 -- zlib 1.2.13 +| lib | commit | +|---------+--------| +| zlib | [[https://github.com/madler/zlib/tree/v1.3][1.3]] | +| mbedtls | [[https://github.com/Mbed-TLS/mbedtls/tree/v3.5.1][3.5.1]] | +| libcurl | [[https://github.com/curl/curl/tree/curl-8_5_0][8.5.0]] | * Usage #+begin_src zig diff --git a/build.zig b/build.zig index 11d4001..20c6c35 100644 --- a/build.zig +++ b/build.zig @@ -8,34 +8,45 @@ const MODULE_NAME = "curl"; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + + const libcurl = buildLibcurl(b, target, optimize); const module = b.addModule(MODULE_NAME, .{ .root_source_file = .{ .path = "src/root.zig" }, }); + module.linkLibrary(libcurl); - // FIXME: libcurl doesn't work with zig master yet. - // const libcurl = b.dependency("libcurl", .{ .target = target, .optimize = optimize }); - // b.installArtifact(libcurl.artifact("curl")); - - try addExample(b, "basic", module, target, optimize); - try addExample(b, "advanced", module, target, optimize); + try addExample(b, "basic", module, libcurl, target, optimize); + try addExample(b, "advanced", module, libcurl, target, optimize); const main_tests = b.addTest(.{ .root_source_file = .{ .path = "src/root.zig" }, .target = target, .optimize = optimize, }); + + main_tests.linkLibrary(libcurl); main_tests.linkLibC(); - main_tests.linkSystemLibrary("curl"); const run_main_tests = b.addRunArtifact(main_tests); const test_step = b.step("test", "Run library tests"); test_step.dependOn(&run_main_tests.step); } +fn buildLibcurl(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *Build.Step.Compile { + const tls = @import("mbedtls.zig").create(b, target, optimize); + const zlib = @import("zlib.zig").create(b, target, optimize); + const libcurl = @import("libcurl.zig").create(b, target, optimize); + libcurl.linkLibrary(tls); + libcurl.linkLibrary(zlib); + + return libcurl; +} + fn addExample( b: *std.Build, comptime name: []const u8, curl_module: *Module, + libcurl: *std.Build.Step.Compile, // libcurl: *Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, @@ -49,8 +60,8 @@ fn addExample( b.installArtifact(exe); exe.root_module.addImport(MODULE_NAME, curl_module); - // exe.linkLibrary(libcurl.artifact("curl")); - exe.linkSystemLibrary("curl"); + exe.linkLibrary(libcurl); + // exe.linkSystemLibrary("curl"); exe.linkLibC(); const run_step = b.step("run-" ++ name, std.fmt.comptimePrint("Run {s} example", .{name})); diff --git a/build.zig.zon b/build.zig.zon index 326fc83..af7d02c 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,14 +3,10 @@ .version = "0.1.0", .paths = .{ "src", + "libs", "build.zig", "build.zig.zon", "LICENSE", }, - .dependencies = .{ - // .libcurl = .{ - // .url = "https://github.com/star-tek-mb/zigcurl/archive/41379c8.tar.gz", - // .hash = "1220424bef91a3ffe97980b7a45062a2c1b26c3bbcefbda301419ad14c3641abcf57", - // }, - }, + .dependencies = .{}, } diff --git a/libcurl.zig b/libcurl.zig new file mode 100644 index 0000000..99ec96b --- /dev/null +++ b/libcurl.zig @@ -0,0 +1,352 @@ +const std = @import("std"); + +pub fn create(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile { + const lib = b.addStaticLibrary(.{ + .name = "curl", + .target = target, + .optimize = optimize, + }); + lib.addCSourceFiles(.{ .files = srcs }); + lib.addIncludePath(.{ .path = "libs/curl/lib" }); + lib.addIncludePath(.{ .path = "libs/curl/include" }); + lib.installHeadersDirectory("libs/curl/include/curl", "curl"); + lib.linkLibC(); + lib.defineCMacro("BUILDING_LIBCURL", null); + lib.defineCMacro("CURL_STATICLIB", "1"); + lib.defineCMacro("CURL_DISABLE_LDAP", "1"); + lib.defineCMacro("CURL_DISABLE_LDAPS", "1"); + lib.defineCMacro("USE_MBEDTLS", "1"); + lib.defineCMacro("CURL_DISABLE_DICT", "1"); + lib.defineCMacro("CURL_DISABLE_FILE", "1"); + lib.defineCMacro("CURL_DISABLE_FTP", "1"); + lib.defineCMacro("CURL_DISABLE_GOPHER", "1"); + lib.defineCMacro("CURL_DISABLE_IMAP", "1"); + lib.defineCMacro("CURL_DISABLE_MQTT", "1"); + lib.defineCMacro("CURL_DISABLE_POP3", "1"); + lib.defineCMacro("CURL_DISABLE_RTSP", "1"); + lib.defineCMacro("CURL_DISABLE_SMB", "1"); + lib.defineCMacro("CURL_DISABLE_SMTP", "1"); + lib.defineCMacro("CURL_DISABLE_TELNET", "1"); + lib.defineCMacro("CURL_DISABLE_TFTP", "1"); + lib.defineCMacro("HAVE_LIBZ", "1"); + lib.defineCMacro("HAVE_ZLIB_H", "1"); + if (target.result.os.tag == .windows) { + lib.linkSystemLibrary("bcrypt"); + return lib; + } + lib.defineCMacro("CURL_EXTERN_SYMBOL", "__attribute__ ((__visibility__ (\"default\"))"); + + const isDarwin = target.result.isDarwin(); + if (!isDarwin) + lib.defineCMacro("ENABLE_IPV6", "1"); + lib.defineCMacro("HAVE_ALARM", "1"); + lib.defineCMacro("HAVE_ALLOCA_H", "1"); + lib.defineCMacro("HAVE_ARPA_INET_H", "1"); + lib.defineCMacro("HAVE_ARPA_TFTP_H", "1"); + lib.defineCMacro("HAVE_ASSERT_H", "1"); + lib.defineCMacro("HAVE_BASENAME", "1"); + lib.defineCMacro("HAVE_BOOL_T", "1"); + lib.defineCMacro("HAVE_BUILTIN_AVAILABLE", "1"); + lib.defineCMacro("HAVE_CLOCK_GETTIME_MONOTONIC", "1"); + lib.defineCMacro("HAVE_DLFCN_H", "1"); + lib.defineCMacro("HAVE_ERRNO_H", "1"); + lib.defineCMacro("HAVE_FCNTL", "1"); + lib.defineCMacro("HAVE_FCNTL_H", "1"); + lib.defineCMacro("HAVE_FCNTL_O_NONBLOCK", "1"); + lib.defineCMacro("HAVE_FREEADDRINFO", "1"); + lib.defineCMacro("HAVE_FTRUNCATE", "1"); + lib.defineCMacro("HAVE_GETADDRINFO", "1"); + lib.defineCMacro("HAVE_GETEUID", "1"); + lib.defineCMacro("HAVE_GETPPID", "1"); + lib.defineCMacro("HAVE_GETHOSTBYNAME", "1"); + if (!isDarwin) + lib.defineCMacro("HAVE_GETHOSTBYNAME_R", "1"); + lib.defineCMacro("HAVE_GETHOSTBYNAME_R_6", "1"); + lib.defineCMacro("HAVE_GETHOSTNAME", "1"); + lib.defineCMacro("HAVE_GETPPID", "1"); + lib.defineCMacro("HAVE_GETPROTOBYNAME", "1"); + lib.defineCMacro("HAVE_GETPEERNAME", "1"); + lib.defineCMacro("HAVE_GETSOCKNAME", "1"); + lib.defineCMacro("HAVE_IF_NAMETOINDEX", "1"); + lib.defineCMacro("HAVE_GETPWUID", "1"); + lib.defineCMacro("HAVE_GETPWUID_R", "1"); + lib.defineCMacro("HAVE_GETRLIMIT", "1"); + lib.defineCMacro("HAVE_GETTIMEOFDAY", "1"); + lib.defineCMacro("HAVE_GMTIME_R", "1"); + lib.defineCMacro("HAVE_IFADDRS_H", "1"); + lib.defineCMacro("HAVE_INET_ADDR", "1"); + lib.defineCMacro("HAVE_INET_PTON", "1"); + lib.defineCMacro("HAVE_SA_FAMILY_T", "1"); + lib.defineCMacro("HAVE_INTTYPES_H", "1"); + lib.defineCMacro("HAVE_IOCTL", "1"); + lib.defineCMacro("HAVE_IOCTL_FIONBIO", "1"); + lib.defineCMacro("HAVE_IOCTL_SIOCGIFADDR", "1"); + lib.defineCMacro("HAVE_LDAP_URL_PARSE", "1"); + lib.defineCMacro("HAVE_LIBGEN_H", "1"); + lib.defineCMacro("HAVE_IDN2_H", "1"); + lib.defineCMacro("HAVE_LL", "1"); + lib.defineCMacro("HAVE_LOCALE_H", "1"); + lib.defineCMacro("HAVE_LOCALTIME_R", "1"); + lib.defineCMacro("HAVE_LONGLONG", "1"); + lib.defineCMacro("HAVE_MALLOC_H", "1"); + lib.defineCMacro("HAVE_MEMORY_H", "1"); + if (!isDarwin) + lib.defineCMacro("HAVE_MSG_NOSIGNAL", "1"); + lib.defineCMacro("HAVE_NETDB_H", "1"); + lib.defineCMacro("HAVE_NETINET_IN_H", "1"); + lib.defineCMacro("HAVE_NETINET_TCP_H", "1"); + + if (target.result.os.tag == .linux) + lib.defineCMacro("HAVE_LINUX_TCP_H", "1"); + lib.defineCMacro("HAVE_NET_IF_H", "1"); + lib.defineCMacro("HAVE_PIPE", "1"); + lib.defineCMacro("HAVE_POLL", "1"); + lib.defineCMacro("HAVE_POLL_FINE", "1"); + lib.defineCMacro("HAVE_POLL_H", "1"); + lib.defineCMacro("HAVE_POSIX_STRERROR_R", "1"); + lib.defineCMacro("HAVE_PTHREAD_H", "1"); + lib.defineCMacro("HAVE_PWD_H", "1"); + lib.defineCMacro("HAVE_RECV", "1"); + lib.defineCMacro("HAVE_SELECT", "1"); + lib.defineCMacro("HAVE_SEND", "1"); + lib.defineCMacro("HAVE_FSETXATTR", "1"); + lib.defineCMacro("HAVE_FSETXATTR_5", "1"); + lib.defineCMacro("HAVE_SETJMP_H", "1"); + lib.defineCMacro("HAVE_SETLOCALE", "1"); + lib.defineCMacro("HAVE_SETRLIMIT", "1"); + lib.defineCMacro("HAVE_SETSOCKOPT", "1"); + lib.defineCMacro("HAVE_SIGACTION", "1"); + lib.defineCMacro("HAVE_SIGINTERRUPT", "1"); + lib.defineCMacro("HAVE_SIGNAL", "1"); + lib.defineCMacro("HAVE_SIGNAL_H", "1"); + lib.defineCMacro("HAVE_SIGSETJMP", "1"); + lib.defineCMacro("HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID", "1"); + lib.defineCMacro("HAVE_SOCKET", "1"); + lib.defineCMacro("HAVE_STDBOOL_H", "1"); + lib.defineCMacro("HAVE_STDINT_H", "1"); + lib.defineCMacro("HAVE_STDIO_H", "1"); + lib.defineCMacro("HAVE_STDLIB_H", "1"); + lib.defineCMacro("HAVE_STRCASECMP", "1"); + lib.defineCMacro("HAVE_STRDUP", "1"); + lib.defineCMacro("HAVE_STRERROR_R", "1"); + lib.defineCMacro("HAVE_STRINGS_H", "1"); + lib.defineCMacro("HAVE_STRING_H", "1"); + lib.defineCMacro("HAVE_STRSTR", "1"); + lib.defineCMacro("HAVE_STRTOK_R", "1"); + lib.defineCMacro("HAVE_STRTOLL", "1"); + lib.defineCMacro("HAVE_STRUCT_SOCKADDR_STORAGE", "1"); + lib.defineCMacro("HAVE_STRUCT_TIMEVAL", "1"); + lib.defineCMacro("HAVE_SYS_IOCTL_H", "1"); + lib.defineCMacro("HAVE_SYS_PARAM_H", "1"); + lib.defineCMacro("HAVE_SYS_POLL_H", "1"); + lib.defineCMacro("HAVE_SYS_RESOURCE_H", "1"); + lib.defineCMacro("HAVE_SYS_SELECT_H", "1"); + lib.defineCMacro("HAVE_SYS_SOCKET_H", "1"); + lib.defineCMacro("HAVE_SYS_STAT_H", "1"); + lib.defineCMacro("HAVE_SYS_TIME_H", "1"); + lib.defineCMacro("HAVE_SYS_TYPES_H", "1"); + lib.defineCMacro("HAVE_SYS_UIO_H", "1"); + lib.defineCMacro("HAVE_SYS_UN_H", "1"); + lib.defineCMacro("HAVE_TERMIOS_H", "1"); + lib.defineCMacro("HAVE_TERMIO_H", "1"); + lib.defineCMacro("HAVE_TIME_H", "1"); + lib.defineCMacro("HAVE_UNAME", "1"); + lib.defineCMacro("HAVE_UNISTD_H", "1"); + lib.defineCMacro("HAVE_UTIME", "1"); + lib.defineCMacro("HAVE_UTIMES", "1"); + lib.defineCMacro("HAVE_UTIME_H", "1"); + lib.defineCMacro("HAVE_VARIADIC_MACROS_C99", "1"); + lib.defineCMacro("HAVE_VARIADIC_MACROS_GCC", "1"); + lib.defineCMacro("OS", "\"Linux\""); + lib.defineCMacro("RANDOM_FILE", "\"/dev/urandom\""); + lib.defineCMacro("RECV_TYPE_ARG1", "int"); + lib.defineCMacro("RECV_TYPE_ARG2", "void *"); + lib.defineCMacro("RECV_TYPE_ARG3", "size_t"); + lib.defineCMacro("RECV_TYPE_ARG4", "int"); + lib.defineCMacro("RECV_TYPE_RETV", "ssize_t"); + lib.defineCMacro("SEND_QUAL_ARG2", "const"); + lib.defineCMacro("SEND_TYPE_ARG1", "int"); + lib.defineCMacro("SEND_TYPE_ARG2", "void *"); + lib.defineCMacro("SEND_TYPE_ARG3", "size_t"); + lib.defineCMacro("SEND_TYPE_ARG4", "int"); + lib.defineCMacro("SEND_TYPE_RETV", "ssize_t"); + lib.defineCMacro("SIZEOF_INT", "4"); + lib.defineCMacro("SIZEOF_SHORT", "2"); + lib.defineCMacro("SIZEOF_LONG", "8"); + lib.defineCMacro("SIZEOF_OFF_T", "8"); + lib.defineCMacro("SIZEOF_CURL_OFF_T", "8"); + lib.defineCMacro("SIZEOF_SIZE_T", "8"); + lib.defineCMacro("SIZEOF_TIME_T", "8"); + lib.defineCMacro("STDC_HEADERS", "1"); + lib.defineCMacro("TIME_WITH_SYS_TIME", "1"); + lib.defineCMacro("USE_THREADS_POSIX", "1"); + lib.defineCMacro("USE_UNIX_SOCKETS", null); + lib.defineCMacro("_FILE_OFFSET_BITS", "64"); + return lib; +} + +const srcs = &.{ + "libs/curl/lib/cookie.c", + "libs/curl/lib/http_chunks.c", + "libs/curl/lib/escape.c", + "libs/curl/lib/version_win32.c", + "libs/curl/lib/url.c", + "libs/curl/lib/base64.c", + "libs/curl/lib/mqtt.c", + "libs/curl/lib/setopt.c", + "libs/curl/lib/telnet.c", + "libs/curl/lib/hostip.c", + "libs/curl/lib/curl_gethostname.c", + "libs/curl/lib/connect.c", + "libs/curl/lib/socks_sspi.c", + "libs/curl/lib/cf-socket.c", + "libs/curl/lib/curl_fnmatch.c", + "libs/curl/lib/curl_gssapi.c", + "libs/curl/lib/http1.c", + "libs/curl/lib/multi.c", + "libs/curl/lib/gopher.c", + "libs/curl/lib/noproxy.c", + "libs/curl/lib/curl_sasl.c", + "libs/curl/lib/dict.c", + "libs/curl/lib/bufref.c", + "libs/curl/lib/slist.c", + "libs/curl/lib/curl_trc.c", + "libs/curl/lib/vtls/rustls.c", + "libs/curl/lib/vtls/mbedtls.c", + "libs/curl/lib/vtls/wolfssl.c", + "libs/curl/lib/vtls/schannel.c", + "libs/curl/lib/vtls/gtls.c", + "libs/curl/lib/vtls/sectransp.c", + "libs/curl/lib/vtls/vtls.c", + "libs/curl/lib/vtls/mbedtls_threadlock.c", + "libs/curl/lib/vtls/schannel_verify.c", + "libs/curl/lib/vtls/hostcheck.c", + "libs/curl/lib/vtls/bearssl.c", + "libs/curl/lib/vtls/openssl.c", + "libs/curl/lib/vtls/x509asn1.c", + "libs/curl/lib/vtls/keylog.c", + "libs/curl/lib/file.c", + "libs/curl/lib/socks_gssapi.c", + "libs/curl/lib/select.c", + "libs/curl/lib/socketpair.c", + "libs/curl/lib/curl_memrchr.c", + "libs/curl/lib/cfilters.c", + "libs/curl/lib/strtok.c", + "libs/curl/lib/version.c", + "libs/curl/lib/fopen.c", + "libs/curl/lib/http_aws_sigv4.c", + "libs/curl/lib/mprintf.c", + "libs/curl/lib/curl_path.c", + "libs/curl/lib/parsedate.c", + "libs/curl/lib/rename.c", + "libs/curl/lib/ftplistparser.c", + "libs/curl/lib/content_encoding.c", + "libs/curl/lib/mime.c", + "libs/curl/lib/rand.c", + "libs/curl/lib/curl_des.c", + "libs/curl/lib/curl_ntlm_core.c", + "libs/curl/lib/pop3.c", + "libs/curl/lib/curl_sspi.c", + "libs/curl/lib/smb.c", + "libs/curl/lib/conncache.c", + "libs/curl/lib/inet_pton.c", + "libs/curl/lib/if2ip.c", + "libs/curl/lib/openldap.c", + "libs/curl/lib/http_digest.c", + "libs/curl/lib/cf-h1-proxy.c", + "libs/curl/lib/asyn-thread.c", + "libs/curl/lib/strerror.c", + "libs/curl/lib/ftp.c", + "libs/curl/lib/strdup.c", + "libs/curl/lib/memdebug.c", + "libs/curl/lib/speedcheck.c", + "libs/curl/lib/vquic/curl_ngtcp2.c", + "libs/curl/lib/vquic/curl_msh3.c", + "libs/curl/lib/vquic/vquic.c", + "libs/curl/lib/vquic/curl_quiche.c", + "libs/curl/lib/getinfo.c", + "libs/curl/lib/http2.c", + "libs/curl/lib/vauth/oauth2.c", + "libs/curl/lib/vauth/vauth.c", + "libs/curl/lib/vauth/digest_sspi.c", + "libs/curl/lib/vauth/digest.c", + "libs/curl/lib/vauth/cram.c", + "libs/curl/lib/vauth/cleartext.c", + "libs/curl/lib/vauth/krb5_sspi.c", + "libs/curl/lib/vauth/spnego_sspi.c", + "libs/curl/lib/vauth/ntlm_sspi.c", + "libs/curl/lib/vauth/spnego_gssapi.c", + "libs/curl/lib/vauth/ntlm.c", + "libs/curl/lib/vauth/krb5_gssapi.c", + "libs/curl/lib/vauth/gsasl.c", + "libs/curl/lib/md4.c", + "libs/curl/lib/bufq.c", + "libs/curl/lib/curl_get_line.c", + "libs/curl/lib/hostip4.c", + "libs/curl/lib/curl_rtmp.c", + "libs/curl/lib/amigaos.c", + "libs/curl/lib/share.c", + "libs/curl/lib/warnless.c", + "libs/curl/lib/hostsyn.c", + "libs/curl/lib/md5.c", + "libs/curl/lib/strtoofft.c", + "libs/curl/lib/altsvc.c", + "libs/curl/lib/formdata.c", + "libs/curl/lib/dynbuf.c", + "libs/curl/lib/curl_addrinfo.c", + "libs/curl/lib/hostasyn.c", + "libs/curl/lib/doh.c", + "libs/curl/lib/curl_ntlm_wb.c", + "libs/curl/lib/easygetopt.c", + "libs/curl/lib/ldap.c", + "libs/curl/lib/nonblock.c", + "libs/curl/lib/idn.c", + "libs/curl/lib/pingpong.c", + "libs/curl/lib/imap.c", + "libs/curl/lib/vssh/libssh.c", + "libs/curl/lib/vssh/wolfssh.c", + "libs/curl/lib/vssh/libssh2.c", + "libs/curl/lib/splay.c", + "libs/curl/lib/krb5.c", + "libs/curl/lib/progress.c", + "libs/curl/lib/cf-haproxy.c", + "libs/curl/lib/easyoptions.c", + "libs/curl/lib/curl_range.c", + "libs/curl/lib/curl_endian.c", + "libs/curl/lib/http_proxy.c", + "libs/curl/lib/inet_ntop.c", + "libs/curl/lib/timeval.c", + "libs/curl/lib/asyn-ares.c", + "libs/curl/lib/rtsp.c", + "libs/curl/lib/sha256.c", + "libs/curl/lib/curl_threads.c", + "libs/curl/lib/easy.c", + "libs/curl/lib/dynhds.c", + "libs/curl/lib/tftp.c", + "libs/curl/lib/hsts.c", + "libs/curl/lib/smtp.c", + "libs/curl/lib/hash.c", + "libs/curl/lib/cf-https-connect.c", + "libs/curl/lib/getenv.c", + "libs/curl/lib/headers.c", + "libs/curl/lib/system_win32.c", + "libs/curl/lib/http_ntlm.c", + "libs/curl/lib/psl.c", + "libs/curl/lib/ws.c", + "libs/curl/lib/hostip6.c", + "libs/curl/lib/curl_multibyte.c", + "libs/curl/lib/netrc.c", + "libs/curl/lib/llist.c", + "libs/curl/lib/urlapi.c", + "libs/curl/lib/strcase.c", + "libs/curl/lib/sendf.c", + "libs/curl/lib/timediff.c", + "libs/curl/lib/http.c", + "libs/curl/lib/cf-h2-proxy.c", + "libs/curl/lib/socks.c", + "libs/curl/lib/http_negotiate.c", + "libs/curl/lib/transfer.c", + "libs/curl/lib/c-hyper.c", + "libs/curl/lib/hmac.c", + "libs/curl/lib/fileinfo.c", +}; diff --git a/libs/download.sh b/libs/download.sh new file mode 100755 index 0000000..f9cb33b --- /dev/null +++ b/libs/download.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -x +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +TMP_DIR=/tmp/ + +cd ${TMP_DIR} || exit 1 +curl -o mbedtls.zip https://codeload.github.com/Mbed-TLS/mbedtls/zip/refs/tags/v3.5.1 +curl -o libcurl.zip https://codeload.github.com/curl/curl/zip/refs/tags/curl-8_5_0 +curl -o zlib.zip https://codeload.github.com/madler/zlib/zip/refs/tags/v1.3 + +unzip mbedtls.zip +unzip libcurl.zip +unzip zlib.zip + +mv curl-curl-8_5_0 "${SCRIPT_DIR}/libcurl" +mv mbedtls-3.5.1 "${SCRIPT_DIR}/mbedtls" +mv zlib-1.3 "${SCRIPT_DIR}/zlib" diff --git a/mbedtls.zig b/mbedtls.zig new file mode 100644 index 0000000..0854853 --- /dev/null +++ b/mbedtls.zig @@ -0,0 +1,131 @@ +const std = @import("std"); +const ResolvedTarget = std.Build.ResolvedTarget; + +pub fn create(b: *std.Build, target: ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile { + const lib = b.addStaticLibrary(.{ + .name = "mbedtls", + .root_source_file = null, + .target = target, + .optimize = optimize, + }); + + lib.addCSourceFiles(.{ .files = srcs, .flags = &.{"-std=c99"} }); + lib.addIncludePath(.{ .path = "libs/mbedtls/include" }); + lib.addIncludePath(.{ .path = "libs/mbedtls/library" }); + lib.linkLibC(); + lib.installHeadersDirectory("libs/mbedtls/include/mbedtls", "mbedtls"); + lib.installHeadersDirectory("libs/mbedtls/include/psa", "psa"); + + if (target.result.os.tag == .windows) { + lib.linkSystemLibrary("ws2_32"); + } + return lib; +} + +const srcs = &.{ + "libs/mbedtls/library/aes.c", + "libs/mbedtls/library/aesni.c", + "libs/mbedtls/library/aesce.c", + "libs/mbedtls/library/aria.c", + "libs/mbedtls/library/asn1parse.c", + "libs/mbedtls/library/asn1write.c", + "libs/mbedtls/library/base64.c", + "libs/mbedtls/library/bignum.c", + "libs/mbedtls/library/bignum_core.c", + "libs/mbedtls/library/bignum_mod.c", + "libs/mbedtls/library/bignum_mod_raw.c", + "libs/mbedtls/library/camellia.c", + "libs/mbedtls/library/ccm.c", + "libs/mbedtls/library/chacha20.c", + "libs/mbedtls/library/chachapoly.c", + "libs/mbedtls/library/cipher.c", + "libs/mbedtls/library/cipher_wrap.c", + "libs/mbedtls/library/constant_time.c", + "libs/mbedtls/library/cmac.c", + "libs/mbedtls/library/ctr_drbg.c", + "libs/mbedtls/library/des.c", + "libs/mbedtls/library/dhm.c", + "libs/mbedtls/library/ecdh.c", + "libs/mbedtls/library/ecdsa.c", + "libs/mbedtls/library/ecjpake.c", + "libs/mbedtls/library/ecp.c", + "libs/mbedtls/library/ecp_curves.c", + "libs/mbedtls/library/entropy.c", + "libs/mbedtls/library/entropy_poll.c", + "libs/mbedtls/library/error.c", + "libs/mbedtls/library/gcm.c", + // "libs/mbedtls/library/hash_info.c", + "libs/mbedtls/library/hkdf.c", + "libs/mbedtls/library/hmac_drbg.c", + "libs/mbedtls/library/lmots.c", + "libs/mbedtls/library/lms.c", + "libs/mbedtls/library/md.c", + "libs/mbedtls/library/md5.c", + "libs/mbedtls/library/memory_buffer_alloc.c", + "libs/mbedtls/library/nist_kw.c", + "libs/mbedtls/library/oid.c", + "libs/mbedtls/library/padlock.c", + "libs/mbedtls/library/pem.c", + "libs/mbedtls/library/pk.c", + "libs/mbedtls/library/pk_wrap.c", + "libs/mbedtls/library/pkcs12.c", + "libs/mbedtls/library/pkcs5.c", + "libs/mbedtls/library/pkparse.c", + "libs/mbedtls/library/pkwrite.c", + "libs/mbedtls/library/platform.c", + "libs/mbedtls/library/platform_util.c", + "libs/mbedtls/library/poly1305.c", + "libs/mbedtls/library/psa_crypto.c", + "libs/mbedtls/library/psa_crypto_aead.c", + "libs/mbedtls/library/psa_crypto_cipher.c", + "libs/mbedtls/library/psa_crypto_client.c", + "libs/mbedtls/library/psa_crypto_ffdh.c", + "libs/mbedtls/library/psa_crypto_driver_wrappers_no_static.c", + "libs/mbedtls/library/psa_crypto_ecp.c", + "libs/mbedtls/library/psa_crypto_hash.c", + "libs/mbedtls/library/psa_crypto_mac.c", + "libs/mbedtls/library/psa_crypto_pake.c", + "libs/mbedtls/library/psa_crypto_rsa.c", + "libs/mbedtls/library/psa_crypto_se.c", + "libs/mbedtls/library/psa_crypto_slot_management.c", + "libs/mbedtls/library/psa_crypto_storage.c", + "libs/mbedtls/library/psa_its_file.c", + "libs/mbedtls/library/psa_util.c", + "libs/mbedtls/library/ripemd160.c", + "libs/mbedtls/library/rsa.c", + "libs/mbedtls/library/rsa_alt_helpers.c", + "libs/mbedtls/library/sha1.c", + "libs/mbedtls/library/sha3.c", + "libs/mbedtls/library/sha256.c", + "libs/mbedtls/library/sha512.c", + "libs/mbedtls/library/threading.c", + "libs/mbedtls/library/timing.c", + "libs/mbedtls/library/version.c", + "libs/mbedtls/library/version_features.c", + "libs/mbedtls/library/pkcs7.c", + "libs/mbedtls/library/x509.c", + "libs/mbedtls/library/x509_create.c", + "libs/mbedtls/library/x509_crl.c", + "libs/mbedtls/library/x509_crt.c", + "libs/mbedtls/library/x509_csr.c", + "libs/mbedtls/library/x509write_crt.c", + "libs/mbedtls/library/x509write_csr.c", + "libs/mbedtls/library/debug.c", + "libs/mbedtls/library/mps_reader.c", + "libs/mbedtls/library/mps_trace.c", + "libs/mbedtls/library/net_sockets.c", + "libs/mbedtls/library/ssl_cache.c", + "libs/mbedtls/library/ssl_ciphersuites.c", + "libs/mbedtls/library/ssl_client.c", + "libs/mbedtls/library/ssl_cookie.c", + "libs/mbedtls/library/ssl_debug_helpers_generated.c", + "libs/mbedtls/library/ssl_msg.c", + "libs/mbedtls/library/ssl_ticket.c", + "libs/mbedtls/library/ssl_tls.c", + "libs/mbedtls/library/ssl_tls12_client.c", + "libs/mbedtls/library/ssl_tls12_server.c", + "libs/mbedtls/library/ssl_tls13_keys.c", + "libs/mbedtls/library/ssl_tls13_server.c", + "libs/mbedtls/library/ssl_tls13_client.c", + "libs/mbedtls/library/ssl_tls13_generic.c", +}; diff --git a/zlib.zig b/zlib.zig new file mode 100644 index 0000000..c5119a2 --- /dev/null +++ b/zlib.zig @@ -0,0 +1,32 @@ +const std = @import("std"); + +pub fn create(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile { + const lib = b.addStaticLibrary(.{ + .name = "z", + .target = target, + .optimize = optimize, + }); + lib.linkLibC(); + lib.addCSourceFiles(.{ .files = srcs, .flags = &.{"-std=c89"} }); + lib.installHeader("libs/zlib/zlib.h", "zlib.h"); + lib.installHeader("libs/zlib/zconf.h", "zconf.h"); + return lib; +} + +const srcs = &.{ + "libs/zlib/adler32.c", + "libs/zlib/compress.c", + "libs/zlib/crc32.c", + "libs/zlib/deflate.c", + "libs/zlib/gzclose.c", + "libs/zlib/gzlib.c", + "libs/zlib/gzread.c", + "libs/zlib/gzwrite.c", + "libs/zlib/inflate.c", + "libs/zlib/infback.c", + "libs/zlib/inftrees.c", + "libs/zlib/inffast.c", + "libs/zlib/trees.c", + "libs/zlib/uncompr.c", + "libs/zlib/zutil.c", +};