From 1093cf5254376256f179b80190578eed094f7237 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 30 Dec 2022 16:32:49 -0800 Subject: [PATCH] config: enable passwd isn't compiled for wasm --- example/app.ts | 10 ++++++++++ src/config.zig | 47 +++++++++++++++++++++++++---------------------- src/passwd.zig | 7 +++++++ 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/example/app.ts b/example/app.ts index 40a81d2c2..55ffb8279 100644 --- a/example/app.ts +++ b/example/app.ts @@ -26,6 +26,10 @@ fetch(url.href).then(response => const { malloc, free, + config_new, + config_free, + config_load_string, + config_finalize, face_new, face_free, face_render_glyph, @@ -68,6 +72,12 @@ fetch(url.href).then(response => return { ptr: ptr, len: utf8.byteLength }; }; + // Create our config + const config = config_new(); + const config_str = makeStr("font-family = monospace"); + config_load_string(config, config_str.ptr, config_str.len); + config_finalize(config); + // Create our atlas // const atlas = atlas_new(512, 0 /* greyscale */); diff --git a/src/config.zig b/src/config.zig index 58a90082f..0e9ee8943 100644 --- a/src/config.zig +++ b/src/config.zig @@ -314,33 +314,36 @@ pub const Config = struct { }; // If we are missing either a command or home directory, we need - // to look up defaults which is kind of expensive. + // to look up defaults which is kind of expensive. We only do this + // on desktop. const wd_home = std.mem.eql(u8, "home", wd); - if (self.command == null or wd_home) command: { - const alloc = self._arena.?.allocator(); + if (comptime !builtin.target.isWasm()) { + if (self.command == null or wd_home) command: { + const alloc = self._arena.?.allocator(); - // First look up the command using the SHELL env var. - if (std.process.getEnvVarOwned(alloc, "SHELL")) |value| { - log.debug("default shell source=env value={s}", .{value}); - self.command = value; + // First look up the command using the SHELL env var. + if (std.process.getEnvVarOwned(alloc, "SHELL")) |value| { + log.debug("default shell source=env value={s}", .{value}); + self.command = value; - // If we don't need the working directory, then we can exit now. - if (!wd_home) break :command; - } else |_| {} + // If we don't need the working directory, then we can exit now. + if (!wd_home) break :command; + } else |_| {} - // We need the passwd entry for the remainder - const pw = try passwd.get(alloc); - if (self.command == null) { - if (pw.shell) |sh| { - log.debug("default shell src=passwd value={s}", .{sh}); - self.command = sh; + // We need the passwd entry for the remainder + const pw = try passwd.get(alloc); + if (self.command == null) { + if (pw.shell) |sh| { + log.debug("default shell src=passwd value={s}", .{sh}); + self.command = sh; + } } - } - if (wd_home) { - if (pw.home) |home| { - log.debug("default working directory src=passwd value={s}", .{home}); - self.@"working-directory" = home; + if (wd_home) { + if (pw.home) |home| { + log.debug("default working directory src=passwd value={s}", .{home}); + self.@"working-directory" = home; + } } } } @@ -528,7 +531,7 @@ pub const Keybinds = struct { }; // Wasm API. -pub const Wasm = struct { +pub const Wasm = if (!builtin.target.isWasm()) struct {} else struct { const wasm = @import("os/wasm.zig"); const alloc = wasm.alloc; const cli_args = @import("cli_args.zig"); diff --git a/src/passwd.zig b/src/passwd.zig index 6d647a86a..0a97676cb 100644 --- a/src/passwd.zig +++ b/src/passwd.zig @@ -5,6 +5,13 @@ const ArenaAllocator = std.heap.ArenaAllocator; const log = std.log.scoped(.passwd); +// We want to be extra sure since this will force bad symbols into our import table +comptime { + if (builtin.target.isWasm()) { + @compileError("passwd is not available for wasm"); + } +} + /// Used to determine the default shell and directory on Unixes. const c = @cImport({ @cInclude("sys/types.h");