Skip to content

Commit

Permalink
add jsc to features list (#10759)
Browse files Browse the repository at this point in the history
  • Loading branch information
paperdave authored May 2, 2024
1 parent 44e09bb commit d66a4fc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/analytics/analytics_thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub fn isCI() bool {

/// This answers, "What parts of bun are people actually using?"
pub const Features = struct {
/// Set right before JSC::initialize is called
pub var jsc: usize = 0;
pub var @"Bun.stderr": usize = 0;
pub var @"Bun.stdin": usize = 0;
pub var @"Bun.stdout": usize = 0;
Expand All @@ -88,6 +90,7 @@ pub const Features = struct {
pub var dotenv: usize = 0;
pub var external: usize = 0;
pub var extracted_packages: usize = 0;
/// Incremented for each call to `fetch`
pub var fetch: usize = 0;
pub var filesystem_router: usize = 0;
pub var git_dependencies: usize = 0;
Expand Down Expand Up @@ -171,6 +174,30 @@ pub const Features = struct {
};
};

pub fn validateFeatureName(name: []const u8) void {
if (name.len > 64) @compileError("Invalid feature name: " ++ name);
for (name) |char| {
switch (char) {
'a'...'z', 'A'...'Z', '0'...'9', '_', '.', ':', '-' => {},
else => @compileError("Invalid feature name: " ++ name),
}
}
}

pub const packed_features_list = brk: {
const decls = std.meta.declarations(Features);
var names: [decls.len][]const u8 = undefined;
var i = 0;
for (decls) |decl| {
if (@TypeOf(@field(Features, decl.name)) == usize) {
validateFeatureName(decl.name);
names[i] = decl.name;
i += 1;
}
}
break :brk names[0..i];
};

pub const PackedFeatures = @Type(.{
.Struct = .{
.layout = .Packed,
Expand Down Expand Up @@ -214,19 +241,6 @@ pub fn packedFeatures() PackedFeatures {
return bits;
}

pub const packed_features_list = brk: {
const decls = std.meta.declarations(Features);
var names: [decls.len][]const u8 = undefined;
var i = 0;
for (decls) |decl| {
if (@TypeOf(@field(Features, decl.name)) == usize) {
names[i] = decl.name;
i += 1;
}
}
break :brk names[0..i];
};

pub const EventName = enum(u8) {
bundle_success,
bundle_fail,
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6279,6 +6279,7 @@ pub const DOMCalls = &.{
extern "c" fn JSCInitialize(env: [*]const [*:0]u8, count: usize, cb: *const fn ([*]const u8, len: usize) callconv(.C) void) void;
pub fn initialize() void {
JSC.markBinding(@src());
bun.analytics.Features.jsc += 1;
JSCInitialize(
std.os.environ.ptr,
std.os.environ.len,
Expand Down

0 comments on commit d66a4fc

Please sign in to comment.