Skip to content

Commit 9bb3960

Browse files
authored
Merge pull request #7 from ananthb/zig-0.15-compat
Zig 0.15 compatibility
2 parents 83293f4 + 2a3acd8 commit 9bb3960

17 files changed

Lines changed: 377 additions & 417 deletions

.github/workflows/build.yml

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,49 @@ on:
55
pull_request:
66

77
jobs:
8-
pre-commit:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v4
12-
- uses: actions/setup-python@v5
13-
- uses: pre-commit/action@v3.0.1
14-
15-
codespell:
8+
build:
169
runs-on: ubuntu-latest
1710
steps:
1811
- uses: actions/checkout@v4
19-
- uses: codespell-project/actions-codespell@master
12+
- uses: mlugg/setup-zig@v2
2013
with:
21-
check_filenames: true
22-
skip: ./.git,./vendor,*_test.go,go.sum,go.mod
14+
version: 0.15.2
15+
- run: zig build
2316

24-
build:
17+
fmt:
2518
runs-on: ubuntu-latest
2619
steps:
2720
- uses: actions/checkout@v4
2821
- uses: mlugg/setup-zig@v2
2922
with:
30-
version: 0.14.1
31-
- run: |
32-
make build
23+
version: 0.15.2
24+
- run: zig build fmt
3325

34-
fmt:
26+
test:
3527
runs-on: ubuntu-latest
3628
steps:
3729
- uses: actions/checkout@v4
3830
- uses: mlugg/setup-zig@v2
3931
with:
40-
version: 0.14.1
41-
- run: |
42-
make fmt
32+
version: 0.15.2
33+
- run: zig build test
4334

44-
unit_test:
35+
coverage:
4536
runs-on: ubuntu-latest
4637
steps:
4738
- uses: actions/checkout@v4
4839
- uses: mlugg/setup-zig@v2
4940
with:
50-
version: 0.14.1
51-
- run: |
52-
sudo apt-get install binutils-dev libssl-dev libcurl4-openssl-dev libelf-dev libstdc++-12-dev zlib1g-dev libdw-dev libiberty-dev git
41+
version: 0.15.2
42+
- name: Install kcov
43+
run: |
44+
sudo apt-get install -y binutils-dev libssl-dev libcurl4-openssl-dev libelf-dev libstdc++-12-dev zlib1g-dev libdw-dev libiberty-dev cmake
5345
git clone https://github.com/SimonKagstrom/kcov.git
54-
cd kcov
55-
git checkout v43
56-
mkdir build
57-
cd build
58-
cmake ..
59-
make
60-
sudo make install
61-
- run: |
62-
make test
63-
make coverage
64-
65-
- name: Upload coverage reports to Codecov
46+
cd kcov && git checkout v43 && mkdir build && cd build && cmake .. && make && sudo make install
47+
- run: zig build cov
48+
- name: Upload coverage
6649
uses: codecov/codecov-action@v3
6750
with:
6851
file: .coverage/test/cov.xml
6952
token: ${{ secrets.CODECOV_TOKEN }}
70-
name: codecov-umbrella
71-
fail_ci_if_error: true
53+
fail_ci_if_error: false

build.zig

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@ pub fn build(b: *std.Build) void {
99
const target = b.standardTargetOptions(.{});
1010
const optimize = b.standardOptimizeOption(.{});
1111

12-
// add library
13-
const lib = b.addStaticLibrary(.{
14-
.name = "ocispec",
15-
// In this case the main source file is merely a path, however, in more
16-
// complicated build scripts, this could be a generated file.
17-
.root_source_file = b.path("src/distribution/lib.zig"),
18-
.target = target,
19-
.optimize = optimize,
20-
.single_threaded = false,
21-
});
22-
23-
b.installArtifact(lib);
24-
2512
const oci_spec_module = b.addModule("ocispec", .{
2613
.root_source_file = b.path("src/lib.zig"),
2714
});
2815

16+
// Library object for documentation generation
17+
const lib = b.addObject(.{
18+
.name = "ocispec",
19+
.root_module = b.createModule(.{
20+
.root_source_file = b.path("src/lib.zig"),
21+
.target = target,
22+
.optimize = optimize,
23+
}),
24+
});
25+
2926
// step generate docs
3027
const install_docs = b.addInstallDirectory(.{
3128
.source_dir = lib.getEmittedDocs(),
@@ -46,36 +43,37 @@ pub fn build(b: *std.Build) void {
4643
}) |example_name| {
4744
const example = b.addExecutable(.{
4845
.name = example_name,
49-
.root_source_file = b.path(b.fmt("examples/{s}.zig", .{example_name})),
50-
.target = target,
51-
.optimize = optimize,
46+
.root_module = b.createModule(.{
47+
.root_source_file = b.path(b.fmt("examples/{s}.zig", .{example_name})),
48+
.target = target,
49+
.optimize = optimize,
50+
}),
5251
});
5352

5453
example.root_module.addImport("ocispec", oci_spec_module);
5554
b.installArtifact(example);
5655
}
5756

5857
// step run tests
59-
const lib_unit_tests = b.addTest(.{
60-
// Assuming this needs to be the same root file as the library,
61-
// since it's the library we're building tests for?
58+
const test_module = b.createModule(.{
6259
.root_source_file = b.path("tests/lib.zig"),
6360
.target = target,
6461
.optimize = optimize,
6562
});
66-
lib_unit_tests.root_module.addImport("ocispec", oci_spec_module);
63+
test_module.addImport("ocispec", oci_spec_module);
64+
const lib_unit_tests = b.addTest(.{
65+
.root_module = test_module,
66+
});
6767

6868
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
6969

7070
const test_step = b.step("test", "Run unit tests");
7171
test_step.dependOn(&run_lib_unit_tests.step);
7272

73-
// step generate code cov
73+
// step generate code coverage
7474
const cov_step = b.step("cov", "Generate code coverage");
75-
7675
const cov_run = b.addSystemCommand(&.{ "kcov", "--clean", "--include-pattern=src/", ".coverage/" });
7776
cov_run.addArtifactArg(lib_unit_tests);
78-
7977
cov_step.dependOn(&cov_run.step);
8078

8179
// step check formatting

examples/artifact_manifest.zig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ pub fn main() !void {
1313

1414
const config_content = try artifact_manifest.toStringPretty(allocator);
1515

16-
const stdout_file = std.io.getStdOut().writer();
17-
var bw = std.io.bufferedWriter(stdout_file);
18-
const stdout = bw.writer();
16+
var write_buf: [4096]u8 = undefined;
17+
var stdout = std.fs.File.stdout().writer(&write_buf);
18+
try stdout.interface.print("{s}\n", .{config_content});
19+
stdout.interface.flush() catch {};
1920

20-
try stdout.print("{s}\n", .{config_content});
21-
22-
try bw.flush();
2321
}

examples/image_config.zig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ pub fn main() !void {
1212
const image_config = try image.Configuration.initFromFile(allocator, file_path);
1313
const config_content = try image_config.toStringPretty(allocator);
1414

15-
const stdout_file = std.io.getStdOut().writer();
16-
var bw = std.io.bufferedWriter(stdout_file);
17-
const stdout = bw.writer();
15+
var write_buf: [4096]u8 = undefined;
16+
var stdout = std.fs.File.stdout().writer(&write_buf);
17+
try stdout.interface.print("{s}\n", .{config_content});
18+
stdout.interface.flush() catch {};
1819

19-
try stdout.print("{s}\n", .{config_content});
20-
21-
try bw.flush();
2220
}

examples/image_index.zig

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ pub fn main() !void {
2020
.digest = try image.Digest.initFromString(allocator, "sha256:9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0"),
2121
};
2222

23-
var manifests = std.ArrayList(image.Descriptor).init(allocator);
23+
var manifests: std.ArrayListUnmanaged(image.Descriptor) = .{};
2424

25-
try manifests.append(index_manifest);
25+
try manifests.append(allocator, index_manifest);
2626

27-
const image_manifests: []image.Descriptor = try manifests.toOwnedSlice();
27+
const image_manifests: []image.Descriptor = try manifests.toOwnedSlice(allocator);
2828

2929
const image_index = image.Index{
3030
.mediaType = image.MediaType.ImageIndex,
@@ -33,11 +33,9 @@ pub fn main() !void {
3333

3434
const image_index_content = try image_index.toStringPretty(allocator);
3535

36-
const stdout_file = std.io.getStdOut().writer();
37-
var bw = std.io.bufferedWriter(stdout_file);
38-
const stdout = bw.writer();
36+
var write_buf: [4096]u8 = undefined;
37+
var stdout = std.fs.File.stdout().writer(&write_buf);
38+
try stdout.interface.print("{s}\n", .{image_index_content});
39+
stdout.interface.flush() catch {};
3940

40-
try stdout.print("{s}\n", .{image_index_content});
41-
42-
try bw.flush();
4341
}

examples/image_manifest.zig

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub fn main() !void {
1212
const media_config = image.MediaType.ImageConfig;
1313
const media_layer = image.MediaType.ImageLayerGzip;
1414

15-
var mlayers = std.ArrayList(image.Descriptor).init(allocator);
16-
try mlayers.append(image.Descriptor{
15+
var mlayers: std.ArrayListUnmanaged(image.Descriptor) = .{};
16+
try mlayers.append(allocator, image.Descriptor{
1717
.mediaType = media_layer,
1818
.digest = try image.Digest.initFromString(
1919
allocator,
@@ -22,7 +22,7 @@ pub fn main() !void {
2222
.size = 32654,
2323
});
2424

25-
const manifest_layers: []image.Descriptor = try mlayers.toOwnedSlice();
25+
const manifest_layers: []image.Descriptor = try mlayers.toOwnedSlice(allocator);
2626

2727
const manifest = image.Manifest{
2828
.mediaType = media_manifest,
@@ -39,11 +39,9 @@ pub fn main() !void {
3939

4040
const manifest_content = try manifest.toStringPretty(allocator);
4141

42-
const stdout_file = std.io.getStdOut().writer();
43-
var bw = std.io.bufferedWriter(stdout_file);
44-
const stdout = bw.writer();
42+
var write_buf: [4096]u8 = undefined;
43+
var stdout = std.fs.File.stdout().writer(&write_buf);
44+
try stdout.interface.print("{s}\n", .{manifest_content});
45+
stdout.interface.flush() catch {};
4546

46-
try stdout.print("{s}\n", .{manifest_content});
47-
48-
try bw.flush();
4947
}

examples/image_oci_layout.zig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ pub fn main() !void {
1212

1313
const oci_layout_content = try oci_layout.toStringPretty(allocator);
1414

15-
const stdout_file = std.io.getStdOut().writer();
16-
var bw = std.io.bufferedWriter(stdout_file);
17-
const stdout = bw.writer();
15+
var write_buf: [4096]u8 = undefined;
16+
var stdout = std.fs.File.stdout().writer(&write_buf);
17+
try stdout.interface.print("{s}\n", .{oci_layout_content});
18+
stdout.interface.flush() catch {};
1819

19-
try stdout.print("{s}\n", .{oci_layout_content});
20-
21-
try bw.flush();
2220
}

examples/runtime_config.zig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ pub fn main() !void {
1313

1414
const config_content = try spec.toStringPretty(allocator);
1515

16-
const stdout_file = std.io.getStdOut().writer();
17-
var bw = std.io.bufferedWriter(stdout_file);
18-
const stdout = bw.writer();
16+
var write_buf: [4096]u8 = undefined;
17+
var stdout = std.fs.File.stdout().writer(&write_buf);
18+
try stdout.interface.print("{s}\n", .{config_content});
19+
stdout.interface.flush() catch {};
1920

20-
try stdout.print("{s}\n", .{config_content});
21-
22-
try bw.flush();
2321
}

0 commit comments

Comments
 (0)