Skip to content

Commit 7d75120

Browse files
authored
remove more usingnamespace (oven-sh#19042)
1 parent a380967 commit 7d75120

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1328
-943
lines changed

.git-blame-ignore-revs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Add commits to ignore in `git blame`. This allows large stylistic refactors to
2+
# avoid mucking up blames.
3+
#
4+
# To configure git to use this, run:
5+
#
6+
# git config blame.ignoreRevsFile .git-blame-ignore-revs
7+
#
8+
4ec410e0d7c5f6a712c323444edbf56b48d432d8 # make @import("bun") work in zig (#19096)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ test/cli/install/registry/packages/publish-pkg-*
153153
test/cli/install/registry/packages/@secret/publish-pkg-8
154154
test/js/third_party/prisma/prisma/sqlite/dev.db-journal
155155
tmp
156+
codegen-for-zig-team.tar.gz
156157

157158
# Dependencies
158159
/vendor

build.zig

Lines changed: 87 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const builtin = @import("builtin");
44
const Build = std.Build;
55
const Step = Build.Step;
66
const Compile = Step.Compile;
7-
const LazyPath = Step.LazyPath;
7+
const LazyPath = Build.LazyPath;
88
const Target = std.Target;
99
const ResolvedTarget = std.Build.ResolvedTarget;
1010
const CrossTarget = std.zig.CrossTarget;
@@ -21,18 +21,18 @@ const pathRel = fs.path.relative;
2121
/// When updating this, make sure to adjust SetupZig.cmake
2222
const recommended_zig_version = "0.14.0";
2323

24-
comptime {
25-
if (!std.mem.eql(u8, builtin.zig_version_string, recommended_zig_version)) {
26-
@compileError(
27-
"" ++
28-
"Bun requires Zig version " ++ recommended_zig_version ++ ", but you have " ++
29-
builtin.zig_version_string ++ ". This is automatically configured via Bun's " ++
30-
"CMake setup. You likely meant to run `bun run build`. If you are trying to " ++
31-
"upgrade the Zig compiler, edit ZIG_COMMIT in cmake/tools/SetupZig.cmake or " ++
32-
"comment this error out.",
33-
);
34-
}
35-
}
24+
// comptime {
25+
// if (!std.mem.eql(u8, builtin.zig_version_string, recommended_zig_version)) {
26+
// @compileError(
27+
// "" ++
28+
// "Bun requires Zig version " ++ recommended_zig_version ++ ", but you have " ++
29+
// builtin.zig_version_string ++ ". This is automatically configured via Bun's " ++
30+
// "CMake setup. You likely meant to run `bun run build`. If you are trying to " ++
31+
// "upgrade the Zig compiler, edit ZIG_COMMIT in cmake/tools/SetupZig.cmake or " ++
32+
// "comment this error out.",
33+
// );
34+
// }
35+
// }
3636

3737
const zero_sha = "0000000000000000000000000000000000000000";
3838

@@ -93,6 +93,7 @@ const BunBuildOptions = struct {
9393
opts.addOption(bool, "baseline", this.isBaseline());
9494
opts.addOption(bool, "enable_logs", this.enable_logs);
9595
opts.addOption([]const u8, "reported_nodejs_version", b.fmt("{}", .{this.reported_nodejs_version}));
96+
opts.addOption(bool, "zig_self_hosted_backend", this.no_llvm);
9697

9798
const mod = opts.createModule();
9899
this.cached_options_module = mod;
@@ -198,10 +199,7 @@ pub fn build(b: *Build) !void {
198199

199200
const bun_version = b.option([]const u8, "version", "Value of `Bun.version`") orelse "0.0.0";
200201

201-
b.reference_trace = ref_trace: {
202-
const trace = b.option(u32, "reference-trace", "Set the reference trace") orelse 24;
203-
break :ref_trace if (trace == 0) null else trace;
204-
};
202+
b.reference_trace = b.reference_trace orelse 32;
205203

206204
const obj_format = b.option(ObjectFormat, "obj_format", "Output file for object files") orelse .obj;
207205

@@ -388,7 +386,22 @@ pub fn build(b: *Build) !void {
388386
// zig build translate-c-headers
389387
{
390388
const step = b.step("translate-c", "Copy generated translated-c-headers.zig to zig-out");
391-
step.dependOn(&b.addInstallFile(getTranslateC(b, b.graph.host, .Debug).getOutput(), "translated-c-headers.zig").step);
389+
for ([_]TargetDescription{
390+
.{ .os = .windows, .arch = .x86_64 },
391+
.{ .os = .mac, .arch = .x86_64 },
392+
.{ .os = .mac, .arch = .aarch64 },
393+
.{ .os = .linux, .arch = .x86_64 },
394+
.{ .os = .linux, .arch = .aarch64 },
395+
.{ .os = .linux, .arch = .x86_64, .musl = true },
396+
.{ .os = .linux, .arch = .aarch64, .musl = true },
397+
}) |t| {
398+
const resolved = t.resolveTarget(b);
399+
step.dependOn(
400+
&b.addInstallFile(getTranslateC(b, resolved, .Debug), b.fmt("translated-c-headers/{s}.zig", .{
401+
resolved.result.zigTriple(b.allocator) catch @panic("OOM"),
402+
})).step,
403+
);
404+
}
392405
}
393406

394407
// zig build enum-extractor
@@ -405,23 +418,32 @@ pub fn build(b: *Build) !void {
405418
}
406419
}
407420

408-
pub fn addMultiCheck(
421+
const TargetDescription = struct {
422+
os: OperatingSystem,
423+
arch: Arch,
424+
musl: bool = false,
425+
426+
fn resolveTarget(desc: TargetDescription, b: *Build) std.Build.ResolvedTarget {
427+
return b.resolveTargetQuery(.{
428+
.os_tag = OperatingSystem.stdOSTag(desc.os),
429+
.cpu_arch = desc.arch,
430+
.cpu_model = getCpuModel(desc.os, desc.arch) orelse .determined_by_arch_os,
431+
.os_version_min = getOSVersionMin(desc.os),
432+
.glibc_version = if (desc.musl) null else getOSGlibCVersion(desc.os),
433+
});
434+
}
435+
};
436+
437+
fn addMultiCheck(
409438
b: *Build,
410439
parent_step: *Step,
411440
root_build_options: BunBuildOptions,
412-
to_check: []const struct { os: OperatingSystem, arch: Arch, musl: bool = false },
441+
to_check: []const TargetDescription,
413442
optimize: []const std.builtin.OptimizeMode,
414443
) void {
415444
for (to_check) |check| {
416445
for (optimize) |mode| {
417-
const check_target = b.resolveTargetQuery(.{
418-
.os_tag = OperatingSystem.stdOSTag(check.os),
419-
.cpu_arch = check.arch,
420-
.cpu_model = getCpuModel(check.os, check.arch) orelse .determined_by_arch_os,
421-
.os_version_min = getOSVersionMin(check.os),
422-
.glibc_version = if (check.musl) null else getOSGlibCVersion(check.os),
423-
});
424-
446+
const check_target = check.resolveTarget(b);
425447
var options: BunBuildOptions = .{
426448
.target = check_target,
427449
.os = check.os,
@@ -445,7 +467,13 @@ pub fn addMultiCheck(
445467
}
446468
}
447469

448-
fn getTranslateC(b: *Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *Step.TranslateC {
470+
fn getTranslateC(b: *Build, initial_target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) LazyPath {
471+
const target = b.resolveTargetQuery(q: {
472+
var query = initial_target.query;
473+
if (query.os_tag == .windows)
474+
query.abi = .gnu;
475+
break :q query;
476+
});
449477
const translate_c = b.addTranslateC(.{
450478
.root_source_file = b.path("src/c-headers-for-zig.h"),
451479
.target = target,
@@ -461,7 +489,35 @@ fn getTranslateC(b: *Build, target: std.Build.ResolvedTarget, optimize: std.buil
461489
const str, const value = entry;
462490
translate_c.defineCMacroRaw(b.fmt("{s}={d}", .{ str, @intFromBool(value) }));
463491
}
464-
return translate_c;
492+
493+
if (target.result.os.tag == .windows) {
494+
// translate-c is unable to translate the unsuffixed windows functions
495+
// like `SetCurrentDirectory` since they are defined with an odd macro
496+
// that translate-c doesn't handle.
497+
//
498+
// #define SetCurrentDirectory __MINGW_NAME_AW(SetCurrentDirectory)
499+
//
500+
// In these cases, it's better to just reference the underlying function
501+
// directly: SetCurrentDirectoryW. To make the error better, a post
502+
// processing step is applied to the translate-c file.
503+
//
504+
// Additionally, this step makes it so that decls like NTSTATUS and
505+
// HANDLE point to the standard library structures.
506+
const helper_exe = b.addExecutable(.{
507+
.name = "process_windows_translate_c",
508+
.root_module = b.createModule(.{
509+
.root_source_file = b.path("src/codegen/process_windows_translate_c.zig"),
510+
.target = b.graph.host,
511+
.optimize = .Debug,
512+
}),
513+
});
514+
const in = translate_c.getOutput();
515+
const run = b.addRunArtifact(helper_exe);
516+
run.addFileArg(in);
517+
const out = run.addOutputFileArg("c-headers-for-zig.zig");
518+
return out;
519+
}
520+
return translate_c.getOutput();
465521
}
466522

467523
pub fn addBunObject(b: *Build, opts: *BunBuildOptions) *Compile {
@@ -580,7 +636,7 @@ fn addInternalImports(b: *Build, mod: *Module, opts: *BunBuildOptions) void {
580636
mod.addImport("build_options", opts.buildOptionsModule(b));
581637

582638
const translate_c = getTranslateC(b, opts.target, opts.optimize);
583-
mod.addImport("translated-c-headers", translate_c.createModule());
639+
mod.addImport("translated-c-headers", b.createModule(.{ .root_source_file = translate_c }));
584640

585641
const zlib_internal_path = switch (os) {
586642
.windows => "src/deps/zlib.win32.zig",

misctools/lldb/lldb_pretty_printers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def log2_int(i): return i.bit_length() - 1
6161
'try',
6262
'union',
6363
'unreachable',
64-
'usingnamespace',
6564
'var',
6665
'volatile',
6766
'while',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
},
3232
"scripts": {
3333
"build": "bun run build:debug",
34+
"watch": "bun zig build check --watch",
3435
"bd": "(bun run --silent build:debug &> /tmp/bun.debug.build.log || (cat /tmp/bun.debug.build.log && rm -rf /tmp/bun.debug.build.log && exit 1)) && rm -f /tmp/bun.debug.build.log && ./build/debug/bun-debug",
3536
"build:debug": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -B build/debug",
3637
"build:valgrind": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_BASELINE=ON -ENABLE_VALGRIND=ON -B build/debug-valgrind",

scripts/pack-codegen-for-zig-team.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
if ! test -d build/debug/codegen; then
3+
echo "Missing codegen"
4+
exit 1
5+
fi
6+
7+
out="codegen-for-zig-team.tar.gz"
8+
tar -cf "$out" \
9+
build/debug/codegen \
10+
src/bun.js/bindings/GeneratedBindings.zig \
11+
src/bun.js/bindings/GeneratedJS2Native.zig
12+
echo "-> $out"

src/StaticHashMap.zig

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,20 @@ pub fn StaticHashMap(comptime K: type, comptime V: type, comptime Context: type,
5757
// get_probe_count: usize = 0,
5858
// del_probe_count: usize = 0,
5959

60-
pub usingnamespace HashMapMixin(Self, K, V, Context);
60+
const impl = HashMapMixin(Self, K, V, Context);
61+
pub const putAssumeCapacity = impl.putAssumeCapacity;
62+
pub const slice = impl.slice;
63+
pub const clearRetainingCapacity = impl.clearRetainingCapacity;
64+
pub const putAssumeCapacityContext = impl.putAssumeCapacityContext;
65+
pub const getOrPutAssumeCapacity = impl.getOrPutAssumeCapacity;
66+
pub const getOrPutAssumeCapacityContext = impl.getOrPutAssumeCapacityContext;
67+
pub const get = impl.get;
68+
pub const getContext = impl.getContext;
69+
pub const has = impl.has;
70+
pub const hasWithHash = impl.hasWithHash;
71+
pub const hasContext = impl.hasContext;
72+
pub const delete = impl.delete;
73+
pub const deleteContext = impl.deleteContext;
6174
};
6275
}
6376

@@ -96,7 +109,20 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime Context: type, compt
96109
// get_probe_count: usize = 0,
97110
// del_probe_count: usize = 0,
98111

99-
pub usingnamespace HashMapMixin(Self, K, V, Context);
112+
const impl = HashMapMixin(Self, K, V, Context);
113+
pub const putAssumeCapacity = impl.putAssumeCapacity;
114+
pub const slice = impl.slice;
115+
pub const clearRetainingCapacity = impl.clearRetainingCapacity;
116+
pub const putAssumeCapacityContext = impl.putAssumeCapacityContext;
117+
pub const getOrPutAssumeCapacity = impl.getOrPutAssumeCapacity;
118+
pub const getOrPutAssumeCapacityContext = impl.getOrPutAssumeCapacityContext;
119+
pub const get = impl.get;
120+
pub const getContext = impl.getContext;
121+
pub const has = impl.has;
122+
pub const hasWithHash = impl.hasWithHash;
123+
pub const hasContext = impl.hasContext;
124+
pub const delete = impl.delete;
125+
pub const deleteContext = impl.deleteContext;
100126

101127
pub fn initCapacity(gpa: mem.Allocator, capacity: u64) !Self {
102128
assert(math.isPowerOfTwo(capacity));

src/boringssl.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ pub fn ERR_toJS(globalThis: *JSC.JSGlobalObject, err_code: u32) JSC.JSValue {
222222

223223
const error_message: []const u8 = bun.sliceTo(outbuf[0..], 0);
224224
if (error_message.len == "BoringSSL ".len) {
225-
return globalThis.ERR_BORINGSSL("An unknown BoringSSL error occurred: {d}", .{err_code}).toJS();
225+
return globalThis.ERR(.BORINGSSL, "An unknown BoringSSL error occurred: {d}", .{err_code}).toJS();
226226
}
227227

228-
return globalThis.ERR_BORINGSSL("{s}", .{error_message}).toJS();
228+
return globalThis.ERR(.BORINGSSL, "{s}", .{error_message}).toJS();
229229
}

src/brotli.zig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
const bun = @import("bun");
22
const std = @import("std");
3-
pub const c = struct {
4-
pub usingnamespace @import("./deps/brotli_decoder.zig");
5-
pub usingnamespace @import("./deps/brotli_encoder.zig");
6-
};
3+
pub const c = @import("./deps/brotli_c.zig");
74
const BrotliDecoder = c.BrotliDecoder;
85
const BrotliEncoder = c.BrotliEncoder;
96

src/bun.js/api/BunObject.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ export fn Bun__resolveSync(global: *JSGlobalObject, specifier: JSValue, source:
892892
defer specifier_str.deref();
893893

894894
if (specifier_str.length() == 0) {
895-
return global.ERR_INVALID_ARG_VALUE("The argument 'id' must be a non-empty string. Received ''", .{}).throw() catch .zero;
895+
return global.ERR(.INVALID_ARG_VALUE, "The argument 'id' must be a non-empty string. Received ''", .{}).throw() catch .zero;
896896
}
897897

898898
const source_str = source.toBunString(global) catch return .zero;
@@ -916,7 +916,7 @@ export fn Bun__resolveSyncWithPaths(
916916
defer specifier_str.deref();
917917

918918
if (specifier_str.length() == 0) {
919-
return global.ERR_INVALID_ARG_VALUE("The argument 'id' must be a non-empty string. Received ''", .{}).throw() catch .zero;
919+
return global.ERR(.INVALID_ARG_VALUE, "The argument 'id' must be a non-empty string. Received ''", .{}).throw() catch .zero;
920920
}
921921

922922
const source_str = source.toBunString(global) catch return .zero;
@@ -939,7 +939,7 @@ export fn Bun__resolveSyncWithSource(global: *JSGlobalObject, specifier: JSValue
939939
const specifier_str = specifier.toBunString(global) catch return .zero;
940940
defer specifier_str.deref();
941941
if (specifier_str.length() == 0) {
942-
return global.ERR_INVALID_ARG_VALUE("The argument 'id' must be a non-empty string. Received ''", .{}).throw() catch .zero;
942+
return global.ERR(.INVALID_ARG_VALUE, "The argument 'id' must be a non-empty string. Received ''", .{}).throw() catch .zero;
943943
}
944944
return JSC.toJSHostValue(global, doResolveWithArgs(global, specifier_str, source.*, is_esm, true, is_user_require_resolve));
945945
}
@@ -1082,7 +1082,7 @@ pub fn serve(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.J
10821082
}
10831083
const obj = server.toJS(globalObject);
10841084
if (route_list_object != .zero) {
1085-
ServerType.routeListSetCached(obj, globalObject, route_list_object);
1085+
ServerType.js.routeListSetCached(obj, globalObject, route_list_object);
10861086
}
10871087
server.js_value.set(globalObject, obj);
10881088

0 commit comments

Comments
 (0)