Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make reported node.js version a build option #12104

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
make reported node.js version a compiler flag
  • Loading branch information
Jarred-Sumner committed Jun 24, 2024
commit 139a1db9a263773525c705b37064c9be1e1e5999
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD_REQUIRED ON)

# Should not start with v
# Used in process.version, process.versions.node, napi, and elsewhere
set(REPORTED_NODEJS_VERSION "22.3.0")

# WebKit uses -std=gnu++20 on non-macOS non-Windows
# If we do not set this, it will crash at startup on the first memory allocation.
if(NOT WIN32 AND NOT APPLE)
Expand Down Expand Up @@ -880,6 +884,7 @@ if(NOT BUN_LINK_ONLY AND NOT BUN_CPP_ONLY)
"-Dcpu=${CPU_TARGET}"
"-Dtarget=${ZIG_TARGET}"
"-Denable_logs=${ENABLE_LOGS}"
"-Dreported_nodejs_version=${REPORTED_NODEJS_VERSION}"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/build.zig"
"${ZIG_FILES}"
Expand Down Expand Up @@ -962,6 +967,7 @@ add_compile_definitions(
"IS_BUILD"
"BUILDING_JSCONLY__"
"BUN_DYNAMIC_JS_LOAD_PATH=\"${BUN_WORKDIR}/js\""
"REPORTED_NODEJS_VERSION=\"${REPORTED_NODEJS_VERSION}\""
)

if(NOT ASSERT_ENABLED)
Expand Down
14 changes: 14 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ comptime {
}
}

const default_reported_nodejs_version = "22.3.0";

const zero_sha = "0000000000000000000000000000000000000000";

const BunBuildOptions = struct {
Expand All @@ -46,6 +48,7 @@ const BunBuildOptions = struct {
sha: []const u8,
enable_logs: bool = false,
tracy_callstack_depth: u16,
reported_nodejs_version: []const u8 = default_reported_nodejs_version,

generated_code_dir: []const u8,

Expand All @@ -70,6 +73,14 @@ const BunBuildOptions = struct {
opts.addOption([:0]const u8, "sha", b.allocator.dupeZ(u8, this.sha) catch @panic("OOM"));
opts.addOption(bool, "baseline", this.isBaseline());
opts.addOption(bool, "enable_logs", this.enable_logs);
opts.addOption([:0]const u8, "reported_nodejs_version", b.allocator.dupeZ(u8, this.reported_nodejs_version) catch @panic("OOM"));
if (this.reported_nodejs_version.len > 0 and this.reported_nodejs_version[0] == 'v') {
@panic("Node.js version should not start with 'v'");
}

if (this.reported_nodejs_version.len == 0) {
@panic("Node.js version should not be empty");
}

const mod = opts.createModule();
this.cached_options_module = mod;
Expand Down Expand Up @@ -167,6 +178,8 @@ pub fn build(b: *Build) !void {
break :canary if (rev == 0) null else rev;
},

.reported_nodejs_version = b.option([]const u8, "reported_nodejs_version", "Reported Node.js version") orelse default_reported_nodejs_version,

.sha = sha: {
const sha = b.option([]const u8, "sha", "Force the git sha") orelse
b.graph.env_map.get("GITHUB_SHA") orelse
Expand Down Expand Up @@ -265,6 +278,7 @@ pub fn build(b: *Build) !void {
.sha = build_options.sha,
.tracy_callstack_depth = build_options.tracy_callstack_depth,
.version = build_options.version,
.reported_nodejs_version = build_options.reported_nodejs_version,
.generated_code_dir = build_options.generated_code_dir,
};
var obj = addBunObject(b, &options);
Expand Down
1 change: 0 additions & 1 deletion src/Global.zig
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ pub const BunInfo = struct {
};

pub const user_agent = "Bun/" ++ Global.package_json_version;

pub export const Bun__userAgent: [*:0]const u8 = Global.user_agent;

comptime {
Expand Down
10 changes: 6 additions & 4 deletions src/bun.js/bindings/BunProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ namespace Bun {

using namespace JSC;

#define REPORTED_NODE_VERSION "22.2.0"
#ifndef REPORTED_NODEJS_VERSION
#define REPORTED_NODEJS_VERSION "22.3.0"
Jarred-Sumner marked this conversation as resolved.
Show resolved Hide resolved
#endif
#define processObjectBindingCodeGenerator processObjectInternalsBindingCodeGenerator
#define setProcessObjectInternalsMainModuleCodeGenerator processObjectInternalsSetMainModuleCodeGenerator
#define setProcessObjectMainModuleCodeGenerator setMainModuleCodeGenerator
Expand Down Expand Up @@ -147,7 +149,7 @@ static JSValue constructVersions(VM& vm, JSObject* processObject)
JSC::JSObject* object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 23);

object->putDirect(vm, JSC::Identifier::fromString(vm, "node"_s),
JSC::JSValue(JSC::jsOwnedString(vm, makeAtomString(REPORTED_NODE_VERSION))));
JSC::JSValue(JSC::jsOwnedString(vm, makeAtomString(REPORTED_NODEJS_VERSION))));
object->putDirect(
vm, JSC::Identifier::fromString(vm, "bun"_s),
JSC::JSValue(JSC::jsOwnedString(vm, makeAtomString(Bun__version + 1 /* remove "v" prefix */))));
Expand Down Expand Up @@ -1513,7 +1515,7 @@ static JSValue constructReportObjectComplete(VM& vm, Zig::GlobalObject* globalOb
}

header->putDirect(vm, JSC::Identifier::fromString(vm, "commandLine"_s), JSValue::decode(Bun__Process__getExecArgv(globalObject)), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "nodejsVersion"_s), JSC::jsString(vm, String::fromLatin1(REPORTED_NODE_VERSION)), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "nodejsVersion"_s), JSC::jsString(vm, String::fromLatin1(REPORTED_NODEJS_VERSION)), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "wordSize"_s), JSC::jsNumber(64), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "arch"_s), constructArch(vm, header), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "platform"_s), constructPlatform(vm, header), 0);
Expand Down Expand Up @@ -1950,7 +1952,7 @@ static JSValue constructBrowser(VM& vm, JSObject* processObject)

static JSValue constructVersion(VM& vm, JSObject* processObject)
{
return JSC::jsString(vm, makeString("v", REPORTED_NODE_VERSION));
return JSC::jsString(vm, makeString("v", REPORTED_NODEJS_VERSION));
}

static JSValue constructIsBun(VM& vm, JSObject* processObject)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/run_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ pub const RunCommand = struct {
// the use of npm/? is copying yarn
// e.g.
// > "yarn/1.22.4 npm/? node/v12.16.3 darwin x64",
"bun/" ++ Global.package_json_version ++ " npm/? node/v22.2.0 " ++ Global.os_name ++ " " ++ Global.arch_name,
"bun/" ++ Global.package_json_version ++ " npm/? node/v" ++ Environment.reported_nodejs_version ++ " " ++ Global.os_name ++ " " ++ Global.arch_name,
) catch unreachable;

if (this_bundler.env.get("npm_execpath") == null) {
Expand Down
2 changes: 2 additions & 0 deletions src/env.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ const BuildOptions = if (isTest) struct {
pub const is_canary = false;
pub const base_path = "/tmp";
pub const canary_revision = 0;
pub const reported_nodejs_version = "22.3.0";
} else @import("root").build_options;

pub const reported_nodejs_version = BuildOptions.reported_nodejs_version;
pub const baseline = BuildOptions.baseline;
pub const enableSIMD: bool = !baseline;
pub const git_sha = BuildOptions.sha;
Expand Down
2 changes: 1 addition & 1 deletion src/install/semver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ pub const SlicedString = struct {
slice: string,

pub inline fn init(buf: string, slice: string) SlicedString {
if (Environment.allow_assert) {
if (Environment.allow_assert and !@inComptime()) {
if (@intFromPtr(buf.ptr) > @intFromPtr(slice.ptr)) {
@panic("SlicedString.init buf is not in front of slice");
}
Expand Down
12 changes: 7 additions & 5 deletions src/napi/napi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1169,13 +1169,15 @@ pub const napi_node_version = extern struct {
major: u32,
minor: u32,
patch: u32,
release: [*c]const u8,
release: [*:0]const u8,

const parsed_nodejs_version = std.SemanticVersion.parse(bun.Environment.reported_nodejs_version) catch @panic("Invalid reported Node.js version");

pub const global: napi_node_version = .{
.major = 17,
.minor = 7,
.patch = 17,
.release = "Bun!!!",
.major = parsed_nodejs_version.major,
.minor = parsed_nodejs_version.minor,
.patch = parsed_nodejs_version.patch,
.release = "node",
};
};
pub const struct_napi_async_cleanup_hook_handle__ = opaque {};
Expand Down
Loading