Compare commits

...

9 Commits

Author SHA1 Message Date
autofix-ci[bot]
914b69c56c [autofix.ci] apply automated fixes 2025-07-24 05:29:26 +00:00
Jarred Sumner
016451a408 Merge branch 'main' into jarred/remote-statfs 2025-07-23 22:27:00 -07:00
Jarred Sumner
4fdd7eacd3 Merge branch 'main' into jarred/remote-statfs 2025-07-23 12:52:37 -07:00
Jarred Sumner
2d40e41fec Use copyfile backend in overlayfs by default 2025-07-23 12:09:15 -07:00
Jarred Sumner
16b124c6a8 Update runTasks.zig 2025-07-22 16:33:10 -07:00
Jarred Sumner
48a855a7d1 Update PackageManager.zig 2025-07-22 14:42:31 -07:00
Jarred Sumner
598c66e063 Update sys.zig 2025-07-22 14:42:10 -07:00
Jarred Sumner
61f0671b11 Update PackageManager.zig 2025-07-22 14:35:23 -07:00
Jarred Sumner
4cdcf7506c Don't save TTL manifest on remote fs 2025-07-22 13:33:29 -07:00
7 changed files with 122 additions and 8 deletions

View File

@@ -30,6 +30,7 @@ pub const RuntimeFeatureFlag = enum {
BUN_FEATURE_FLAG_LAST_MODIFIED_PRETEND_304,
BUN_FEATURE_FLAG_NO_LIBDEFLATE,
BUN_INSTRUMENTS,
BUN_FEATURE_FLAG_MANIFEST_CACHE_NO_SAVE_TTL,
BUN_INTERNAL_BUNX_INSTALL,
BUN_NO_CODESIGN_MACHO_BINARY,
BUN_TRACE,

View File

@@ -19,7 +19,7 @@ scripts_node: ?*Progress.Node = null,
progress_name_buf: [768]u8 = undefined,
progress_name_buf_dynamic: []u8 = &[_]u8{},
cpu_count: u32 = 0,
is_cache_directory_remote: ?bun.sys.RemoteFileSystem = null,
track_installed_bin: TrackInstalledBin = .{
.none = {},
},
@@ -381,6 +381,24 @@ pub fn computeIsContinuousIntegration(this: *PackageManager) bool {
return this.env.isCI();
}
pub fn isCacheDirectoryRemote(this: *PackageManager) bun.sys.RemoteFileSystem {
if (comptime Environment.isWindows) {
// TODO:
return .none;
}
if (this.is_cache_directory_remote) |remote_fs| {
return remote_fs;
}
const statfs = bun.sys.statfs(this.cache_directory_path).unwrap() catch {
this.is_cache_directory_remote = .none;
return .none;
};
this.is_cache_directory_remote = bun.sys.RemoteFileSystem.get(&statfs);
return this.is_cache_directory_remote.?;
}
pub inline fn isContinuousIntegration(this: *PackageManager) bool {
return this.ci_mode.get();
}
@@ -558,6 +576,34 @@ fn httpThreadOnInitError(err: HTTP.InitError, opts: HTTP.HTTPThread.InitOpts) no
Global.crash();
}
pub fn useCopyfileBackendIfFaster(this: *PackageManager) void {
if (this.options.do.auto_choose_backend) {
// Only do this once.
this.options.do.auto_choose_backend = false;
const PackageInstall = @import("./PackageInstall.zig").PackageInstall;
if (PackageInstall.supported_method == .hardlink) {
// Vercel builds:
//
// --backend=copyfile:
// 268 packages installed [5.06s]
//
// --backend=hardlink
// 268 packages installed [11.55s]
if (this.isCacheDirectoryRemote() == .overlayfs) {
if (PackageManager.verbose_install) {
if (this.options.node_linker == .hoisted) {
Output.prettyErrorln("<d>[PackageManager]<r> using <b>\"copyfile\"<r> backend instead of <b>\"hardlink\"<r> for faster installs in OverlayFS. Consider --linker=isolated to further speed up installs.", .{});
} else {
Output.prettyErrorln("<d>[PackageManager]<r> using <b>\"copyfile\"<r> backend instead of <b>\"hardlink\"<r> for faster installs in OverlayFS", .{});
}
}
PackageInstall.supported_method = .copyfile;
}
}
}
}
pub fn init(
ctx: Command.Context,
cli: CommandLineArguments,

View File

@@ -565,6 +565,7 @@ pub fn load(
if (cli.backend) |backend| {
PackageInstall.supported_method = backend;
this.do.auto_choose_backend = false;
}
this.do.update_to_latest = cli.latest;
@@ -666,7 +667,8 @@ pub const Do = packed struct(u16) {
trust_dependencies_from_args: bool = false,
update_to_latest: bool = false,
analyze: bool = false,
_: u4 = 0,
auto_choose_backend: bool = true,
_: u3 = 0,
};
pub const Enable = packed struct(u16) {

View File

@@ -266,12 +266,16 @@ pub fn runTasks(
entry.value_ptr.manifest.pkg.public_max_age = timestamp_this_tick.?;
if (manager.options.enable.manifest_cache) {
Npm.PackageManifest.Serializer.saveAsync(
&entry.value_ptr.manifest,
manager.scopeForPackageName(name.slice()),
manager.getTemporaryDirectory(),
manager.getCacheDirectory(),
);
if (!bun.getRuntimeFeatureFlag(.BUN_FEATURE_FLAG_MANIFEST_CACHE_NO_SAVE_TTL)) {
if (manager.isCacheDirectoryRemote() == .none) {
Npm.PackageManifest.Serializer.saveAsync(
&entry.value_ptr.manifest,
manager.scopeForPackageName(name.slice()),
manager.getTemporaryDirectory(),
manager.getCacheDirectory(),
);
}
}
}
if (@hasField(@TypeOf(callbacks), "manifests_only") and callbacks.manifests_only) {

View File

@@ -83,6 +83,7 @@ pub fn installHoistedPackages(
var summary = PackageInstall.Summary{};
{
this.useCopyfileBackendIfFaster();
var iterator = Lockfile.Tree.Iterator(.node_modules).init(this.lockfile);
if (comptime Environment.isPosix) {
Bin.Linker.ensureUmask();

View File

@@ -620,6 +620,8 @@ pub fn installIsolatedPackages(
var seen_workspace_ids: std.AutoHashMapUnmanaged(PackageID, void) = .empty;
defer seen_workspace_ids.deinit(lockfile.allocator);
manager.useCopyfileBackendIfFaster();
const tasks = try manager.allocator.alloc(Store.Installer.Task, store.entries.len);
defer manager.allocator.free(tasks);

View File

@@ -830,6 +830,49 @@ pub fn stat(path: [:0]const u8) Maybe(bun.Stat) {
}
}
pub const RemoteFileSystem = enum {
overlayfs,
remote,
none,
const remote_fs_magic = [_]u32{
0xadf5, // ADFS_SUPER_MAGIC
0xadff, // AFFS_SUPER_MAGIC
0x5346414f, // AFS_SUPER_MAGIC
0x09041934, // ANON_INODE_FS_MAGIC
0x0187, // AUTOFS_SUPER_MAGIC
0x6969, // NFS_SUPER_MAGIC
0x6e736673, // NSFS_MAGIC
0x564c, // NCP_SUPER_MAGIC
0x517b, // SMB_SUPER_MAGIC
0xfe534d42, // SMB2_MAGIC_NUMBER
0x65735546, // FUSE_SUPER_MAGIC
0x6165676c, // PSTOREFS_MAGIC
0x68191122, // QNX6_SUPER_MAGIC
0x62646576, // BDEVFS_MAGIC
0x62656572, // SYSFS_MAGIC
0x63677270, // CGROUP2_SUPER_MAGIC
0x63637275, // CRAMFS_MAGIC
0x64626720, // DEBUGFS_MAGIC
};
const OVERLAYFS_MAGIC = 0x794c7630;
pub fn get(stat_fs: *const bun.StatFS) RemoteFileSystem {
if (stat_fs.f_type == OVERLAYFS_MAGIC) {
return .overlayfs;
}
for (remote_fs_magic) |magic| {
if (stat_fs.f_type == magic) {
return .remote;
}
}
return .none;
}
};
pub fn statfs(path: [:0]const u8) Maybe(bun.StatFS) {
if (Environment.isWindows) {
return .{ .err = Error.fromCode(.ENOSYS, .statfs) };
@@ -850,6 +893,21 @@ pub fn statfs(path: [:0]const u8) Maybe(bun.StatFS) {
}
}
pub fn fstatfs(fd: bun.FileDescriptor) Maybe(bun.StatFS) {
if (Environment.isWindows) {
return .{ .err = Error.fromCode(.ENOSYS, .fstatfs) };
} else {
var statfs_ = mem.zeroes(bun.StatFS);
const rc = c.fstatfs(fd.cast(), &statfs_);
if (comptime Environment.allow_assert)
log("fstatfs({}) = {d}", .{ fd, rc });
if (Maybe(bun.StatFS).errnoSysFd(rc, .fstatfs, fd)) |err| return err;
return Maybe(bun.StatFS){ .result = statfs_ };
}
}
pub fn lstat(path: [:0]const u8) Maybe(bun.Stat) {
if (Environment.isWindows) {
return sys_uv.lstat(path);