start making the src more wasm target aware

This commit is contained in:
Mitchell Hashimoto
2022-12-31 08:55:12 -08:00
parent ce490e21ea
commit 8b6128ddfc
2 changed files with 44 additions and 34 deletions

View File

@ -56,8 +56,10 @@ pub const Backend = enum {
/// Returns the default backend for a build environment. This is
/// meant to be called at comptime.
pub fn default() Backend {
// Wasm only supports browser at the moment.
if (builtin.target.isWasm()) return .web_canvas;
const wasm = @import("../os/wasm.zig");
if (wasm.target) |target| return switch (target) {
.browser => .web_canvas,
};
return if (build_options.coretext)
.coretext_freetype

View File

@ -2,6 +2,13 @@ const std = @import("std");
const builtin = @import("builtin");
const wasm = @import("../wasm.zig");
// Use the correct implementation
pub usingnamespace if (wasm.target) |target| switch (target) {
.browser => Browser,
} else struct {};
/// Browser implementation calls an extern "log" function.
pub const Browser = struct {
// The function std.log will call.
pub fn log(
comptime level: std.log.Level,
@ -38,3 +45,4 @@ pub fn log(
const JS = struct {
extern "env" fn log(ptr: [*]const u8, len: usize) void;
};
};