Skip to content

Commit

Permalink
vendor libs
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Jan 21, 2024
1 parent 23534e7 commit 2ee9754
Show file tree
Hide file tree
Showing 9 changed files with 569 additions and 20 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ docgen_tmp/
Vagrantfile
zig-linux*
docs
libroot*
libroot*
.DS_Store

libs/*
!libs/download.sh
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

prepare:
./libs/download.sh

run:
zig build run-basic -freference-trace
zig build run-advanced -freference-trace
Expand Down
10 changes: 6 additions & 4 deletions README.org
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
29 changes: 20 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}));
Expand Down
8 changes: 2 additions & 6 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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 = .{},
}
Loading

0 comments on commit 2ee9754

Please sign in to comment.