core: use mach-sysjs via package manager

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-05-19 08:20:01 -07:00
parent e4e3da7e54
commit 816b5101b3
8 changed files with 26 additions and 15 deletions

View file

@ -2,7 +2,6 @@ const std = @import("std");
const builtin = @import("builtin");
const system_sdk = @import("libs/mach-glfw/system_sdk.zig");
const glfw = @import("libs/mach-glfw/build.zig");
const sysjs = @import("libs/mach-sysjs/build.zig");
const gamemode = @import("libs/mach-gamemode/build.zig");
const gpu_dawn = @import("libs/mach-gpu-dawn/sdk.zig").Sdk(.{
.glfw_include_dir = sdkPath("/libs/mach-glfw/upstream/glfw/include"),
@ -16,7 +15,6 @@ const core = @import("sdk.zig").Sdk(.{
.gpu_dawn = gpu_dawn,
.glfw = glfw,
.gamemode = gamemode,
.sysjs = sysjs,
});
pub fn build(b: *std.Build) !void {
@ -43,11 +41,6 @@ pub fn build(b: *std.Build) !void {
all_tests_step.dependOn(gpu_test_step);
all_tests_step.dependOn(core_test_step);
// TODO: we need a way to test wasm stuff
// const sysjs_test_step = b.step( "test-sysjs", "Run sysjs library tests");
// sysjs_test_step.dependOn(&sysjs.testStep(b, optimize, target).step);
// all_tests_step.dependOn(sysjs_test_step);
// Compiles the `libmachcore` shared library
const shared_lib = try core.buildSharedLib(b, optimize, target, options);

11
libs/core/build.zig.zon Normal file
View file

@ -0,0 +1,11 @@
.{
.name = "mach-core",
.version = "0.2.0",
.dependencies = .{
.mach_sysjs = .{
.url = "https://github.com/hexops/mach-sysjs/archive/b71eb0531f337fcca5a2b245f595355260109a34.tar.gz",
.hash = "12208b30f1d9c229d1e64483354610207c9aa06350a46558560b818d597800ed86e0",
},
},
}

View file

@ -1 +0,0 @@
../../sysjs

View file

@ -1 +0,0 @@
../../../tools/wasmserve

View file

@ -84,6 +84,7 @@ pub fn Sdk(comptime deps: anytype) type {
platform: Platform,
res_dirs: ?[]const []const u8,
watch_paths: ?[]const []const u8,
sysjs_dep: ?*std.Build.Dependency,
const web_install_dir = std.build.InstallDir{ .custom = "www" };
@ -124,6 +125,11 @@ pub fn Sdk(comptime deps: anytype) type {
.dependencies = try dependencies.toOwnedSlice(),
});
const sysjs_dep = if (platform == .web) b.dependency("mach_sysjs", .{
.target = options.target,
.optimize = options.optimize,
}) else null;
const step = blk: {
if (platform == .web) {
const lib = b.addSharedLibrary(.{
@ -133,8 +139,7 @@ pub fn Sdk(comptime deps: anytype) type {
.optimize = options.optimize,
});
lib.rdynamic = true;
lib.addModule("sysjs", deps.sysjs.module(b));
lib.addModule("sysjs", sysjs_dep.?.module("mach-sysjs"));
break :blk lib;
} else {
const exe = b.addExecutable(.{
@ -163,6 +168,7 @@ pub fn Sdk(comptime deps: anytype) type {
.platform = platform,
.res_dirs = options.res_dirs,
.watch_paths = options.watch_paths,
.sysjs_dep = sysjs_dep,
};
}
@ -184,9 +190,9 @@ pub fn Sdk(comptime deps: anytype) type {
// Set install directory to '{prefix}/www'
app.getInstallStep().?.dest_dir = web_install_dir;
inline for (.{ "/src/platform/wasm/mach.js", "/libs/mach-sysjs/src/mach-sysjs.js" }) |js| {
inline for (.{ sdkPath("/src/platform/wasm/mach.js"), @import("mach_sysjs").getJSPath() }) |js| {
const install_js = app.b.addInstallFileWithDir(
.{ .path = sdkPath(js) },
.{ .path = js },
web_install_dir,
std.fs.path.basename(js),
);