Skip to content

Commit

Permalink
add vendor opt
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Jan 2, 2025
1 parent b370fa8 commit 6ef2907
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ for target in "${targets[@]}"; do
zig build -Doptimize=ReleaseSafe -p ${dst_dir} \
-Dgit_commit=${GIT_COMMIT} -Dbuild_date=${BUILD_DATE}
else
zig build -Dskip_zigfetch=true -Doptimize=ReleaseSafe -Dtarget="${target}" -p ${dst_dir} \
zig build -Dskip-zigfetch=true -Doptimize=ReleaseSafe -Dtarget="${target}" -p ${dst_dir} \
-Dgit_commit=${GIT_COMMIT} -Dbuild_date=${BUILD_DATE}
fi

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: |
zig fmt --check .
zig build test
zig build
zig build -Dvendor-libcurl
find zig-out
- name: zigfetch compare(unix)
if: matrix.os != 'windows-latest'
Expand All @@ -76,4 +76,4 @@ jobs:
sudo apt update && sudo apt-get install -y libcurl4-openssl-dev
- name: Build
run: |
zig build -Dtarget=${{ matrix.targets }} -Dskip_zigfetch=true
zig build -Dtarget=${{ matrix.targets }} -Dskip-zigfetch=true
1 change: 1 addition & 0 deletions .github/zigfetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
pkg=https://github.com/jiacai2050/zig-curl/archive/c8e2f43f8f042f52373c86043ec16b0f2c3388a2.tar.gz

zig fetch --debug-hash "${pkg}"
"${script_dir}/../zig-out/bin/zigfetch" "${pkg}"

actual=$("${script_dir}/../zig-out/bin/zigfetch" "${pkg}" 2>&1 | tail -1)
expected="1220e9b279355ce92cd217684a2449bd8024274eb3fc09a576deb33ca1733b9f0a1f"
Expand Down
35 changes: 28 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ const macos_private_framework = "/Applications/Xcode.app/Contents/Developer/Plat
pub fn build(b: *Build) !void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const skip_zigfetch = b.option(bool, "skip_zigfetch", "Skip zig fetch") orelse false;
const skip_zigfetch = b.option(bool, "skip-zigfetch", "Skip zig fetch") orelse false;
const vendor_libcurl = b.option(bool, "vendor-libcurl", "Static link libcurl") orelse false;
var all_tests = std.ArrayList(*Build.Step).init(b.allocator);

try addModules(b, target, &all_tests);
try buildBinaries(b, optimize, target, &all_tests, skip_zigfetch);
try buildBinaries(b, optimize, target, &all_tests, skip_zigfetch, vendor_libcurl);
try buildExamples(b, optimize, target, &all_tests);

const test_all_step = b.step("test", "Run all tests");
Expand Down Expand Up @@ -87,7 +88,7 @@ fn buildExamples(
"simargs-demo",
"pretty-table-demo",
}) |name| {
try buildBinary(b, .{ .ex = name }, optimize, target, all_tests, false);
try buildBinary(b, .{ .ex = name }, optimize, target, all_tests, false, false);
}
}

Expand All @@ -97,6 +98,7 @@ fn buildBinaries(
target: std.Build.ResolvedTarget,
all_tests: *std.ArrayList(*Build.Step),
skip_zigfetch: bool,
vendor_libcurl: bool,
) !void {
inline for (.{
"zigfetch",
Expand All @@ -109,7 +111,15 @@ fn buildBinaries(
"repeat",
"tcp-proxy",
}) |name| {
try buildBinary(b, .{ .bin = name }, optimize, target, all_tests, skip_zigfetch);
try buildBinary(
b,
.{ .bin = name },
optimize,
target,
all_tests,
skip_zigfetch,
vendor_libcurl,
);
}

// TODO: move util out of `bin`
Expand All @@ -123,8 +133,16 @@ fn buildBinary(
target: std.Build.ResolvedTarget,
all_tests: *std.ArrayList(*Build.Step),
skip_zigfetch: bool,
vendor_libcurl: bool,
) !void {
if (makeCompileStep(b, source, optimize, target, skip_zigfetch)) |exe| {
if (makeCompileStep(
b,
source,
optimize,
target,
skip_zigfetch,
vendor_libcurl,
)) |exe| {
var deps = b.modules.iterator();
while (deps.next()) |dep| {
exe.root_module.addImport(dep.key_ptr.*, dep.value_ptr.*);
Expand Down Expand Up @@ -168,6 +186,7 @@ fn makeCompileStep(
optimize: std.builtin.Mode,
target: std.Build.ResolvedTarget,
skip_zigfetch: bool,
vendor_libcurl: bool,
) ?*Build.Step.Compile {
const name = comptime source.name();
const path = comptime source.path();
Expand Down Expand Up @@ -206,9 +225,11 @@ fn makeCompileStep(
return null;
}
if (host_os == .linux or host_os == .macos) {
const dep_curl = b.dependency("curl", .{ .link_vendor = false });
const dep_curl = b.dependency("curl", .{ .link_vendor = vendor_libcurl });
if (!vendor_libcurl) {
exe.linkSystemLibrary("curl");
}
exe.root_module.addImport("curl", dep_curl.module("curl"));
exe.linkSystemLibrary("curl");
exe.linkLibC();
} else {
return null;
Expand Down

0 comments on commit 6ef2907

Please sign in to comment.