Skip to content

Commit

Permalink
Merge pull request #199 from Jack-Ji/master
Browse files Browse the repository at this point in the history
update to 0.14.0-dev.1391+e084c46ed
  • Loading branch information
ikskuh authored Sep 2, 2024
2 parents 172a84e + 2052d6e commit 38ca4ef
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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(),
},
},
Expand All @@ -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,
},
},
Expand All @@ -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(),
},
},
Expand All @@ -215,23 +215,23 @@ 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,
},
},
});
}

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.?,
Expand All @@ -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 });

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)});
Expand All @@ -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)});
};
Expand All @@ -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;
Expand All @@ -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"),
};
}

Expand All @@ -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,
},
),
Expand All @@ -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);

Expand All @@ -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",
});
Expand All @@ -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)
Expand All @@ -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);
}
Expand All @@ -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),
},
);
Expand Down

0 comments on commit 38ca4ef

Please sign in to comment.