Skip to content

Commit aeaf220

Browse files
committed
initial Zig 12 support
1 parent a790783 commit aeaf220

File tree

3 files changed

+50
-47
lines changed

3 files changed

+50
-47
lines changed

Sdk.zig

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ fn sdkRoot() *const [sdkRootIntern().len]u8 {
1818

1919
// linux-x86_64
2020
pub fn toolchainHostTag() []const u8 {
21-
comptime {
22-
const os = builtin.os.tag;
23-
const arch = builtin.cpu.arch;
24-
return @tagName(os) ++ "-" ++ @tagName(arch);
25-
}
21+
const os = builtin.os.tag;
22+
const arch = builtin.cpu.arch;
23+
return (comptime if (std.mem.eql(u8, @tagName(os), "macos")) "darwin" else @tagName(os)) ++ "-" ++ @tagName(arch);
2624
}
2725

2826
/// This file encodes a instance of an Android SDK interface.
@@ -92,12 +90,12 @@ pub fn init(b: *Builder, user_config: ?UserConfig, toolchains: ToolchainVersions
9290
.name = "zip_add",
9391
.root_source_file = .{ .path = sdkRoot() ++ "/tools/zip_add.zig" },
9492
});
95-
zip_add.addCSourceFile(sdkRoot() ++ "/vendor/kuba-zip/zip.c", &[_][]const u8{
93+
zip_add.addCSourceFile(.{ .file = .{ .path = sdkRoot() ++ "/vendor/kuba-zip/zip.c" }, .flags = &[_][]const u8{
9694
"-std=c99",
9795
"-fno-sanitize=undefined",
9896
"-D_POSIX_C_SOURCE=200112L",
99-
});
100-
zip_add.addIncludePath(sdkRoot() ++ "/vendor/kuba-zip");
97+
} });
98+
zip_add.addIncludePath(.{ .path = sdkRoot() ++ "/vendor/kuba-zip" });
10199
zip_add.linkLibC();
102100

103101
break :blk HostTools{
@@ -503,10 +501,11 @@ pub fn createApp(
503501
}
504502
resource_dir_step.add(Resource{
505503
.path = "values/strings.xml",
506-
.content = write_xml_step.getFileSource("strings.xml").?,
504+
// .content = write_xml_step.getFileSource("strings.xml").?,
505+
.content = write_xml_step.addCopyFile(.{ .path = "strings.xml" }, ""),
507506
});
508507

509-
const sdk_version_int = @enumToInt(app_config.target_version);
508+
const sdk_version_int = @intFromEnum(app_config.target_version);
510509

511510
if (sdk_version_int < 16) @panic("Minimum supported sdk version is 16.");
512511

@@ -549,7 +548,8 @@ pub fn createApp(
549548
const unaligned_apk_file = make_unsigned_apk.addOutputFileArg(unaligned_apk_name);
550549

551550
make_unsigned_apk.addArg("-M"); // specify full path to AndroidManifest.xml to include in zip
552-
make_unsigned_apk.addFileSourceArg(manifest_step.getFileSource("AndroidManifest.xml").?);
551+
// make_unsigned_apk.addFileSourceArg(manifest_step.getFileSource("AndroidManifest.xml").?);
552+
make_unsigned_apk.addFileSourceArg(manifest_step.addCopyFile(.{ .path = "AndroidManifest.xml" }, ""));
553553

554554
make_unsigned_apk.addArg("-S"); // directory in which to find resources. Multiple directories will be scanned and the first match found (left to right) will take precedence
555555
make_unsigned_apk.addDirectorySourceArg(resource_dir_step.getOutputDirectory());
@@ -848,7 +848,7 @@ pub fn compileAppLibrary(
848848
ndk_root,
849849
toolchainHostTag(),
850850
config.lib_dir,
851-
@enumToInt(app_config.target_version),
851+
@intFromEnum(app_config.target_version),
852852
});
853853

854854
const include_dir = std.fs.path.resolve(sdk.b.allocator, &[_][]const u8{
@@ -887,7 +887,7 @@ pub fn compileAppLibrary(
887887

888888
// exe.addIncludePath(include_dir);
889889

890-
exe.addLibraryPath(lib_dir);
890+
exe.addLibraryPath(.{ .path = lib_dir });
891891

892892
// exe.addIncludePath(include_dir);
893893
// exe.addIncludePath(system_include_dir);
@@ -904,7 +904,7 @@ pub fn compileAppLibrary(
904904
}
905905

906906
fn createLibCFile(sdk: *const Sdk, version: AndroidVersion, folder_name: []const u8, include_dir: []const u8, sys_include_dir: []const u8, crt_dir: []const u8) !std.build.FileSource {
907-
const fname = sdk.b.fmt("android-{d}-{s}.conf", .{ @enumToInt(version), folder_name });
907+
const fname = sdk.b.fmt("android-{d}-{s}.conf", .{ @intFromEnum(version), folder_name });
908908

909909
var contents = std.ArrayList(u8).init(sdk.b.allocator);
910910
errdefer contents.deinit();
@@ -926,7 +926,8 @@ fn createLibCFile(sdk: *const Sdk, version: AndroidVersion, folder_name: []const
926926
try writer.writeAll("gcc_dir=\n");
927927

928928
const step = sdk.b.addWriteFile(fname, contents.items);
929-
return step.getFileSource(fname) orelse unreachable;
929+
// return step.getFileSource(fname) orelse unreachable;
930+
return step.addCopyFile(.{ .path = fname }, "");
930931
}
931932

932933
pub fn compressApk(sdk: Sdk, input_apk_file: []const u8, output_apk_file: []const u8) *Step {
@@ -1151,22 +1152,22 @@ const BuildOptionStep = struct {
11511152
}
11521153
return;
11531154
},
1154-
std.builtin.Version => {
1155-
out.print(
1156-
\\pub const {}: @import("std").builtin.Version = .{{
1157-
\\ .major = {d},
1158-
\\ .minor = {d},
1159-
\\ .patch = {d},
1160-
\\}};
1161-
\\
1162-
, .{
1163-
std.zig.fmtId(name),
1164-
1165-
value.major,
1166-
value.minor,
1167-
value.patch,
1168-
}) catch unreachable;
1169-
},
1155+
// std.builtin.Version => {
1156+
// out.print(
1157+
// \\pub const {}: @import("std").builtin.Version = .{{
1158+
// \\ .major = {d},
1159+
// \\ .minor = {d},
1160+
// \\ .patch = {d},
1161+
// \\}};
1162+
// \\
1163+
// , .{
1164+
// std.zig.fmtId(name),
1165+
1166+
// value.major,
1167+
// value.minor,
1168+
// value.patch,
1169+
// }) catch unreachable;
1170+
// },
11701171
std.SemanticVersion => {
11711172
out.print(
11721173
\\pub const {}: @import("std").SemanticVersion = .{{

build/auto-detect.zig

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ pub fn findUserConfig(b: *Builder, versions: Sdk.ToolchainVersions) !UserConfig
2424
// Check for a user config file.
2525
if (std.fs.cwd().openFile(config_path, .{})) |file| {
2626
defer file.close();
27-
const bytes = file.readToEndAlloc(b.allocator, 1 * 1000 * 1000) catch |err| {
28-
print("Unexpected error reading {s}: {s}\n", .{ config_path, @errorName(err) });
29-
return err;
30-
};
31-
var stream = std.json.TokenStream.init(bytes);
32-
if (std.json.parse(UserConfig, &stream, .{ .allocator = b.allocator })) |conf| {
33-
config = conf;
34-
} else |err| {
35-
print("Could not parse {s} ({s}).\n", .{ config_path, @errorName(err) });
36-
return err;
37-
}
27+
// @panic("Config file not supported yet");
28+
std.debug.print("Config file: TODO\n", .{});
29+
// const bytes = file.readToEndAlloc(b.allocator, 1 * 1000 * 1000) catch |err| {
30+
// print("Unexpected error reading {s}: {s}\n", .{ config_path, @errorName(err) });
31+
// return err;
32+
// };
33+
// var stream = std.json.TokenStream.init(bytes);
34+
// if (std.json.parse(UserConfig, &stream, .{ .allocator = b.allocator })) |conf| {
35+
// config = conf;
36+
// } else |err| {
37+
// print("Could not parse {s} ({s}).\n", .{ config_path, @errorName(err) });
38+
// return err;
39+
// }
3840
} else |err| switch (err) {
3941
error.FileNotFound => {
4042
config_dirty = true;
@@ -99,10 +101,10 @@ pub fn findUserConfig(b: *Builder, versions: Sdk.ToolchainVersions) !UserConfig
99101
const LSTATUS = u32;
100102
const DWORD = u32;
101103

102-
// const HKEY_CLASSES_ROOT = @intToPtr(HKEY, 0x80000000);
103-
const HKEY_CURRENT_USER = @intToPtr(HKEY, 0x80000001);
104-
const HKEY_LOCAL_MACHINE = @intToPtr(HKEY, 0x80000002);
105-
// const HKEY_USERS = @intToPtr(HKEY, 0x80000003);
104+
// const HKEY_CLASSES_ROOT: HKEY= @ptrFromInt(0x80000000);
105+
const HKEY_CURRENT_USER: HKEY = @ptrFromInt(0x80000001);
106+
const HKEY_LOCAL_MACHINE: HKEY = @ptrFromInt(0x80000002);
107+
// const HKEY_USERS: HKEY= @ptrFromInt(0x80000003);
106108

107109
// const RRF_RT_ANY: DWORD = 0xFFFF;
108110
// const RRF_RT_REG_BINARY: DWORD = 0x08;
@@ -142,7 +144,7 @@ pub fn findUserConfig(b: *Builder, versions: Sdk.ToolchainVersions) !UserConfig
142144

143145
// get the data
144146
const buffer = allocator.alloc(u8, len) catch unreachable;
145-
len = @intCast(DWORD, buffer.len);
147+
len = @as(DWORD, @intCast(buffer.len));
146148
res = RegGetValueA(key, null, value, RRF_RT_REG_SZ, null, buffer.ptr, &len);
147149
if (res == ERROR_SUCCESS) {
148150
for (buffer[0..len], 0..) |c, i| {

strings.xml

Whitespace-only changes.

0 commit comments

Comments
 (0)