|
1 | 1 | const std = @import("std"); |
| 2 | +const builtin = @import("builtin"); |
2 | 3 | const androidbuild = @import("src/androidbuild/androidbuild.zig"); |
3 | 4 |
|
4 | 5 | // Expose Android build functionality for use in your build.zig |
@@ -27,17 +28,56 @@ pub fn build(b: *std.Build) void { |
27 | 28 | const target = b.standardTargetOptions(.{}); |
28 | 29 | const optimize = b.standardOptimizeOption(.{}); |
29 | 30 |
|
30 | | - const module = b.addModule("android", .{ |
| 31 | + // Create stub of builtin options. |
| 32 | + // This is discovered and then replaced by "Apk" in the build process |
| 33 | + const android_builtin_options = std.Build.addOptions(b); |
| 34 | + android_builtin_options.addOption([:0]const u8, "package_name", ""); |
| 35 | + const android_builtin_module = android_builtin_options.createModule(); |
| 36 | + |
| 37 | + // Create android module |
| 38 | + const android_module = b.addModule("android", .{ |
31 | 39 | .root_source_file = b.path("src/android/android.zig"), |
32 | 40 | .target = target, |
33 | 41 | .optimize = optimize, |
34 | 42 | }); |
| 43 | + const ndk_module = b.createModule(.{ |
| 44 | + .root_source_file = b.path("src/android/ndk/ndk.zig"), |
| 45 | + .target = target, |
| 46 | + .optimize = optimize, |
| 47 | + }); |
| 48 | + android_module.addImport("ndk", ndk_module); |
| 49 | + android_module.addImport("android_builtin", android_builtin_module); |
35 | 50 |
|
36 | | - // Create stub of builtin options. |
37 | | - // This is discovered and then replaced by "Apk" in the build process |
38 | | - const android_builtin_options = std.Build.addOptions(b); |
39 | | - android_builtin_options.addOption([:0]const u8, "package_name", ""); |
40 | | - module.addImport("android_builtin", android_builtin_options.createModule()); |
| 51 | + // Add backwards compatibility modules |
| 52 | + if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 14) { |
| 53 | + // Deprecated: Allow older Zig builds to work |
| 54 | + var zig014 = b.createModule(.{ |
| 55 | + .root_source_file = b.path("src/android/zig014/zig014.zig"), |
| 56 | + .target = target, |
| 57 | + .optimize = optimize, |
| 58 | + }); |
| 59 | + zig014.addImport("ndk", ndk_module); |
| 60 | + zig014.addImport("android_builtin", android_builtin_module); |
| 61 | + android_module.addImport("zig014", zig014); |
| 62 | + } |
| 63 | + if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15) { |
| 64 | + // Add as a module to deal with @Type(.enum_literal) being deprecated |
| 65 | + const zig015 = b.createModule(.{ |
| 66 | + .root_source_file = b.path("src/android/zig015/zig015.zig"), |
| 67 | + .target = target, |
| 68 | + .optimize = optimize, |
| 69 | + }); |
| 70 | + android_module.addImport("zig015", zig015); |
| 71 | + } |
| 72 | + if (builtin.zig_version.major == 0 and builtin.zig_version.minor >= 16) { |
| 73 | + // Add as a module to deal with @Type(.enum_literal) being deprecated |
| 74 | + const zig016 = b.createModule(.{ |
| 75 | + .root_source_file = b.path("src/android/zig016/zig016.zig"), |
| 76 | + .target = target, |
| 77 | + .optimize = optimize, |
| 78 | + }); |
| 79 | + android_module.addImport("zig016", zig016); |
| 80 | + } |
41 | 81 |
|
42 | | - module.linkSystemLibrary("log", .{}); |
| 82 | + android_module.linkSystemLibrary("log", .{}); |
43 | 83 | } |
0 commit comments