mirror of
https://github.com/oven-sh/bun
synced 2026-02-17 14:22:01 +00:00
Fix wasm build
This commit is contained in:
@@ -56,6 +56,7 @@ const Resolver = _resolver.Resolver;
|
||||
const TOML = @import("./toml/toml_parser.zig").TOML;
|
||||
|
||||
const EntryPoints = @import("./bundler/entry_points.zig");
|
||||
const SystemTimer = @import("./system_timer.zig");
|
||||
pub usingnamespace EntryPoints;
|
||||
// How it works end-to-end
|
||||
// 1. Resolve a file path from input using the resolver
|
||||
@@ -133,7 +134,7 @@ pub const Bundler = struct {
|
||||
router: ?Router = null,
|
||||
|
||||
linker: Linker,
|
||||
timer: std.time.Timer = undefined,
|
||||
timer: SystemTimer = undefined,
|
||||
env: *DotEnv.Loader,
|
||||
|
||||
macro_context: ?js_ast.Macro.MacroContext = null,
|
||||
@@ -229,7 +230,7 @@ pub const Bundler = struct {
|
||||
.options = bundle_options,
|
||||
.fs = fs,
|
||||
.allocator = allocator,
|
||||
.timer = std.time.Timer.start() catch @panic("Timer fail"),
|
||||
.timer = SystemTimer.start() catch @panic("Timer fail"),
|
||||
.resolver = Resolver.init1(allocator, log, fs, bundle_options),
|
||||
.log = log,
|
||||
// .thread_pool = pool,
|
||||
|
||||
@@ -43,7 +43,7 @@ const SourceMap = @import("./sourcemap/sourcemap.zig");
|
||||
const ObjectPool = @import("./pool.zig").ObjectPool;
|
||||
const Lock = @import("./lock.zig").Lock;
|
||||
const RequestDataPool = ObjectPool([32_000]u8, null, false, 1);
|
||||
|
||||
const ResolveWatcher = @import("./resolver/resolver.zig").ResolveWatcher;
|
||||
pub fn constStrToU8(s: string) []u8 {
|
||||
return @intToPtr([*]u8, @ptrToInt(s.ptr))[0..s.len];
|
||||
}
|
||||
@@ -3887,8 +3887,10 @@ pub const Server = struct {
|
||||
server.watcher = try Watcher.init(server, server.bundler.fs, server.allocator);
|
||||
|
||||
if (comptime FeatureFlags.watch_directories and !Environment.isTest) {
|
||||
server.bundler.resolver.onStartWatchingDirectoryCtx = server.watcher;
|
||||
server.bundler.resolver.onStartWatchingDirectory = onMaybeWatchDirectory;
|
||||
server.bundler.resolver.watcher = ResolveWatcher(Watcher){
|
||||
.context = server.watcher,
|
||||
.callback = onMaybeWatchDirectory,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -247,6 +247,7 @@ export fn transform(opts_array: u64) u64 {
|
||||
.{},
|
||||
void,
|
||||
null,
|
||||
false,
|
||||
) catch 0;
|
||||
|
||||
output_files[0] = .{ .data = writer.ctx.written, .path = path };
|
||||
|
||||
@@ -9,6 +9,8 @@ const Global = @import("./global.zig").Global;
|
||||
const ComptimeStringMap = @import("./global.zig").ComptimeStringMap;
|
||||
const use_mimalloc = @import("./global.zig").use_mimalloc;
|
||||
|
||||
const SystemTimer = @import("./system_timer.zig");
|
||||
|
||||
// These are threadlocal so we don't have stdout/stderr writing on top of each other
|
||||
threadlocal var source: Source = undefined;
|
||||
threadlocal var source_set: bool = false;
|
||||
@@ -282,7 +284,8 @@ pub fn printStartEndStdout(start: i128, end: i128) void {
|
||||
printElapsedStdout(@intToFloat(f64, elapsed));
|
||||
}
|
||||
|
||||
pub fn printTimer(timer: *std.time.Timer) void {
|
||||
pub fn printTimer(timer: *SystemTimer) void {
|
||||
if (comptime Environment.isWasm) return;
|
||||
const elapsed = @divTrunc(timer.read(), @as(u64, std.time.ns_per_ms));
|
||||
printElapsed(@intToFloat(f64, elapsed));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ const BrowserMap = @import("./package_json.zig").BrowserMap;
|
||||
const CacheSet = cache.Set;
|
||||
const DataURL = @import("./data_url.zig").DataURL;
|
||||
pub const DirInfo = @import("./dir_info.zig");
|
||||
const HTTPWatcher = if (Environment.isTest) void else @import("../http.zig").Watcher;
|
||||
const HTTPWatcher = if (Environment.isTest or Environment.isWasm) void else @import("../http.zig").Watcher;
|
||||
const Wyhash = std.hash.Wyhash;
|
||||
const ResolvePath = @import("./resolve_path.zig");
|
||||
const NodeFallbackModules = @import("../node_fallbacks.zig");
|
||||
@@ -302,6 +302,18 @@ var bin_folders: BinFolderArray = undefined;
|
||||
var bin_folders_lock: Mutex = Mutex.init();
|
||||
var bin_folders_loaded: bool = false;
|
||||
|
||||
const Timer = @import("../timer.zig");
|
||||
pub fn ResolveWatcher(comptime Context: type) type {
|
||||
return struct {
|
||||
context: *Context,
|
||||
callback: fn (*Context, dir_path: string, dir_fd: StoredFileDescriptorType) void = undefined,
|
||||
|
||||
pub fn watch(this: @This(), dir_path: string, fd: StoredFileDescriptorType) void {
|
||||
return this.callback(this.context, dir_path, fd);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub const Resolver = struct {
|
||||
const ThisResolver = @This();
|
||||
opts: options.BundleOptions,
|
||||
@@ -310,7 +322,7 @@ pub const Resolver = struct {
|
||||
allocator: std.mem.Allocator,
|
||||
node_module_bundle: ?*NodeModuleBundle,
|
||||
extension_order: []const string = undefined,
|
||||
timer: std.time.Timer = undefined,
|
||||
timer: Timer = undefined,
|
||||
|
||||
care_about_bin_folder: bool = false,
|
||||
care_about_scripts: bool = false,
|
||||
@@ -318,8 +330,7 @@ pub const Resolver = struct {
|
||||
debug_logs: ?DebugLogs = null,
|
||||
elapsed: u64 = 0, // tracing
|
||||
|
||||
onStartWatchingDirectory: ?fn (*HTTPWatcher, dir_path: string, dir_fd: StoredFileDescriptorType) void = null,
|
||||
onStartWatchingDirectoryCtx: ?*HTTPWatcher = null,
|
||||
watcher: ?ResolveWatcher(HTTPWatcher) = null,
|
||||
|
||||
caches: CacheSet,
|
||||
|
||||
@@ -384,7 +395,7 @@ pub const Resolver = struct {
|
||||
.mutex = &resolver_Mutex,
|
||||
.caches = CacheSet.init(allocator),
|
||||
.opts = opts,
|
||||
.timer = std.time.Timer.start() catch @panic("Timer error!"),
|
||||
.timer = if (comptime Timer != void) Timer.start() catch @panic("Timer error!") else Timer{},
|
||||
.fs = _fs,
|
||||
.node_module_bundle = opts.node_modules_bundle,
|
||||
.log = log,
|
||||
@@ -568,9 +579,9 @@ pub const Resolver = struct {
|
||||
else => r.opts.extension_order,
|
||||
};
|
||||
|
||||
var timer: ?std.time.Timer = null;
|
||||
var timer: Timer = undefined;
|
||||
if (FeatureFlags.tracing) {
|
||||
timer = std.time.Timer.start() catch null;
|
||||
timer = Timer.start() catch null;
|
||||
}
|
||||
|
||||
defer {
|
||||
|
||||
27
src/system_timer.zig
Normal file
27
src/system_timer.zig
Normal file
@@ -0,0 +1,27 @@
|
||||
const Environment = @import("./env.zig");
|
||||
const std = @import("std");
|
||||
|
||||
fn NewTimer() type {
|
||||
if (Environment.isWasm) {
|
||||
return struct {
|
||||
pub fn start() anyerror!@This() {
|
||||
return @This(){};
|
||||
}
|
||||
|
||||
pub fn read(_: anytype) u64 {
|
||||
@compileError("FeatureFlags.tracing should be disabled in WASM");
|
||||
}
|
||||
|
||||
pub fn lap(_: anytype) u64 {
|
||||
@compileError("FeatureFlags.tracing should be disabled in WASM");
|
||||
}
|
||||
|
||||
pub fn reset(_: anytype) u64 {
|
||||
@compileError("FeatureFlags.tracing should be disabled in WASM");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return std.time.Timer;
|
||||
}
|
||||
pub usingnamespace NewTimer();
|
||||
Reference in New Issue
Block a user