From 2052d6e6b348764ac155a4db225ba3f90f8871ec Mon Sep 17 00:00:00 2001 From: jack Date: Sun, 1 Sep 2024 12:04:37 +0800 Subject: [PATCH] update to 0.14.0-dev.1391+e084c46ed --- build.zig | 102 +++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/build.zig b/build.zig index 48717e9..e03ed12 100644 --- a/build.zig +++ b/build.zig @@ -123,7 +123,7 @@ const SdkOption = struct { maybe_sdl_ttf_config_path: ?[]const u8 = null, }; -build: *Build, +builder: *Build, sdl_config_path: []const u8, prepare_sources: *PrepareStubSourceStep, @@ -150,7 +150,7 @@ pub fn init(b: *Build, opt: SdkOption) *Sdk { b; sdk.* = .{ - .build = builder, + .builder = builder, .sdl_config_path = sdl_config_path, .sdl_ttf_config_path = sdl_ttf_config_path, .prepare_sources = undefined, @@ -164,13 +164,13 @@ pub fn init(b: *Build, opt: SdkOption) *Sdk { /// for a more *ziggy* feeling. /// This is similar to the *C import* result. pub fn getNativeModule(sdk: *Sdk) *Build.Module { - const build_options = sdk.build.addOptions(); + const build_options = sdk.builder.addOptions(); build_options.addOption(bool, "vulkan", false); - return sdk.build.createModule(.{ - .root_source_file = sdk.build.path("src/binding/sdl.zig"), + return sdk.builder.createModule(.{ + .root_source_file = sdk.builder.path("src/binding/sdl.zig"), .imports = &.{ .{ - .name = sdk.build.dupe("build_options"), + .name = sdk.builder.dupe("build_options"), .module = build_options.createModule(), }, }, @@ -182,17 +182,17 @@ pub fn getNativeModule(sdk: *Sdk) *Build.Module { /// provided as an argument. /// This is similar to the *C import* result. pub fn getNativeModuleVulkan(sdk: *Sdk, vulkan: *Build.Module) *Build.Module { - const build_options = sdk.build.addOptions(); + const build_options = sdk.builder.addOptions(); build_options.addOption(bool, "vulkan", true); - return sdk.build.createModule(.{ - .root_source_file = sdk.build.path("src/binding/sdl.zig"), + return sdk.builder.createModule(.{ + .root_source_file = sdk.builder.path("src/binding/sdl.zig"), .imports = &.{ .{ - .name = sdk.build.dupe("build_options"), + .name = sdk.builder.dupe("build_options"), .module = build_options.createModule(), }, .{ - .name = sdk.build.dupe("vulkan"), + .name = sdk.builder.dupe("vulkan"), .module = vulkan, }, }, @@ -201,11 +201,11 @@ pub fn getNativeModuleVulkan(sdk: *Sdk, vulkan: *Build.Module) *Build.Module { /// Returns the smart wrapper for the SDL api. Contains convenient zig types, tagged unions and so on. pub fn getWrapperModule(sdk: *Sdk) *Build.Module { - return sdk.build.createModule(.{ - .root_source_file = sdk.build.path("src/wrapper/sdl.zig"), + return sdk.builder.createModule(.{ + .root_source_file = sdk.builder.path("src/wrapper/sdl.zig"), .imports = &.{ .{ - .name = sdk.build.dupe("sdl-native"), + .name = sdk.builder.dupe("sdl-native"), .module = sdk.getNativeModule(), }, }, @@ -215,15 +215,15 @@ pub fn getWrapperModule(sdk: *Sdk) *Build.Module { /// Returns the smart wrapper with Vulkan support. The Vulkan module provided by `vulkan-zig` must be /// provided as an argument. pub fn getWrapperModuleVulkan(sdk: *Sdk, vulkan: *Build.Module) *Build.Module { - return sdk.build.createModule(.{ - .root_source_file = sdk.build.path("src/wrapper/sdl.zig"), + return sdk.builder.createModule(.{ + .root_source_file = sdk.builder.path("src/wrapper/sdl.zig"), .imports = &.{ .{ - .name = sdk.build.dupe("sdl-native"), + .name = sdk.builder.dupe("sdl-native"), .module = sdk.getNativeModuleVulkan(vulkan), }, .{ - .name = sdk.build.dupe("vulkan"), + .name = sdk.builder.dupe("vulkan"), .module = vulkan, }, }, @@ -231,7 +231,7 @@ pub fn getWrapperModuleVulkan(sdk: *Sdk, vulkan: *Build.Module) *Build.Module { } fn linkLinuxCross(sdk: *Sdk, exe: *Compile) !void { - const build_linux_sdl_stub = sdk.build.addSharedLibrary(.{ + const build_linux_sdl_stub = sdk.builder.addSharedLibrary(.{ .name = "SDL2", .target = exe.root_module.resolved_target.?, .optimize = exe.root_module.optimize.?, @@ -258,14 +258,14 @@ fn linkWindows( if (exe.root_module.resolved_target.?.result.abi == .msvc) { exe.linkSystemLibrary2(lib_name, .{ .use_pkg_config = .no }); } else { - const file_name = try std.fmt.allocPrint(sdk.build.allocator, "lib{s}.{s}", .{ + const file_name = try std.fmt.allocPrint(sdk.builder.allocator, "lib{s}.{s}", .{ lib_name, if (linkage == .static) "a" else "dll.a", }); - defer sdk.build.allocator.free(file_name); + defer sdk.builder.allocator.free(file_name); - const lib_path = try std.fs.path.join(sdk.build.allocator, &[_][]const u8{ paths.libs, file_name }); - defer sdk.build.allocator.free(lib_path); + const lib_path = try std.fs.path.join(sdk.builder.allocator, &[_][]const u8{ paths.libs, file_name }); + defer sdk.builder.allocator.free(lib_path); exe.addObjectFile(.{ .cwd_relative = lib_path }); @@ -287,13 +287,13 @@ fn linkWindows( } if (linkage == .dynamic and exe.kind == .exe) { - const dll_name = try std.fmt.allocPrint(sdk.build.allocator, "{s}.dll", .{lib_name}); - defer sdk.build.allocator.free(dll_name); + const dll_name = try std.fmt.allocPrint(sdk.builder.allocator, "{s}.dll", .{lib_name}); + defer sdk.builder.allocator.free(dll_name); - const dll_path = try std.fs.path.join(sdk.build.allocator, &[_][]const u8{ paths.bin, dll_name }); - defer sdk.build.allocator.free(dll_path); + const dll_path = try std.fs.path.join(sdk.builder.allocator, &[_][]const u8{ paths.bin, dll_name }); + defer sdk.builder.allocator.free(dll_path); - const install_bin = sdk.build.addInstallBinFile(.{ .cwd_relative = dll_path }, dll_name); + const install_bin = sdk.builder.addInstallBinFile(.{ .cwd_relative = dll_path }, dll_name); exe.step.dependOn(&install_bin.step); } } @@ -335,7 +335,7 @@ pub fn link( linkage: std.builtin.LinkMode, comptime library: Library, ) void { - const b = sdk.build; + const b = sdk.builder; const target = exe.root_module.resolved_target.?; const is_native = target.query.isNativeOs(); @@ -402,8 +402,8 @@ const GetPathsError = error{ fn printPathsErrorMessage(sdk: *Sdk, config_path: []const u8, target_local: std.Build.ResolvedTarget, err: GetPathsError, library: Library) !void { const writer = std.io.getStdErr().writer(); - const target_name = try tripleName(sdk.build.allocator, target_local); - defer sdk.build.allocator.free(target_name); + const target_name = try tripleName(sdk.builder.allocator, target_local); + defer sdk.builder.allocator.free(target_name); const lib_name = switch (library) { .SDL2 => "SDL2", @@ -458,7 +458,7 @@ fn printPathsErrorMessage(sdk: *Sdk, config_path: []const u8, target_local: std. } fn getPaths(sdk: *Sdk, config_path: []const u8, target_local: std.Build.ResolvedTarget, library: Library) GetPathsError!Paths { - const json_data = std.fs.cwd().readFileAlloc(sdk.build.allocator, config_path, 1 << 20) catch |err| switch (err) { + const json_data = std.fs.cwd().readFileAlloc(sdk.builder.allocator, config_path, 1 << 20) catch |err| switch (err) { error.FileNotFound => { printPathsErrorMessage(sdk, config_path, target_local, GetPathsError.FileNotFound, library) catch |e| { std.debug.panic("Failed to print error message: {s}", .{@errorName(e)}); @@ -470,9 +470,9 @@ fn getPaths(sdk: *Sdk, config_path: []const u8, target_local: std.Build.Resolved return GetPathsError.FileNotFound; }, }; - defer sdk.build.allocator.free(json_data); + defer sdk.builder.allocator.free(json_data); - const parsed = std.json.parseFromSlice(std.json.Value, sdk.build.allocator, json_data, .{}) catch { + const parsed = std.json.parseFromSlice(std.json.Value, sdk.builder.allocator, json_data, .{}) catch { printPathsErrorMessage(sdk, config_path, target_local, GetPathsError.InvalidJson, library) catch |e| { std.debug.panic("Failed to print error message: {s}", .{@errorName(e)}); }; @@ -483,7 +483,7 @@ fn getPaths(sdk: *Sdk, config_path: []const u8, target_local: std.Build.Resolved var root_node = parsed.value.object; var config_iterator = root_node.iterator(); while (config_iterator.next()) |entry| { - const config_target = sdk.build.resolveTargetQuery( + const config_target = sdk.builder.resolveTargetQuery( std.Target.Query.parse(.{ .arch_os_abi = entry.key_ptr.* }) catch { std.log.err("Invalid target in config file: {s}", .{entry.key_ptr.*}); return GetPathsError.InvalidTarget; @@ -500,9 +500,9 @@ fn getPaths(sdk: *Sdk, config_path: []const u8, target_local: std.Build.Resolved const node = entry.value_ptr.*.object; return Paths{ - .include = sdk.build.allocator.dupe(u8, node.get("include").?.string) catch @panic("out of memory"), - .libs = sdk.build.allocator.dupe(u8, node.get("libs").?.string) catch @panic("out of memory"), - .bin = sdk.build.allocator.dupe(u8, node.get("bin").?.string) catch @panic("out of memory"), + .include = sdk.builder.allocator.dupe(u8, node.get("include").?.string) catch @panic("out of memory"), + .libs = sdk.builder.allocator.dupe(u8, node.get("libs").?.string) catch @panic("out of memory"), + .bin = sdk.builder.allocator.dupe(u8, node.get("bin").?.string) catch @panic("out of memory"), }; } @@ -521,14 +521,14 @@ const PrepareStubSourceStep = struct { assembly_source: GeneratedFile, pub fn create(sdk: *Sdk) *PrepareStubSourceStep { - const psss = sdk.build.allocator.create(Self) catch @panic("out of memory"); + const psss = sdk.builder.allocator.create(Self) catch @panic("out of memory"); psss.* = .{ .step = Step.init( .{ .id = .custom, .name = "Prepare SDL2 stub sources", - .owner = sdk.build, + .owner = sdk.builder, .makeFn = make, }, ), @@ -547,7 +547,7 @@ const PrepareStubSourceStep = struct { _ = make_opt; const self: *Self = @fieldParentPtr("step", step); - var cache = CacheBuilder.init(self.sdk.build, "sdl"); + var cache = CacheBuilder.init(self.sdk.builder, "sdl"); cache.addBytes(sdl2_symbol_definitions); @@ -571,7 +571,7 @@ const PrepareStubSourceStep = struct { try writer.writeAll(" .byte 0\n"); } - self.assembly_source.path = try std.fs.path.join(self.sdk.build.allocator, &[_][]const u8{ + self.assembly_source.path = try std.fs.path.join(self.sdk.builder.allocator, &[_][]const u8{ dirpath.path, "sdl.S", }); @@ -589,13 +589,13 @@ fn tripleName(allocator: std.mem.Allocator, target_local: std.Build.ResolvedTarg const CacheBuilder = struct { const Self = @This(); - build: *std.Build, + builder: *std.Build, hasher: std.crypto.hash.Sha1, subdir: ?[]const u8, pub fn init(builder: *std.Build, subdir: ?[]const u8) Self { return Self{ - .build = builder, + .builder = builder, .hasher = std.crypto.hash.Sha1.init(.{}), .subdir = if (subdir) |s| builder.dupe(s) @@ -609,10 +609,10 @@ const CacheBuilder = struct { } pub fn addFile(self: *Self, file: LazyPath) !void { - const path = file.getPath(self.build); + const path = file.getPath(self.builder); - const data = try std.fs.cwd().readFileAlloc(self.build.allocator, path, 1 << 32); // 4 GB - defer self.build.allocator.free(data); + const data = try std.fs.cwd().readFileAlloc(self.builder.allocator, path, 1 << 32); // 4 GB + defer self.builder.allocator.free(data); self.addBytes(data); } @@ -623,20 +623,20 @@ const CacheBuilder = struct { const path = if (self.subdir) |subdir| try std.fmt.allocPrint( - self.build.allocator, + self.builder.allocator, "{s}/{s}/o/{}", .{ - self.build.cache_root.path.?, + self.builder.cache_root.path.?, subdir, std.fmt.fmtSliceHexLower(&hash), }, ) else try std.fmt.allocPrint( - self.build.allocator, + self.builder.allocator, "{s}/o/{}", .{ - self.build.cache_root.path.?, + self.builder.cache_root.path.?, std.fmt.fmtSliceHexLower(&hash), }, );