Skip to content
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

[update] use modified JB #28

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,34 @@ const toolbox = @import ("toolbox");

const Paths = struct
{
glslang: [] const u8 = undefined,
glslang_in: [] const u8 = undefined,
// prefixed attributes
__glslang: [] const u8 = undefined,
__glslang_in: [] const u8 = undefined,

// mandatory getters
pub fn getGlslang (self: @This ()) [] const u8 { return self.__glslang; }
pub fn getGlslangIn (self: @This ()) [] const u8 { return self.__glslang_in; }

// mandatory init
pub fn init (builder: *std.Build) !@This ()
{
var self = @This ()
{
.__glslang = try builder.build_root.join (builder.allocator,
&.{ "glslang", }),
};

self.__glslang_in = try std.fs.path.join (builder.allocator,
&.{ self.getGlslang (), "glslang", });

return self;
}
};

fn update (builder: *std.Build, path: *const Paths,
dependencies: *const toolbox.Dependencies) !void
{
std.fs.deleteTreeAbsolute (path.glslang) catch |err|
std.fs.deleteTreeAbsolute (path.getGlslang ()) catch |err|
{
switch (err)
{
Expand All @@ -19,19 +39,19 @@ fn update (builder: *std.Build, path: *const Paths,
}
};

try dependencies.clone (builder, "glslang", path.glslang);
try dependencies.clone (builder, "glslang", path.getGlslang ());

try toolbox.run (builder, .{ .argv = &[_][] const u8 { "python3",
try std.fs.path.join (builder.allocator,
&.{ path.glslang, "build_info.py", }), path.glslang,
&.{ path.getGlslang (), "build_info.py", }), path.getGlslang (),
"-i", try std.fs.path.join (builder.allocator,
&.{ path.glslang, "build_info.h.tmpl", }),
&.{ path.getGlslang (), "build_info.h.tmpl", }),
"-o", try std.fs.path.join (builder.allocator,
&.{ path.glslang_in, "build_info.h", }),
&.{ path.getGlslangIn (), "build_info.h", }),
}, });

var glslang_dir =
try std.fs.openDirAbsolute (path.glslang, .{ .iterate = true, });
try std.fs.openDirAbsolute (path.getGlslang (), .{ .iterate = true, });
defer glslang_dir.close ();

var it = glslang_dir.iterate ();
Expand All @@ -41,11 +61,11 @@ fn update (builder: *std.Build, path: *const Paths,
!std.mem.eql (u8, "StandAlone", entry.name) and
!std.mem.eql (u8, "glslang", entry.name))
try std.fs.deleteTreeAbsolute (try std.fs.path.join (
builder.allocator, &.{ path.glslang, entry.name, }));
builder.allocator, &.{ path.getGlslang (), entry.name, }));
}

const standalone_path = try std.fs.path.join (builder.allocator,
&.{ path.glslang, "StandAlone", });
&.{ path.getGlslang (), "StandAlone", });

var standalone_dir = try std.fs.openDirAbsolute (standalone_path,
.{ .iterate = true, });
Expand All @@ -67,11 +87,7 @@ pub fn build (builder: *std.Build) !void
const target = builder.standardTargetOptions (.{});
const optimize = builder.standardOptimizeOption (.{});

var path: Paths = .{};
path.glslang =
try builder.build_root.join (builder.allocator, &.{ "glslang", });
path.glslang_in =
try std.fs.path.join (builder.allocator, &.{ path.glslang, "glslang", });
const path = try Paths.init (builder);

const dependencies = try toolbox.Dependencies.init (builder, "glslang.zig",
.{
Expand Down Expand Up @@ -105,13 +121,13 @@ pub fn build (builder: *std.Build) !void
try std.fs.path.join (builder.allocator, &.{ "glslang", "StandAlone", }),
}) |include| toolbox.addInclude (lib, include);

toolbox.addHeader (lib, path.glslang_in, "glslang", &.{ ".h", });
toolbox.addHeader (lib, path.getGlslangIn (), "glslang", &.{ ".h", });
toolbox.addHeader (lib, try std.fs.path.join (builder.allocator,
&.{ path.glslang, "SPIRV", }), "SPIRV", &.{ ".h", });
&.{ path.getGlslang (), "SPIRV", }), "SPIRV", &.{ ".h", });

lib.linkLibCpp ();

var glslang_dir = try std.fs.openDirAbsolute (path.glslang,
var glslang_dir = try std.fs.openDirAbsolute (path.getGlslang (),
.{ .iterate = true, });
defer glslang_dir.close ();

Expand All @@ -129,7 +145,7 @@ pub fn build (builder: *std.Build) !void
if (std.mem.eql (u8, component.name, "OSDependent")) continue :walk;
}
if (toolbox.isCppSource (entry.basename))
try toolbox.addSource (lib, path.glslang, entry.path, &flags);
try toolbox.addSource (lib, path.getGlslang (), entry.path, &flags);
},
else => {},
}
Expand All @@ -143,7 +159,7 @@ pub fn build (builder: *std.Build) !void
};

const os_path = try std.fs.path.join (builder.allocator,
&.{ path.glslang_in, "OSDependent", os, });
&.{ path.getGlslangIn (), "OSDependent", os, });

var os_dir = try std.fs.openDirAbsolute (os_path,
.{ .iterate = true, });
Expand Down