From 31e1034c88e8520fc4daf4a15b3eab31c3a15aac Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Sun, 12 May 2024 12:14:46 +0800 Subject: [PATCH] use lazy dependency --- .github/workflows/CI.yml | 48 +++++++++++++++++++++++++++++++++++++++- Makefile | 10 +++++---- build.zig.zon | 3 +++ libs/curl.zig | 4 ++-- libs/mbedtls.zig | 4 ++-- libs/zlib.zig | 4 ++-- 6 files changed, 62 insertions(+), 11 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 72da2d2..b423390 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -16,7 +16,7 @@ on: - '**.yml' jobs: - test-linux: + test-vendor: timeout-minutes: 10 runs-on: ${{ matrix.os }} strategy: @@ -56,3 +56,49 @@ jobs: valgrind --leak-check=full --tool=memcheck \ --show-leak-kinds=all --error-exitcode=1 ${bin} done + + test-dynamic: + timeout-minutes: 10 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + zig-version: [master, 0.12.0] + steps: + - uses: actions/checkout@v4 + - uses: goto-bus-stop/setup-zig@v2 + with: + version: ${{ matrix.zig-version }} + - uses: actions/setup-go@v5 + with: + go-version: 'stable' + - name: Set Environment Variables + run: | + echo "ZIG_ARGS='-Dlink_vendor=false'" >> $GITHUB_ENV + sudo apt-get install -y libcurl4-openssl-dev + + - name: Run tests + run: | + make test + - name: Run examples + run: | + SERVER=/tmp/echo-server + go build -o ${SERVER} server/main.go + ${SERVER} & + sleep 10 + make run + - name: Install deps + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt update && sudo apt install -y valgrind + - name: Memory leak detect + if: matrix.os == 'ubuntu-latest' + run: | + zig build -Dcpu=baseline --verbose + + BINS=("./zig-out/bin/basic" "./zig-out/bin/advanced") + for bin in ${BINS[@]}; do + valgrind --leak-check=full --tool=memcheck \ + --show-leak-kinds=all --error-exitcode=1 ${bin} + done diff --git a/Makefile b/Makefile index 5946acc..255beae 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ +ARGS = ${ZIG_ARGS} + prepare: ./libs/update.sh @@ -9,12 +11,12 @@ serve: cd server && go run main.go run: - zig build run-basic -freference-trace - zig build run-advanced -freference-trace - zig build run-multi -freference-trace + zig build run-basic -freference-trace $(ARGS) + zig build run-advanced -freference-trace $(ARGS) + zig build run-multi -freference-trace $(ARGS) test: - zig build test + zig build test $(ARGS) docs: if [ ! -d zig-out ]; then mkdir zig-out; fi diff --git a/build.zig.zon b/build.zig.zon index 22dee29..e209ba4 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -13,15 +13,18 @@ // https://github.com/curl/curl/releases/tag/curl-8_5_0 .url = "https://github.com/curl/curl/releases/download/curl-8_5_0/curl-8.5.0.tar.gz", .hash = "12206e97053bf43e6bd83f2d51eefbac497a05f2eee98868431e9d228a12971e716e", + .lazy = true, }, // https://github.com/madler/zlib/releases/tag/v1.3 .zlib = .{ .url = "https://github.com/madler/zlib/releases/download/v1.3/zlib-1.3.tar.gz", .hash = "1220c32f4f9dbcb4445c153b6a5bf1e1f697a76f6b690dda9c600357c6b7080af614", + .lazy = true, }, .mbedtls = .{ .url = "https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v3.5.1.tar.gz", .hash = "1220700935566604edf3dd5491dab97c29571d1b07830e626ed31109811198fdc941", + .lazy = true, }, }, } diff --git a/libs/curl.zig b/libs/curl.zig index 97a208f..99c4d17 100644 --- a/libs/curl.zig +++ b/libs/curl.zig @@ -7,10 +7,10 @@ pub fn create(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bui .optimize = optimize, .link_libc = true, }); - const curl_dep = b.dependency("curl", .{ + const curl_dep = b.lazyDependency("curl", .{ .target = target, .optimize = optimize, - }); + }) orelse unreachable; inline for (srcs) |s| { lib.addCSourceFile(.{ diff --git a/libs/mbedtls.zig b/libs/mbedtls.zig index 400b9f1..731933c 100644 --- a/libs/mbedtls.zig +++ b/libs/mbedtls.zig @@ -9,10 +9,10 @@ pub fn create(b: *std.Build, target: ResolvedTarget, optimize: std.builtin.Optim .link_libc = true, }); - const mbedtls_dep = b.dependency("mbedtls", .{ + const mbedtls_dep = b.lazyDependency("mbedtls", .{ .target = target, .optimize = optimize, - }); + }) orelse unreachable; inline for (srcs) |s| { lib.addCSourceFile(.{ .file = mbedtls_dep.path(s), .flags = &.{"-std=c99"} }); } diff --git a/libs/zlib.zig b/libs/zlib.zig index 4f28dd6..5a2f805 100644 --- a/libs/zlib.zig +++ b/libs/zlib.zig @@ -7,10 +7,10 @@ pub fn create(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bui .optimize = optimize, .link_libc = true, }); - const zlib_dep = b.dependency("zlib", .{ + const zlib_dep = b.lazyDependency("zlib", .{ .target = target, .optimize = optimize, - }); + }) orelse unreachable; inline for (srcs) |s| { lib.addCSourceFile(.{