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

@ -23,7 +23,6 @@ const core = @import("libs/core/sdk.zig").Sdk(.{
.gpu_dawn = gpu_dawn, .gpu_dawn = gpu_dawn,
.glfw = glfw, .glfw = glfw,
.gamemode = gamemode, .gamemode = gamemode,
.sysjs = sysjs,
}); });
var _module: ?*std.build.Module = null; var _module: ?*std.build.Module = null;

View file

@ -11,5 +11,9 @@
.url = "https://github.com/hexops/mach-earcut/archive/5a34772313a6a0679cc6c83f310a59741d03c246.tar.gz", .url = "https://github.com/hexops/mach-earcut/archive/5a34772313a6a0679cc6c83f310a59741d03c246.tar.gz",
.hash = "1220c7059f62cf479e1c3de773cddb71aeb5824ac74528392cd38715f586d7a52e2f", .hash = "1220c7059f62cf479e1c3de773cddb71aeb5824ac74528392cd38715f586d7a52e2f",
}, },
.mach_sysjs = .{
.url = "https://github.com/hexops/mach-sysjs/archive/b71eb0531f337fcca5a2b245f595355260109a34.tar.gz",
.hash = "12208b30f1d9c229d1e64483354610207c9aa06350a46558560b818d597800ed86e0",
},
}, },
} }

View file

@ -2,7 +2,6 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const system_sdk = @import("libs/mach-glfw/system_sdk.zig"); const system_sdk = @import("libs/mach-glfw/system_sdk.zig");
const glfw = @import("libs/mach-glfw/build.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 gamemode = @import("libs/mach-gamemode/build.zig");
const gpu_dawn = @import("libs/mach-gpu-dawn/sdk.zig").Sdk(.{ const gpu_dawn = @import("libs/mach-gpu-dawn/sdk.zig").Sdk(.{
.glfw_include_dir = sdkPath("/libs/mach-glfw/upstream/glfw/include"), .glfw_include_dir = sdkPath("/libs/mach-glfw/upstream/glfw/include"),
@ -16,7 +15,6 @@ const core = @import("sdk.zig").Sdk(.{
.gpu_dawn = gpu_dawn, .gpu_dawn = gpu_dawn,
.glfw = glfw, .glfw = glfw,
.gamemode = gamemode, .gamemode = gamemode,
.sysjs = sysjs,
}); });
pub fn build(b: *std.Build) !void { 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(gpu_test_step);
all_tests_step.dependOn(core_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 // Compiles the `libmachcore` shared library
const shared_lib = try core.buildSharedLib(b, optimize, target, options); 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, platform: Platform,
res_dirs: ?[]const []const u8, res_dirs: ?[]const []const u8,
watch_paths: ?[]const []const u8, watch_paths: ?[]const []const u8,
sysjs_dep: ?*std.Build.Dependency,
const web_install_dir = std.build.InstallDir{ .custom = "www" }; const web_install_dir = std.build.InstallDir{ .custom = "www" };
@ -124,6 +125,11 @@ pub fn Sdk(comptime deps: anytype) type {
.dependencies = try dependencies.toOwnedSlice(), .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: { const step = blk: {
if (platform == .web) { if (platform == .web) {
const lib = b.addSharedLibrary(.{ const lib = b.addSharedLibrary(.{
@ -133,8 +139,7 @@ pub fn Sdk(comptime deps: anytype) type {
.optimize = options.optimize, .optimize = options.optimize,
}); });
lib.rdynamic = true; lib.rdynamic = true;
lib.addModule("sysjs", deps.sysjs.module(b)); lib.addModule("sysjs", sysjs_dep.?.module("mach-sysjs"));
break :blk lib; break :blk lib;
} else { } else {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
@ -163,6 +168,7 @@ pub fn Sdk(comptime deps: anytype) type {
.platform = platform, .platform = platform,
.res_dirs = options.res_dirs, .res_dirs = options.res_dirs,
.watch_paths = options.watch_paths, .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' // Set install directory to '{prefix}/www'
app.getInstallStep().?.dest_dir = web_install_dir; 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( const install_js = app.b.addInstallFileWithDir(
.{ .path = sdkPath(js) }, .{ .path = js },
web_install_dir, web_install_dir,
std.fs.path.basename(js), std.fs.path.basename(js),
); );

View file

@ -5,8 +5,8 @@ pub const log_level = core.log_level;
pub const Core = core.Core; pub const Core = core.Core;
pub const Timer = core.Timer; pub const Timer = core.Timer;
pub const gpu = core.gpu; pub const gpu = core.gpu;
pub const sysjs = core.sysjs;
pub const sysjs = @import("sysjs");
pub const ecs = @import("ecs"); pub const ecs = @import("ecs");
pub const sysaudio = @import("sysaudio"); pub const sysaudio = @import("sysaudio");
pub const earcut = @import("earcut"); pub const earcut = @import("earcut");