Skip to content

Commit 4900870

Browse files
committed
improve testing
1 parent 1ccb98e commit 4900870

8 files changed

Lines changed: 89 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ jobs:
9494
version: ${{ needs.setup.outputs.zig-stable-version }}
9595

9696
- name: Build Test
97-
run: zig build -Dandroid=true --verbose
98-
working-directory: test/build
97+
run: zig build --verbose
98+
working-directory: test
9999

100100
- name: Build Minimal Example
101101
run: zig build -Dandroid=true --verbose
@@ -183,8 +183,8 @@ jobs:
183183
version: "master"
184184

185185
- name: Build Test
186-
run: zig build -Dandroid=true --verbose
187-
working-directory: test/build
186+
run: zig build --verbose
187+
working-directory: test
188188

189189
- name: Build Minimal Example
190190
run: zig build -Dandroid=true --verbose
@@ -233,8 +233,8 @@ jobs:
233233
version: ${{ needs.setup.outputs.zig-previous-stable-version }}
234234

235235
- name: Build Test
236-
run: zig build -Dandroid=true --verbose
237-
working-directory: test/build
236+
run: zig build --verbose
237+
working-directory: test
238238

239239
- name: Build Minimal Example
240240
run: zig build -Dandroid=true --verbose

src/androidbuild/androidbuild.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub fn standardTargets(b: *std.Build, target: ResolvedTarget) []ResolvedTarget {
107107
// Seperated logic into "resolveTargets" so that consumers of this library can create this option themselves and use "b.lazyImport"
108108
// See: https://github.com/silbinarywolf/zig-android-sdk/pull/82
109109
const all_targets = b.option(bool, "android", "Build for all Android targets (x86, x86_64, aarch64, arm, etc)") orelse false;
110+
110111
return resolveTargets(b, .{
111112
.default_target = target,
112113
.all_targets = all_targets,

test/build.zig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Build = @import("std").Build;
2+
3+
pub fn build(b: *Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
7+
const all_step = b.step("all", "Run all tests");
8+
b.default_step = all_step;
9+
10+
for (b.available_deps) |available_dep| {
11+
const test_name, _ = available_dep;
12+
const run_example = b.dependency(test_name, .{
13+
.target = target,
14+
.optimize = optimize,
15+
.android = true,
16+
}).builder.default_step;
17+
const example_step = b.step(test_name, b.fmt("Run the '{s}' test", .{test_name}));
18+
example_step.dependOn(run_example);
19+
all_step.dependOn(example_step);
20+
}
21+
}

test/build.zig.zon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.{
2+
.name = .tests,
3+
.version = "0.0.0",
4+
.fingerprint = 0x1260fc5e4c176d8b,
5+
.minimum_zig_version = "0.16.0",
6+
.paths = .{""},
7+
.dependencies = .{
8+
.build = .{ .path = "build" },
9+
.lazy_android = .{ .path = "lazy_android" },
10+
},
11+
}

test/build/build.zig

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
const std = @import("std");
88
const builtin = @import("builtin");
9-
const log = std.log;
9+
const log = std.log.scoped(.build);
1010

1111
const android = @import("android");
1212

@@ -20,12 +20,6 @@ pub fn build(b: *std.Build) void {
2020
const optimize = b.standardOptimizeOption(.{});
2121
const android_targets = android.standardTargets(b, root_target);
2222

23-
// NOTE(jae): 2026-04-12
24-
// Run it *after* the "standardTargets" call
25-
if (is_latest_stable_zig) {
26-
testLazyImportAndResolveTargets(b, root_target);
27-
}
28-
2923
var root_target_single = [_]std.Build.ResolvedTarget{root_target};
3024
const targets: []std.Build.ResolvedTarget = if (android_targets.len == 0)
3125
root_target_single[0..]
@@ -53,6 +47,10 @@ pub fn build(b: *std.Build) void {
5347
};
5448

5549
for (targets) |target| {
50+
if (!target.result.abi.isAndroid()) {
51+
std.debug.panic("For testing Android builds only. Target(s) should be Android not: {t}", .{target.result.abi});
52+
}
53+
5654
const translate_c_vendored_mod = testTranslateCVendor(b, target, optimize) orelse return;
5755

5856
const app_module = b.createModule(.{
@@ -142,27 +140,6 @@ fn testTranslateCExternal(b: *std.Build, target: std.Build.ResolvedTarget, optim
142140
return trans_libandroid.mod;
143141
}
144142

145-
/// Test calling lazyImport and then calling "resolveTargets"
146-
///
147-
/// PR: https://github.com/silbinarywolf/zig-android-sdk/pull/83
148-
fn testLazyImportAndResolveTargets(b: *std.Build, root_target: std.Build.ResolvedTarget) void {
149-
const all_android_targets = true;
150-
const android_targets: []std.Build.ResolvedTarget = blk: {
151-
if (all_android_targets or root_target.result.abi.isAndroid()) {
152-
if (b.lazyImport(@This(), "lazy_android")) |lazy_android| {
153-
break :blk lazy_android.resolveTargets(b, .{
154-
.default_target = root_target,
155-
.all_targets = true,
156-
});
157-
}
158-
}
159-
break :blk &[0]std.Build.ResolvedTarget{};
160-
};
161-
if (android_targets.len != 4) @panic("expected 'resolveTargets' it to return 4 Android targets");
162-
163-
log.info("testLazyImportAndResolveTargets: check that resolving android targets worked. Got: {}", .{android_targets.len});
164-
}
165-
166143
/// Test the addLibraryFile functionality
167144
///
168145
/// Requested feature here: https://github.com/silbinarywolf/zig-android-sdk/issues/77

test/build/build.zig.zon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
.android = .{
66
.path = "../..",
77
},
8-
.lazy_android = .{
9-
.path = "../..",
10-
.lazy = true,
11-
},
128
.vulkan_validation = .{
139
.url = "https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/download/vulkan-sdk-1.4.341.0/android-binaries-1.4.341.0.zip",
1410
.hash = "N-V-__8AABTXlAV0z_BGl5-lZeOEm_d2gHEhExT2qjxMqQ72",

test/lazy_android/build.zig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const Build = @import("std").Build;
2+
const log = @import("std").log.scoped(.lazy_android);
3+
4+
pub fn build(b: *Build) void {
5+
const root_target = b.standardTargetOptions(.{});
6+
_ = b.standardOptimizeOption(.{});
7+
8+
// Test calling lazyImport and then calling "resolveTargets"
9+
//
10+
// PR: https://github.com/silbinarywolf/zig-android-sdk/pull/83
11+
{
12+
const all_android_targets = b.option(bool, "android", "Custom usage of android flag") orelse false;
13+
if (!all_android_targets)
14+
@panic("expected android=true for the flag");
15+
const android_targets: []Build.ResolvedTarget = blk: {
16+
if (all_android_targets or root_target.result.abi.isAndroid()) {
17+
if (b.lazyImport(@This(), "lazy_android")) |lazy_android| {
18+
break :blk lazy_android.resolveTargets(b, .{
19+
.default_target = root_target,
20+
.all_targets = true,
21+
});
22+
}
23+
}
24+
break :blk &[0]Build.ResolvedTarget{};
25+
};
26+
if (android_targets.len != 4) @panic("expected 'resolveTargets' it to return 4 Android targets");
27+
28+
log.info("testLazyImportAndResolveTargets: check that resolving android targets worked. Got: {}", .{android_targets.len});
29+
}
30+
}

test/lazy_android/build.zig.zon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.{
2+
.name = .lazy_android,
3+
.version = "0.0.0",
4+
.fingerprint = 0xf96a46f8318f02b1,
5+
.dependencies = .{
6+
.lazy_android = .{
7+
.path = "../..",
8+
.lazy = true,
9+
},
10+
},
11+
.paths = .{
12+
"build.zig",
13+
"build.zig.zon",
14+
},
15+
}

0 commit comments

Comments
 (0)