config: enable passwd isn't compiled for wasm

This commit is contained in:
Mitchell Hashimoto
2022-12-30 16:32:49 -08:00
parent 7c291a2c4c
commit 1093cf5254
3 changed files with 42 additions and 22 deletions

View File

@ -26,6 +26,10 @@ fetch(url.href).then(response =>
const { const {
malloc, malloc,
free, free,
config_new,
config_free,
config_load_string,
config_finalize,
face_new, face_new,
face_free, face_free,
face_render_glyph, face_render_glyph,
@ -68,6 +72,12 @@ fetch(url.href).then(response =>
return { ptr: ptr, len: utf8.byteLength }; 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 // Create our atlas
// const atlas = atlas_new(512, 0 /* greyscale */); // const atlas = atlas_new(512, 0 /* greyscale */);

View File

@ -314,33 +314,36 @@ pub const Config = struct {
}; };
// If we are missing either a command or home directory, we need // 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); const wd_home = std.mem.eql(u8, "home", wd);
if (self.command == null or wd_home) command: { if (comptime !builtin.target.isWasm()) {
const alloc = self._arena.?.allocator(); if (self.command == null or wd_home) command: {
const alloc = self._arena.?.allocator();
// First look up the command using the SHELL env var. // First look up the command using the SHELL env var.
if (std.process.getEnvVarOwned(alloc, "SHELL")) |value| { if (std.process.getEnvVarOwned(alloc, "SHELL")) |value| {
log.debug("default shell source=env value={s}", .{value}); log.debug("default shell source=env value={s}", .{value});
self.command = value; self.command = value;
// If we don't need the working directory, then we can exit now. // If we don't need the working directory, then we can exit now.
if (!wd_home) break :command; if (!wd_home) break :command;
} else |_| {} } else |_| {}
// We need the passwd entry for the remainder // We need the passwd entry for the remainder
const pw = try passwd.get(alloc); const pw = try passwd.get(alloc);
if (self.command == null) { if (self.command == null) {
if (pw.shell) |sh| { if (pw.shell) |sh| {
log.debug("default shell src=passwd value={s}", .{sh}); log.debug("default shell src=passwd value={s}", .{sh});
self.command = sh; self.command = sh;
}
} }
}
if (wd_home) { if (wd_home) {
if (pw.home) |home| { if (pw.home) |home| {
log.debug("default working directory src=passwd value={s}", .{home}); log.debug("default working directory src=passwd value={s}", .{home});
self.@"working-directory" = home; self.@"working-directory" = home;
}
} }
} }
} }
@ -528,7 +531,7 @@ pub const Keybinds = struct {
}; };
// Wasm API. // Wasm API.
pub const Wasm = struct { pub const Wasm = if (!builtin.target.isWasm()) struct {} else struct {
const wasm = @import("os/wasm.zig"); const wasm = @import("os/wasm.zig");
const alloc = wasm.alloc; const alloc = wasm.alloc;
const cli_args = @import("cli_args.zig"); const cli_args = @import("cli_args.zig");

View File

@ -5,6 +5,13 @@ const ArenaAllocator = std.heap.ArenaAllocator;
const log = std.log.scoped(.passwd); 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. /// Used to determine the default shell and directory on Unixes.
const c = @cImport({ const c = @cImport({
@cInclude("sys/types.h"); @cInclude("sys/types.h");