Git Product home page Git Product logo

zig-curl's Introduction

zig-curl

cURL binding for Zig

Usage

var allocator = std.heap.page_allocator;
var f = struct {
    fn f(data: []const u8) anyerror!usize {
        try std.io.getStdOut().writeAll(data);
        return data.len;
    }
}.f;
var res = try curl.get("https://google.com/", .{ .allocator = allocator, .cb = f });
if (res != 0) {
    var msg = try curl.strerrorAlloc(allocator, res);
    defer allocator.free(msg);
    std.log.warn("{s}", .{msg});
}

Requirements

  • libcurl

Installation

$ zig build

Link to zig-curl

add following function into your build.zig.

fn linkToCurl(step: *std.build.LibExeObjStep) void {
    var libs = if (builtin.os.tag == .windows) [_][]const u8{ "c", "curl", "bcrypt", "crypto", "crypt32", "ws2_32", "wldap32", "ssl", "psl", "iconv", "idn2", "unistring", "z", "zstd", "nghttp2", "ssh2", "brotlienc", "brotlidec", "brotlicommon" } else [_][]const u8{ "c", "curl" };
    for (libs) |i| {
        step.linkSystemLibrary(i);
    }
    if (builtin.os.tag == .linux) {
        step.linkSystemLibraryNeeded("libcurl");
    }
    if (builtin.os.tag == .windows) {
        step.include_dirs.append(.{ .raw_path = "c:/msys64/mingw64/include" }) catch unreachable;
        step.lib_paths.append("c:/msys64/mingw64/lib") catch unreachable;
    }
}

Then, call for the step.

const exe = b.addExecutable("zig-curl-example", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
pkgs.addAllTo(exe);
linkToCurl(exe); // DO THIS
exe.install();

License

MIT

Author

Yasuhiro Matsumoto (a.k.a. mattn)

zig-curl's People

Contributors

mattn avatar nitrogenez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.