gpu-dawn: remove xcode_frameworks submodule; Sdk type
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
5aa06c2234
commit
2caffc8d35
4 changed files with 1682 additions and 1594 deletions
|
|
@ -3,11 +3,7 @@ const builtin = @import("builtin");
|
||||||
const freetype = @import("libs/freetype/build.zig");
|
const freetype = @import("libs/freetype/build.zig");
|
||||||
const glfw = @import("libs/glfw/build.zig");
|
const glfw = @import("libs/glfw/build.zig");
|
||||||
const sysaudio = @import("mach_sysaudio");
|
const sysaudio = @import("mach_sysaudio");
|
||||||
pub const gpu_dawn = @import("libs/gpu-dawn/build.zig").Sdk(.{
|
pub const gpu_dawn = @import("libs/gpu-dawn/build.zig"); // TODO(build-system): make this private
|
||||||
// TODO(build-system): This cannot be imported with the Zig package manager
|
|
||||||
// error: TarUnsupportedFileType
|
|
||||||
.xcode_frameworks = @import("libs/gpu-dawn/libs/xcode-frameworks/build.zig"),
|
|
||||||
});
|
|
||||||
const gpu = @import("libs/gpu/build.zig").Sdk(.{
|
const gpu = @import("libs/gpu/build.zig").Sdk(.{
|
||||||
.gpu_dawn = gpu_dawn,
|
.gpu_dawn = gpu_dawn,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const glfw = @import("libs/mach-glfw/build.zig");
|
const glfw = @import("libs/mach-glfw/build.zig");
|
||||||
const gpu_dawn = @import("libs/mach-gpu-dawn/build.zig").Sdk(.{
|
const gpu_dawn = @import("libs/mach-gpu-dawn/build.zig");
|
||||||
// TODO(build-system): This cannot be imported with the Zig package manager
|
|
||||||
// error: TarUnsupportedFileType
|
|
||||||
.xcode_frameworks = @import("libs/mach-gpu-dawn/libs/xcode-frameworks/build.zig"),
|
|
||||||
});
|
|
||||||
const gpu = @import("libs/mach-gpu/build.zig").Sdk(.{
|
const gpu = @import("libs/mach-gpu/build.zig").Sdk(.{
|
||||||
.gpu_dawn = gpu_dawn,
|
.gpu_dawn = gpu_dawn,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,7 @@ pub fn build(b: *Build) !void {
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const glfw = @import("libs/mach-glfw/build.zig");
|
const glfw = @import("libs/mach-glfw/build.zig");
|
||||||
const gpu_dawn = Sdk(.{
|
const options = Options{
|
||||||
// TODO(build-system): This cannot be imported with the Zig package manager
|
|
||||||
// error: TarUnsupportedFileType
|
|
||||||
.xcode_frameworks = @import("libs/xcode-frameworks/build.zig"),
|
|
||||||
});
|
|
||||||
|
|
||||||
const options = gpu_dawn.Options{
|
|
||||||
.install_libs = true,
|
.install_libs = true,
|
||||||
.from_source = true,
|
.from_source = true,
|
||||||
};
|
};
|
||||||
|
|
@ -24,14 +18,12 @@ pub fn build(b: *Build) !void {
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
try gpu_dawn.link(b, example, options);
|
try link(b, example, options);
|
||||||
try glfw.link(b, example, .{});
|
try glfw.link(b, example, .{});
|
||||||
example.addModule("glfw", glfw.module(b));
|
example.addModule("glfw", glfw.module(b));
|
||||||
b.installArtifact(example);
|
b.installArtifact(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Sdk(comptime deps: anytype) type {
|
|
||||||
return struct {
|
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
/// Defaults to true on Windows
|
/// Defaults to true on Windows
|
||||||
d3d12: ?bool = null,
|
d3d12: ?bool = null,
|
||||||
|
|
@ -101,7 +93,7 @@ pub fn Sdk(comptime deps: anytype) type {
|
||||||
// .optimize = step.optimize,
|
// .optimize = step.optimize,
|
||||||
// }).artifact("xcode-frameworks"));
|
// }).artifact("xcode-frameworks"));
|
||||||
// @import("xcode_frameworks").addPaths(step);
|
// @import("xcode_frameworks").addPaths(step);
|
||||||
deps.xcode_frameworks.addPaths(step);
|
xcode_frameworks.addPaths(b, step);
|
||||||
}
|
}
|
||||||
|
|
||||||
try if (options.from_source)
|
try if (options.from_source)
|
||||||
|
|
@ -592,7 +584,7 @@ pub fn Sdk(comptime deps: anytype) type {
|
||||||
// .optimize = step.optimize,
|
// .optimize = step.optimize,
|
||||||
// }).artifact("xcode-frameworks"));
|
// }).artifact("xcode-frameworks"));
|
||||||
// @import("xcode_frameworks").addPaths(step);
|
// @import("xcode_frameworks").addPaths(step);
|
||||||
deps.xcode_frameworks.addPaths(step);
|
xcode_frameworks.addPaths(b, step);
|
||||||
|
|
||||||
step.linkSystemLibraryName("objc");
|
step.linkSystemLibraryName("objc");
|
||||||
step.linkFramework("Foundation");
|
step.linkFramework("Foundation");
|
||||||
|
|
@ -744,7 +736,7 @@ pub fn Sdk(comptime deps: anytype) type {
|
||||||
// .optimize = step.optimize,
|
// .optimize = step.optimize,
|
||||||
// }).artifact("xcode-frameworks"));
|
// }).artifact("xcode-frameworks"));
|
||||||
// @import("xcode_frameworks").addPaths(step);
|
// @import("xcode_frameworks").addPaths(step);
|
||||||
deps.xcode_frameworks.addPaths(step);
|
xcode_frameworks.addPaths(b, step);
|
||||||
|
|
||||||
step.linkSystemLibraryName("objc");
|
step.linkSystemLibraryName("objc");
|
||||||
step.linkFramework("Metal");
|
step.linkFramework("Metal");
|
||||||
|
|
@ -1292,7 +1284,7 @@ pub fn Sdk(comptime deps: anytype) type {
|
||||||
// .optimize = step.optimize,
|
// .optimize = step.optimize,
|
||||||
// }).artifact("xcode-frameworks"));
|
// }).artifact("xcode-frameworks"));
|
||||||
// @import("xcode_frameworks").addPaths(step);
|
// @import("xcode_frameworks").addPaths(step);
|
||||||
deps.xcode_frameworks.addPaths(step);
|
xcode_frameworks.addPaths(b, step);
|
||||||
|
|
||||||
step.linkSystemLibraryName("objc");
|
step.linkSystemLibraryName("objc");
|
||||||
step.linkFramework("CoreFoundation");
|
step.linkFramework("CoreFoundation");
|
||||||
|
|
@ -1626,5 +1618,113 @@ pub fn Sdk(comptime deps: anytype) type {
|
||||||
break :blk root_dir ++ suffix;
|
break :blk root_dir ++ suffix;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(build-system): This is a workaround that we copy anywhere xcode_frameworks needs to be used.
|
||||||
|
// With the Zig package manager, it should be possible to remove this entirely and instead just
|
||||||
|
// write:
|
||||||
|
//
|
||||||
|
// ```
|
||||||
|
// step.linkLibrary(b.dependency("xcode_frameworks", .{
|
||||||
|
// .target = step.target,
|
||||||
|
// .optimize = step.optimize,
|
||||||
|
// }).artifact("xcode-frameworks"));
|
||||||
|
// @import("xcode_frameworks").addPaths(step);
|
||||||
|
// ```
|
||||||
|
//
|
||||||
|
// However, today this package cannot be imported with the Zig package manager due to `error: TarUnsupportedFileType`
|
||||||
|
// which would be fixed by https://github.com/ziglang/zig/pull/15382 - so instead for now you must
|
||||||
|
// copy+paste this struct into your `build.zig` and write:
|
||||||
|
//
|
||||||
|
// ```
|
||||||
|
// try xcode_frameworks.addPaths(b, step);
|
||||||
|
// ```
|
||||||
|
const xcode_frameworks = struct {
|
||||||
|
pub fn addPaths(b: *std.Build, step: *std.build.CompileStep) void {
|
||||||
|
// branch: mach
|
||||||
|
ensureGitRepoCloned(b.allocator, "https://github.com/hexops/xcode-frameworks", "723aa55e9752c8c6c25d3413722b5fe13d72ac4f", "zig-cache/xcode_frameworks") catch |err| @panic(@errorName(err));
|
||||||
|
|
||||||
|
step.addFrameworkPath("zig-cache/xcode_frameworks/Frameworks");
|
||||||
|
step.addSystemIncludePath("zig-cache/xcode_frameworks/include");
|
||||||
|
step.addLibraryPath("zig-cache/xcode_frameworks/lib");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn xcodeSdkPath(comptime suffix: []const u8) []const u8 {
|
||||||
|
if (suffix[0] != '/') @compileError("suffix must be an absolute path");
|
||||||
|
return comptime blk: {
|
||||||
|
const root_dir = std.fs.path.dirname(@src().file) orelse ".";
|
||||||
|
break :blk root_dir ++ suffix;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ensureGitRepoCloned(allocator: std.mem.Allocator, clone_url: []const u8, revision: []const u8, rel_dir: []const u8) !void {
|
||||||
|
if (isEnvVarTruthy(allocator, "NO_ENSURE_SUBMODULES") or isEnvVarTruthy(allocator, "NO_ENSURE_GIT")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ensureGit(allocator);
|
||||||
|
|
||||||
|
if (std.fs.cwd().realpathAlloc(allocator, rel_dir)) |dir| {
|
||||||
|
const current_revision = try getCurrentGitRevision(allocator, dir);
|
||||||
|
if (!std.mem.eql(u8, current_revision, revision)) {
|
||||||
|
// Reset to the desired revision
|
||||||
|
exec(allocator, &[_][]const u8{ "git", "fetch" }, dir) catch |err| std.debug.print("warning: failed to 'git fetch' in {s}: {s}\n", .{ dir, @errorName(err) });
|
||||||
|
try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir);
|
||||||
|
try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else |err| return switch (err) {
|
||||||
|
error.FileNotFound => {
|
||||||
|
std.log.info("cloning required dependency..\ngit clone {s} {s}..\n", .{ clone_url, rel_dir });
|
||||||
|
|
||||||
|
try exec(allocator, &[_][]const u8{ "git", "clone", "-c", "core.longpaths=true", clone_url, rel_dir }, xcodeSdkPath("/"));
|
||||||
|
try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, rel_dir);
|
||||||
|
try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, rel_dir);
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
else => err,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exec(allocator: std.mem.Allocator, argv: []const []const u8, cwd: []const u8) !void {
|
||||||
|
var child = std.ChildProcess.init(argv, allocator);
|
||||||
|
child.cwd = cwd;
|
||||||
|
_ = try child.spawnAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn getCurrentGitRevision(allocator: std.mem.Allocator, cwd: []const u8) ![]const u8 {
|
||||||
|
const result = try std.ChildProcess.exec(.{ .allocator = allocator, .argv = &.{ "git", "rev-parse", "HEAD" }, .cwd = cwd });
|
||||||
|
allocator.free(result.stderr);
|
||||||
|
if (result.stdout.len > 0) return result.stdout[0 .. result.stdout.len - 1]; // trim newline
|
||||||
|
return result.stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ensureGit(allocator: std.mem.Allocator) void {
|
||||||
|
const argv = &[_][]const u8{ "git", "--version" };
|
||||||
|
const result = std.ChildProcess.exec(.{
|
||||||
|
.allocator = allocator,
|
||||||
|
.argv = argv,
|
||||||
|
.cwd = ".",
|
||||||
|
}) catch { // e.g. FileNotFound
|
||||||
|
std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{});
|
||||||
|
std.process.exit(1);
|
||||||
|
};
|
||||||
|
defer {
|
||||||
|
allocator.free(result.stderr);
|
||||||
|
allocator.free(result.stdout);
|
||||||
|
}
|
||||||
|
if (result.term.Exited != 0) {
|
||||||
|
std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{});
|
||||||
|
std.process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn isEnvVarTruthy(allocator: std.mem.Allocator, name: []const u8) bool {
|
||||||
|
if (std.process.getEnvVarOwned(allocator, name)) |truthy| {
|
||||||
|
defer allocator.free(truthy);
|
||||||
|
if (std.mem.eql(u8, truthy, "true")) return true;
|
||||||
|
return false;
|
||||||
|
} else |_| {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,7 @@ pub fn build(b: *std.Build) !void {
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const glfw = @import("libs/mach-glfw/build.zig");
|
const glfw = @import("libs/mach-glfw/build.zig");
|
||||||
const gpu_dawn = @import("libs/mach-gpu-dawn/build.zig").Sdk(.{
|
const gpu_dawn = @import("libs/mach-gpu-dawn/build.zig");
|
||||||
// TODO(build-system): This cannot be imported with the Zig package manager
|
|
||||||
// error: TarUnsupportedFileType
|
|
||||||
.xcode_frameworks = @import("libs/mach-gpu-dawn/libs/xcode-frameworks/build.zig"),
|
|
||||||
});
|
|
||||||
const gpu = Sdk(.{
|
const gpu = Sdk(.{
|
||||||
.gpu_dawn = gpu_dawn,
|
.gpu_dawn = gpu_dawn,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue