Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions test/translate_c_dep/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const std = @import("std");
const builtin = @import("builtin");
const log = std.log.scoped(.build);
const log = std.log.scoped(.translate_c_dep);

const android = @import("android");

Expand Down Expand Up @@ -45,22 +45,60 @@ pub fn build(b: *std.Build) void {
break :blk apk;
};

// Load translate_c module
const translate_c_dep_name = "translate_c";
const translate_c_import = b.lazyImport(@This(), translate_c_dep_name) orelse return;
const translate_c = b.lazyDependency(translate_c_dep_name, .{}) orelse return;
const Translator = translate_c_import.Translator;

for (targets) |target| {
if (!target.result.abi.isAndroid()) {
std.debug.panic("For testing Android builds only. Target(s) should be Android not: {t}", .{target.result.abi});
}

const app_module = b.createModule(.{
.root_source_file = b.path("src/translate_c_dep_main.zig"),
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/translate_c_dep_main.zig"),
});

// Must be stable release of Zig *and* 0.16.X or higher
// testTranslateCExternal
{
const translator: Translator = .init(translate_c, .{
.c_source_file = b.addWriteFiles().add("android_c.h",
\\#include <android/log.h> /* For main module */
),
.target = target,
.optimize = optimize,
});
app_module.addImport("translate_c_external", translator.mod);
log.info("testTranslateCExternal({t}): add import 'translate_c_external'", .{target.result.cpu.arch});
}

// testTranslateCExternal for sub-sub-module, this test should ideally catch recursion with imported modules
{
const translate_c_external_mod = testTranslateCExternal(b, target, optimize) orelse return;
app_module.addImport("translate_c_external", translate_c_external_mod);
log.info("testTranslateCExternal: add import 'translate_c_external' to {t}", .{target.result.cpu.arch});
const single_depth_mod = b.createModule(.{
.root_source_file = b.path("src/translate_c_dep_single_depth_module.zig"),
.target = target,
.optimize = optimize,
});
const double_depth_mod = b.createModule(.{
.root_source_file = b.path("src/translate_c_dep_double_depth_module.zig"),
.target = target,
.optimize = optimize,
});
single_depth_mod.addImport("double_depth", double_depth_mod);

const translator: Translator = .init(translate_c, .{
.c_source_file = b.addWriteFiles().add("android_sub_c.h",
\\#include <android/log.h> /* For sub-module (two-depth from main) */
),
.target = target,
.optimize = optimize,
});
double_depth_mod.addImport("translate_c_external_recursive", translator.mod);
app_module.addImport("single_depth", single_depth_mod);
log.info("testTranslateCExternalSubModule({t}): add import 'translate_c_external_recursive' a sub-sub-module of main", .{target.result.cpu.arch});
}

const libmain = b.addLibrary(.{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Test that a translate-c module will work recursively

comptime {
// For external translate-c usage, validate at compile-time that this symbol exists
_ = @import("translate_c_external_recursive").__android_log_write;
}
1 change: 1 addition & 0 deletions test/translate_c_dep/src/translate_c_dep_main.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const builtin = @import("builtin");

const android = @import("android");
const _ = @import("single_depth");

comptime {
// For external translate-c usage, validate at compile-time that this symbol exists
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Test that a module added to "main" works

const _ = @import("double_depth");
Loading