-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial Zig 12 support #36
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,9 @@ fn sdkRoot() *const [sdkRootIntern().len]u8 { | |
|
||
// linux-x86_64 | ||
pub fn toolchainHostTag() []const u8 { | ||
comptime { | ||
const os = builtin.os.tag; | ||
const arch = builtin.cpu.arch; | ||
return @tagName(os) ++ "-" ++ @tagName(arch); | ||
} | ||
const os = builtin.os.tag; | ||
const arch = builtin.cpu.arch; | ||
return (comptime if (std.mem.eql(u8, @tagName(os), "macos")) "darwin" else @tagName(os)) ++ "-" ++ @tagName(arch); | ||
} | ||
|
||
/// This file encodes a instance of an Android SDK interface. | ||
|
@@ -92,12 +90,12 @@ pub fn init(b: *Builder, user_config: ?UserConfig, toolchains: ToolchainVersions | |
.name = "zip_add", | ||
.root_source_file = .{ .path = sdkRoot() ++ "/tools/zip_add.zig" }, | ||
}); | ||
zip_add.addCSourceFile(sdkRoot() ++ "/vendor/kuba-zip/zip.c", &[_][]const u8{ | ||
zip_add.addCSourceFile(.{ .file = .{ .path = sdkRoot() ++ "/vendor/kuba-zip/zip.c" }, .flags = &[_][]const u8{ | ||
"-std=c99", | ||
"-fno-sanitize=undefined", | ||
"-D_POSIX_C_SOURCE=200112L", | ||
}); | ||
zip_add.addIncludePath(sdkRoot() ++ "/vendor/kuba-zip"); | ||
} }); | ||
zip_add.addIncludePath(.{ .path = sdkRoot() ++ "/vendor/kuba-zip" }); | ||
zip_add.linkLibC(); | ||
|
||
break :blk HostTools{ | ||
|
@@ -503,10 +501,11 @@ pub fn createApp( | |
} | ||
resource_dir_step.add(Resource{ | ||
.path = "values/strings.xml", | ||
.content = write_xml_step.getFileSource("strings.xml").?, | ||
// .content = write_xml_step.getFileSource("strings.xml").?, | ||
.content = write_xml_step.addCopyFile(.{ .path = "strings.xml" }, ""), | ||
}); | ||
|
||
const sdk_version_int = @enumToInt(app_config.target_version); | ||
const sdk_version_int = @intFromEnum(app_config.target_version); | ||
|
||
if (sdk_version_int < 16) @panic("Minimum supported sdk version is 16."); | ||
|
||
|
@@ -549,7 +548,8 @@ pub fn createApp( | |
const unaligned_apk_file = make_unsigned_apk.addOutputFileArg(unaligned_apk_name); | ||
|
||
make_unsigned_apk.addArg("-M"); // specify full path to AndroidManifest.xml to include in zip | ||
make_unsigned_apk.addFileSourceArg(manifest_step.getFileSource("AndroidManifest.xml").?); | ||
// make_unsigned_apk.addFileSourceArg(manifest_step.getFileSource("AndroidManifest.xml").?); | ||
make_unsigned_apk.addFileSourceArg(manifest_step.addCopyFile(.{ .path = "AndroidManifest.xml" }, "")); | ||
|
||
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 | ||
make_unsigned_apk.addDirectorySourceArg(resource_dir_step.getOutputDirectory()); | ||
|
@@ -848,7 +848,7 @@ pub fn compileAppLibrary( | |
ndk_root, | ||
toolchainHostTag(), | ||
config.lib_dir, | ||
@enumToInt(app_config.target_version), | ||
@intFromEnum(app_config.target_version), | ||
}); | ||
|
||
const include_dir = std.fs.path.resolve(sdk.b.allocator, &[_][]const u8{ | ||
|
@@ -887,7 +887,7 @@ pub fn compileAppLibrary( | |
|
||
// exe.addIncludePath(include_dir); | ||
|
||
exe.addLibraryPath(lib_dir); | ||
exe.addLibraryPath(.{ .path = lib_dir }); | ||
|
||
// exe.addIncludePath(include_dir); | ||
// exe.addIncludePath(system_include_dir); | ||
|
@@ -904,7 +904,7 @@ pub fn compileAppLibrary( | |
} | ||
|
||
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 { | ||
const fname = sdk.b.fmt("android-{d}-{s}.conf", .{ @enumToInt(version), folder_name }); | ||
const fname = sdk.b.fmt("android-{d}-{s}.conf", .{ @intFromEnum(version), folder_name }); | ||
|
||
var contents = std.ArrayList(u8).init(sdk.b.allocator); | ||
errdefer contents.deinit(); | ||
|
@@ -926,7 +926,8 @@ fn createLibCFile(sdk: *const Sdk, version: AndroidVersion, folder_name: []const | |
try writer.writeAll("gcc_dir=\n"); | ||
|
||
const step = sdk.b.addWriteFile(fname, contents.items); | ||
return step.getFileSource(fname) orelse unreachable; | ||
// return step.getFileSource(fname) orelse unreachable; | ||
return step.addCopyFile(.{ .path = fname }, ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
pub fn compressApk(sdk: Sdk, input_apk_file: []const u8, output_apk_file: []const u8) *Step { | ||
|
@@ -1151,22 +1152,22 @@ const BuildOptionStep = struct { | |
} | ||
return; | ||
}, | ||
std.builtin.Version => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't found this type in the standard library, so I removed it for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zig 0.11.0 release notes address this: https://ziglang.org/download/0.11.0/release-notes.html#Language-Changes
Since SemanticVersion is already implemented below this code, we can go ahead and delete the |
||
out.print( | ||
\\pub const {}: @import("std").builtin.Version = .{{ | ||
\\ .major = {d}, | ||
\\ .minor = {d}, | ||
\\ .patch = {d}, | ||
\\}}; | ||
\\ | ||
, .{ | ||
std.zig.fmtId(name), | ||
|
||
value.major, | ||
value.minor, | ||
value.patch, | ||
}) catch unreachable; | ||
}, | ||
// std.builtin.Version => { | ||
// out.print( | ||
// \\pub const {}: @import("std").builtin.Version = .{{ | ||
// \\ .major = {d}, | ||
// \\ .minor = {d}, | ||
// \\ .patch = {d}, | ||
// \\}}; | ||
// \\ | ||
// , .{ | ||
// std.zig.fmtId(name), | ||
|
||
// value.major, | ||
// value.minor, | ||
// value.patch, | ||
// }) catch unreachable; | ||
// }, | ||
std.SemanticVersion => { | ||
out.print( | ||
\\pub const {}: @import("std").SemanticVersion = .{{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,17 +24,19 @@ pub fn findUserConfig(b: *Builder, versions: Sdk.ToolchainVersions) !UserConfig | |
// Check for a user config file. | ||
if (std.fs.cwd().openFile(config_path, .{})) |file| { | ||
defer file.close(); | ||
const bytes = file.readToEndAlloc(b.allocator, 1 * 1000 * 1000) catch |err| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't figured out the new Json api, it's hard because I haven't used the previous one. |
||
print("Unexpected error reading {s}: {s}\n", .{ config_path, @errorName(err) }); | ||
return err; | ||
}; | ||
var stream = std.json.TokenStream.init(bytes); | ||
if (std.json.parse(UserConfig, &stream, .{ .allocator = b.allocator })) |conf| { | ||
config = conf; | ||
} else |err| { | ||
print("Could not parse {s} ({s}).\n", .{ config_path, @errorName(err) }); | ||
return err; | ||
} | ||
// @panic("Config file not supported yet"); | ||
std.debug.print("Config file: TODO\n", .{}); | ||
// const bytes = file.readToEndAlloc(b.allocator, 1 * 1000 * 1000) catch |err| { | ||
// print("Unexpected error reading {s}: {s}\n", .{ config_path, @errorName(err) }); | ||
// return err; | ||
// }; | ||
// var stream = std.json.TokenStream.init(bytes); | ||
// if (std.json.parse(UserConfig, &stream, .{ .allocator = b.allocator })) |conf| { | ||
// config = conf; | ||
// } else |err| { | ||
// print("Could not parse {s} ({s}).\n", .{ config_path, @errorName(err) }); | ||
// return err; | ||
// } | ||
Jomy10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else |err| switch (err) { | ||
error.FileNotFound => { | ||
config_dirty = true; | ||
|
@@ -99,10 +101,10 @@ pub fn findUserConfig(b: *Builder, versions: Sdk.ToolchainVersions) !UserConfig | |
const LSTATUS = u32; | ||
const DWORD = u32; | ||
|
||
// const HKEY_CLASSES_ROOT = @intToPtr(HKEY, 0x80000000); | ||
const HKEY_CURRENT_USER = @intToPtr(HKEY, 0x80000001); | ||
const HKEY_LOCAL_MACHINE = @intToPtr(HKEY, 0x80000002); | ||
// const HKEY_USERS = @intToPtr(HKEY, 0x80000003); | ||
// const HKEY_CLASSES_ROOT: HKEY= @ptrFromInt(0x80000000); | ||
const HKEY_CURRENT_USER: HKEY = @ptrFromInt(0x80000001); | ||
const HKEY_LOCAL_MACHINE: HKEY = @ptrFromInt(0x80000002); | ||
// const HKEY_USERS: HKEY= @ptrFromInt(0x80000003); | ||
|
||
// const RRF_RT_ANY: DWORD = 0xFFFF; | ||
// const RRF_RT_REG_BINARY: DWORD = 0x08; | ||
|
@@ -142,7 +144,7 @@ pub fn findUserConfig(b: *Builder, versions: Sdk.ToolchainVersions) !UserConfig | |
|
||
// get the data | ||
const buffer = allocator.alloc(u8, len) catch unreachable; | ||
len = @intCast(DWORD, buffer.len); | ||
len = @as(DWORD, @intCast(buffer.len)); | ||
res = RegGetValueA(key, null, value, RRF_RT_REG_SZ, null, buffer.ptr, &len); | ||
if (res == ERROR_SUCCESS) { | ||
for (buffer[0..len], 0..) |c, i| { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
android uses "darwin" tag instead of "macos" as zig does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect you're the first mac use to try this out! Thank you :)