Skip to content

Commit

Permalink
feat: Add cp builtin to shell for Windows (#10174)
Browse files Browse the repository at this point in the history
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
Co-authored-by: zackradisic <zackradisic@users.noreply.github.com>
  • Loading branch information
5 people authored May 9, 2024
1 parent f1fbf54 commit 4b581b0
Show file tree
Hide file tree
Showing 14 changed files with 1,900 additions and 594 deletions.
50 changes: 44 additions & 6 deletions src/bun.js/event_loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,14 @@ pub const AnyTaskWithExtraContext = struct {
callback: *const (fn (*anyopaque, *anyopaque) void) = undefined,
next: ?*AnyTaskWithExtraContext = null,

pub fn fromCallbackAutoDeinit(of: anytype, comptime callback: anytype) *AnyTaskWithExtraContext {
const TheTask = NewManaged(std.meta.Child(@TypeOf(of)), void, @field(std.meta.Child(@TypeOf(of)), callback));
const task = bun.default_allocator.create(AnyTaskWithExtraContext) catch bun.outOfMemory();
task.* = TheTask.init(of);
return task;
}

pub fn from(this: *@This(), of: anytype, comptime field: []const u8) *@This() {
// this.* = .{
// .ctx = of,
// .callback = @field(std.meta.Child(@TypeOf(of)), field),
// .next = null,
// };
// return this;
const TheTask = New(std.meta.Child(@TypeOf(of)), void, @field(std.meta.Child(@TypeOf(of)), field));
this.* = TheTask.init(of);
return this;
Expand Down Expand Up @@ -266,6 +267,30 @@ pub const AnyTaskWithExtraContext = struct {
}
};
}

pub fn NewManaged(comptime Type: type, comptime ContextType: type, comptime Callback: anytype) type {
return struct {
pub fn init(ctx: *Type) AnyTaskWithExtraContext {
return AnyTaskWithExtraContext{
.callback = wrap,
.ctx = ctx,
};
}

pub fn wrap(this: ?*anyopaque, extra: ?*anyopaque) void {
@call(
.always_inline,
Callback,
.{
@as(*Type, @ptrCast(@alignCast(this.?))),
@as(*ContextType, @ptrCast(@alignCast(extra.?))),
},
);
const anytask: *AnyTaskWithExtraContext = @fieldParentPtr(AnyTaskWithExtraContext, "ctx", @as(*?*anyopaque, @ptrCast(@alignCast(this.?))));
bun.default_allocator.destroy(anytask);
}
};
}
};

pub const CppTask = opaque {
Expand Down Expand Up @@ -363,6 +388,7 @@ const ShellMvCheckTargetTask = bun.shell.Interpreter.Builtin.Mv.ShellMvCheckTarg
const ShellMvBatchedTask = bun.shell.Interpreter.Builtin.Mv.ShellMvBatchedTask;
const ShellMkdirTask = bun.shell.Interpreter.Builtin.Mkdir.ShellMkdirTask;
const ShellTouchTask = bun.shell.Interpreter.Builtin.Touch.ShellTouchTask;
const ShellCpTask = bun.shell.Interpreter.Builtin.Cp.ShellCpTask;
const ShellCondExprStatTask = bun.shell.Interpreter.CondExpr.ShellCondExprStatTask;
const ShellAsync = bun.shell.Interpreter.Async;
// const ShellIOReaderAsyncDeinit = bun.shell.Interpreter.IOReader.AsyncDeinit;
Expand Down Expand Up @@ -443,6 +469,7 @@ pub const Task = TaggedPointerUnion(.{
ShellLsTask,
ShellMkdirTask,
ShellTouchTask,
ShellCpTask,
ShellCondExprStatTask,
ShellAsync,
ShellAsyncSubprocessDone,
Expand Down Expand Up @@ -918,6 +945,10 @@ pub const EventLoop = struct {
var shell_ls_task: *ShellCondExprStatTask = task.get(ShellCondExprStatTask).?;
shell_ls_task.task.runFromMainThread();
},
@field(Task.Tag, typeBaseName(@typeName(ShellCpTask))) => {
var shell_ls_task: *ShellCpTask = task.get(ShellCpTask).?;
shell_ls_task.runFromMainThread();
},
@field(Task.Tag, typeBaseName(@typeName(ShellTouchTask))) => {
var shell_ls_task: *ShellTouchTask = task.get(ShellTouchTask).?;
shell_ls_task.runFromMainThread();
Expand Down Expand Up @@ -2094,6 +2125,13 @@ pub const EventLoopHandle = union(enum) {
js: *JSC.EventLoop,
mini: *MiniEventLoop,

pub fn globalObject(this: EventLoopHandle) ?*JSC.JSGlobalObject {
return switch (this) {
.js => this.js.global,
.mini => null,
};
}

pub fn stdout(this: EventLoopHandle) *JSC.WebCore.Blob.Store {
return switch (this) {
.js => this.js.virtual_machine.rareData().stdout(),
Expand Down
Loading

0 comments on commit 4b581b0

Please sign in to comment.