Skip to content

Commit

Permalink
use lazy dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed May 12, 2024
1 parent 2b12a41 commit 31e1034
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 11 deletions.
48 changes: 47 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
- '**.yml'

jobs:
test-linux:
test-vendor:
timeout-minutes: 10
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -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
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

ARGS = ${ZIG_ARGS}

prepare:
./libs/update.sh

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
4 changes: 2 additions & 2 deletions libs/curl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(.{
Expand Down
4 changes: 2 additions & 2 deletions libs/mbedtls.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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"} });
}
Expand Down
4 changes: 2 additions & 2 deletions libs/zlib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(.{
Expand Down

0 comments on commit 31e1034

Please sign in to comment.