replace module() helper; remove invalid re-exports;

Fixes hexops/mach#1041
Helps hexops/mach#1038

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-09-24 17:20:40 -07:00
parent 2615afaaed
commit 4e091f1cb8
3 changed files with 65 additions and 50 deletions

View file

@ -6,48 +6,48 @@ const core = @import("mach_core");
var _module: ?*std.build.Module = null;
pub fn module(b: *std.Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *std.build.Module {
if (_module) |m| return m;
const mach_core = b.dependency("mach_core", .{
.target = target,
.optimize = optimize,
});
const mach_sysaudio = b.dependency("mach_sysaudio", .{
.target = target,
.optimize = optimize,
});
const mach_ecs = b.dependency("mach_ecs", .{
.target = target,
.optimize = optimize,
});
const mach_basisu = b.dependency("mach_basisu", .{
.target = target,
.optimize = optimize,
});
const mach_freetype = b.dependency("mach_freetype", .{
.target = target,
.optimize = optimize,
});
_module = b.createModule(.{
.source_file = .{ .path = sdkPath("/src/main.zig") },
.dependencies = &.{
.{ .name = "mach-core", .module = core.module(mach_core.builder, optimize, target) },
.{ .name = "mach-ecs", .module = mach_ecs.module("mach-ecs") },
.{ .name = "mach-sysaudio", .module = sysaudio.module(mach_sysaudio.builder, optimize, target) },
.{ .name = "mach-basisu", .module = mach_basisu.module("mach-basisu") },
.{ .name = "mach-freetype", .module = mach_freetype.module("mach-freetype") },
.{ .name = "mach-harfbuzz", .module = mach_freetype.module("mach-harfbuzz") },
},
});
return _module.?;
}
pub fn build(b: *std.Build) !void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const mach_core_dep = b.dependency("mach_core", .{
.target = target,
.optimize = optimize,
});
const mach_sysaudio_dep = b.dependency("mach_sysaudio", .{
.target = target,
.optimize = optimize,
});
const mach_ecs_dep = b.dependency("mach_ecs", .{
.target = target,
.optimize = optimize,
});
const mach_basisu_dep = b.dependency("mach_basisu", .{
.target = target,
.optimize = optimize,
});
const mach_freetype_dep = b.dependency("mach_freetype", .{
.target = target,
.optimize = optimize,
});
const mach_sysjs_dep = b.dependency("mach_sysjs", .{
.target = target,
.optimize = optimize,
});
const module = b.addModule("mach", .{
.source_file = .{ .path = sdkPath("/src/main.zig") },
.dependencies = &.{
.{ .name = "mach-core", .module = mach_core_dep.module("mach-core") },
.{ .name = "mach-ecs", .module = mach_ecs_dep.module("mach-ecs") },
.{ .name = "mach-sysaudio", .module = mach_sysaudio_dep.module("mach-sysaudio") },
.{ .name = "mach-basisu", .module = mach_basisu_dep.module("mach-basisu") },
.{ .name = "mach-freetype", .module = mach_freetype_dep.module("mach-freetype") },
.{ .name = "mach-harfbuzz", .module = mach_freetype_dep.module("mach-harfbuzz") },
.{ .name = "mach-sysjs", .module = mach_sysjs_dep.module("mach-sysjs") },
},
});
if (target.getCpuArch() != .wasm32) {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
@ -56,7 +56,7 @@ pub fn build(b: *std.Build) !void {
.target = target,
.optimize = optimize,
});
var iter = module(b, optimize, target).dependencies.iterator();
var iter = module.dependencies.iterator();
while (iter.next()) |e| {
unit_tests.addModule(e.key_ptr.*, e.value_ptr.*);
}
@ -66,6 +66,14 @@ pub fn build(b: *std.Build) !void {
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
const install_docs = b.addInstallDirectory(.{
.source_dir = unit_tests.getEmittedDocs(),
.install_dir = .prefix, // default build output prefix, ./zig-out
.install_subdir = "docs",
});
const docs_step = b.step("docs", "Generate API docs");
docs_step.dependOn(&install_docs.step);
}
}
@ -91,20 +99,26 @@ pub const App = struct {
res_dirs: ?[]const []const u8 = null,
watch_paths: ?[]const []const u8 = null,
mach_builder: ?*std.Build = null,
mach_mod: ?*std.build.Module = null,
},
) !App {
const mach_builder = options.mach_builder orelse app_builder.dependency("mach", .{
.target = options.target,
.optimize = options.optimize,
}).builder;
const mach_mod = options.mach_mod orelse app_builder.dependency("mach", .{
.target = options.target,
.optimize = options.optimize,
}).module("mach");
var deps = std.ArrayList(std.build.ModuleDependency).init(app_builder.allocator);
if (options.deps) |v| try deps.appendSlice(v);
try deps.append(.{ .name = "mach", .module = module(mach_builder, options.optimize, options.target) });
const mach_sysaudio = mach_builder.dependency("mach_sysaudio", .{
try deps.append(.{ .name = "mach", .module = mach_mod });
const mach_sysaudio_dep = mach_builder.dependency("mach_sysaudio", .{
.target = options.target,
.optimize = options.optimize,
});
try deps.append(.{ .name = "sysaudio", .module = sysaudio.module(mach_sysaudio.builder, options.optimize, options.target) });
try deps.append(.{ .name = "mach-sysaudio", .module = mach_sysaudio_dep.module("mach-sysaudio") });
const mach_core = mach_builder.dependency("mach_core", .{
.target = options.target,

View file

@ -11,20 +11,24 @@
.hash = "12204dbf4f71c675479fd59ded257644bd48decf045464f0105a72b632f56be3b4de",
},
.mach_core = .{
.url = "https://pkg.machengine.org/mach-core/9243a331a3eb0d4ba97aec7f793e60f1cf90bd8b.tar.gz",
.hash = "12206e93994d37b3ce5c790e391736130f2a26bec06eca01ca51ab08a6d8105ab7f9",
.url = "https://pkg.machengine.org/mach-core/d2b382d9698fc621d912ba1c693fe484d8e2178a.tar.gz",
.hash = "1220c90fcb6a12a9659f4971e12ec53db017eb082abd3ebf4d1b8f703412c84228ae",
},
.mach_basisu = .{
.url = "https://pkg.machengine.org/mach-basisu/fe2f30a9a9662db2d12bc978b50158d4e74ec0d8.tar.gz",
.hash = "1220c36c6c5491e78f0ca3f857080551cb90480b6e2028d6636409a907d6dfa49df2",
},
.mach_sysaudio = .{
.url = "https://pkg.machengine.org/mach-sysaudio/a9bf13c14e05648e00745f5782883f4111eaeed4.tar.gz",
.hash = "12206935288305365fe8bc46e0e30191f1119fca96632a5f93ca95ceb978b13bdb33",
.url = "https://pkg.machengine.org/mach-sysaudio/381b3815caef1f631d64360cc51525adf638189c.tar.gz",
.hash = "12205e0f7e775161606bd55c92eb4244c69cb7072ee5d8205e50300048cbf1f6dc5c",
},
.mach_freetype = .{
.url = "https://pkg.machengine.org/mach-freetype/92773615e2480c0a6f561748f2ba1180376bbb68.tar.gz",
.hash = "12205a6057fe43a4940c6db304449ebf3e98ff15d0eec05b75f621d7616c2e7d7f2c",
},
.mach_sysjs = .{
.url = "https://pkg.machengine.org/mach-sysjs/bafd6c9b8fd5e7be1e8e24cfbd156703d6026aa8.tar.gz",
.hash = "1220187935c4c5d4cf824927df28e858dcd06cb864bb5d6be4cd349d2836abb4aec4",
},
},
}

View file

@ -1,13 +1,10 @@
// Core re-exports
pub const core = @import("mach-core");
pub const GPUInterface = core.GPUInterface;
pub const Timer = core.Timer;
pub const scope_levels = core.scope_levels;
pub const log_level = core.log_level;
// Mach packages
pub const gpu = core.gpu;
pub const sysjs = @import("sysjs");
pub const sysjs = @import("mach-sysjs");
pub const ecs = @import("mach-ecs");
pub const sysaudio = @import("mach-sysaudio");