|
| 1 | +[](https://github.com/allyourcodebase/curl/actions) |
| 2 | + |
| 3 | +# curl |
| 4 | + |
| 5 | +This is [curl](https://github.com/curl/curl), packaged for [Zig](https://ziglang.org/). |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +> [!WARNING] |
| 10 | +> |
| 11 | +> Curl depends on https://github.com/allyourcodebase/openssl which currently doesn't work on macOS. Consider using a different openssl implementation. |
| 12 | +
|
| 13 | +### Standalone library (libcurl) and command-line tool (curl) |
| 14 | + |
| 15 | +```bash |
| 16 | +git clone https://github.com/allyourcodebase/curl |
| 17 | +cd curl |
| 18 | +zig build -Doptimize=ReleaseFast |
| 19 | +``` |
| 20 | + |
| 21 | +The library and CLI tool can be found in the newly created `./zig-out` directory. The `zig build run` build step may be used to directly run curl. |
| 22 | + |
| 23 | +#### Avoid system dependencies |
| 24 | + |
| 25 | +By default, curl requires some system dependencies that have not been ported to the zig build system yet. These dependencies may be either manually installed on the host system or disabled with the following build command: |
| 26 | + |
| 27 | +```bash |
| 28 | +# Windows |
| 29 | +zig build -Doptimize=ReleaseFast -Dlibpsl=false -Dlibssh2=false -Dlibidn2=false -Dnghttp2=false |
| 30 | +# Posix |
| 31 | +zig build -Doptimize=ReleaseFast -Dlibpsl=false -Dlibssh2=false -Dlibidn2=false -Dnghttp2=false -Ddisable-ldap |
| 32 | +``` |
| 33 | + |
| 34 | +### Zig Build System |
| 35 | + |
| 36 | +First, update your `build.zig.zon`: |
| 37 | + |
| 38 | +``` |
| 39 | +# Initialize a `zig build` project if you haven't already |
| 40 | +zig init |
| 41 | +zig fetch --save git+https://github.com/allyourcodebase/curl.git |
| 42 | +``` |
| 43 | + |
| 44 | +You can then import curl in your `build.zig` with: |
| 45 | + |
| 46 | +```zig |
| 47 | +const curl_dependency = b.dependency("curl", .{ |
| 48 | + .target = target, |
| 49 | + .optimize = optimize, |
| 50 | +}); |
| 51 | +
|
| 52 | +// A custom `artifact` function is provided because the build system |
| 53 | +// provides no way to differentiate between the library (libcurl) and |
| 54 | +// the command-line tool (curl) since they are both named "curl" in |
| 55 | +// the build system. |
| 56 | +// See https://github.com/ziglang/zig/issues/20377 |
| 57 | +const curlExe = @import("curl").artifact(curl_dependency, .exe); |
| 58 | +const libCurl = @import("curl").artifact(curl_dependency, .lib); |
| 59 | +
|
| 60 | +your_exe.root_module.linkLibrary(libCurl); |
| 61 | +``` |
| 62 | + |
| 63 | +#### Avoid system dependencies |
| 64 | + |
| 65 | +By default, curl requires some system dependencies that have not been ported to the zig build system yet. These dependencies may be either manually installed on the host system or disabled with the following change to the `build.zig`: |
| 66 | + |
| 67 | +```zig |
| 68 | +const curl_dependency = b.dependency("curl", .{ |
| 69 | + .target = target, |
| 70 | + .optimize = optimize, |
| 71 | + .libpsl = false, |
| 72 | + .libssh2 = false, |
| 73 | + .libidn2 = false, |
| 74 | + .nghttp2 = false, |
| 75 | + .disable-ldap = true, |
| 76 | +}); |
| 77 | +``` |
0 commit comments