Skip to content

Commit

Permalink
Merge branch 'main' into riskymh/update-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RiskyMH authored Jan 11, 2025
2 parents c51a6f6 + 96dc7ed commit c1dc1b7
Show file tree
Hide file tree
Showing 168 changed files with 12,141 additions and 3,124 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ $ git clone https://github.com/oven-sh/WebKit vendor/WebKit

# Make a debug build of JSC. This will output build artifacts in ./vendor/WebKit/WebKitBuild/Debug
# Optionally, you can use `make jsc` for a release build
$ make jsc-debug
$ make jsc-debug && rm vendor/WebKit/WebKitBuild/Debug/JavaScriptCore/DerivedSources/inspector/InspectorProtocolObjects.h

# Build bun with the local JSC build
$ bun run build:local
Expand Down
2 changes: 1 addition & 1 deletion LATEST
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.42
1.1.43
5 changes: 5 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ pub fn addInstallObjectFile(
name: []const u8,
out_mode: ObjectFormat,
) *Step {
if (@import("builtin").os.tag != .windows and std.posix.getenvZ("COMPILE_ERRORS_ONLY") != null) {
const failstep = b.addSystemCommand(&.{"COMPILE_ERRORS_ONLY set but there were no compile errors"});
failstep.step.dependOn(&compile.step);
return &failstep.step;
}
// bin always needed to be computed or else the compilation will do nothing. zig build system bug?
const bin = compile.getEmittedBin();
return &b.addInstallFile(switch (out_mode) {
Expand Down
4 changes: 4 additions & 0 deletions bunfig.node-test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# FIXME: move this back to test/js/node
# https://github.com/oven-sh/bun/issues/16289
[test]
preload = ["./test/js/node/harness.ts", "./test/preload.ts"]
6 changes: 5 additions & 1 deletion cmake/tools/SetupWebKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ if(NOT WEBKIT_VERSION)
set(WEBKIT_VERSION e1a802a2287edfe7f4046a9dd8307c8b59f5d816)
endif()

string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX)

if(WEBKIT_LOCAL)
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/WebKit/WebKitBuild/${CMAKE_BUILD_TYPE})
else()
set(DEFAULT_WEBKIT_PATH ${CACHE_PATH}/webkit-${WEBKIT_VERSION})
set(DEFAULT_WEBKIT_PATH ${CACHE_PATH}/webkit-${WEBKIT_VERSION_PREFIX})
endif()

option(WEBKIT_PATH "The path to the WebKit directory")
Expand All @@ -28,6 +30,8 @@ if(WEBKIT_LOCAL)
${WEBKIT_PATH}
${WEBKIT_PATH}/JavaScriptCore/Headers/JavaScriptCore
${WEBKIT_PATH}/JavaScriptCore/PrivateHeaders
${WEBKIT_PATH}/JavaScriptCore/DerivedSources/inspector
${WEBKIT_PATH}/JavaScriptCore/PrivateHeaders/JavaScriptCore
${WEBKIT_PATH}/bmalloc/Headers
${WEBKIT_PATH}/WTF/Headers
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "bun",
"version": "1.1.43",
"version": "1.1.44",
"workspaces": [
"./packages/bun-types"
],
Expand Down
14 changes: 14 additions & 0 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,10 @@ declare module "bun" {
errors: number;
totalCount: number;
};

ADDRCONFIG: number;
ALL: number;
V4MAPPED: number;
};

interface DNSLookup {
Expand Down Expand Up @@ -1226,6 +1230,16 @@ declare module "bun" {
* Deletes the file.
*/
unlink(): Promise<void>;

/**
* Deletes the file. ( same as unlink )
*/
delete(): Promise<void>

/**
* Provides useful information about the file.
*/
stat(): Promise<Stats>
}
interface NetworkSink extends FileSink {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/bun-types/html-rewriter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ declare namespace HTMLRewriterTypes {

interface Element {
tagName: string;
readonly attributes: IterableIterator<string[]>;
readonly attributes: IterableIterator<[string, string]>;
readonly removed: boolean;
/** Whether the element is explicitly self-closing, e.g. `<foo />` */
readonly selfClosing: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/bun-usockets/src/internal/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ enum {
#define POLL_TYPE_MASK (POLL_TYPE_KIND_MASK | POLL_TYPE_POLLING_MASK)

/* Bun APIs implemented in Zig */
void Bun__lock(uint32_t *lock);
void Bun__unlock(uint32_t *lock);
void Bun__lock(zig_mutex_t *lock);
void Bun__unlock(zig_mutex_t *lock);

struct addrinfo_request;
struct addrinfo_result_entry {
Expand Down
14 changes: 13 additions & 1 deletion packages/bun-usockets/src/internal/loop_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@

#include <stdint.h>

#if defined(__APPLE__)
#include <os/lock.h>
typedef os_unfair_lock zig_mutex_t;
#elif defined(__linux__)
typedef uint32_t zig_mutex_t;
#elif defined(_WIN32)
// SRWLOCK
typedef void* zig_mutex_t;
#else
#error "Unsupported platform"
#endif

// IMPORTANT: When changing this, don't forget to update the zig version in uws.zig as well!
struct us_internal_loop_data_t {
struct us_timer_t *sweep_timer;
Expand All @@ -39,7 +51,7 @@ struct us_internal_loop_data_t {
int low_prio_budget;
struct us_connecting_socket_t *dns_ready_head;
struct us_connecting_socket_t *closed_connecting_head;
uint32_t mutex;
zig_mutex_t mutex;
void *parent_ptr;
char parent_tag;
/* We do not care if this flips or not, it doesn't matter */
Expand Down
32 changes: 12 additions & 20 deletions packages/bun-usockets/src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,30 @@
#ifndef WIN32
#include <sys/ioctl.h>
#endif
#include "wtf/Platform.h"

#if ASSERT_ENABLED
extern const size_t Bun__lock__size;
extern void __attribute((__noreturn__)) Bun__panic(const char* message, size_t length);
#define BUN_PANIC(message) Bun__panic(message, sizeof(message) - 1)
#endif

/* The loop has 2 fallthrough polls */
void us_internal_loop_data_init(struct us_loop_t *loop, void (*wakeup_cb)(struct us_loop_t *loop),
void (*pre_cb)(struct us_loop_t *loop), void (*post_cb)(struct us_loop_t *loop)) {
// We allocate with calloc, so we only need to initialize the specific fields in use.
loop->data.sweep_timer = us_create_timer(loop, 1, 0);
loop->data.recv_buf = malloc(LIBUS_RECV_BUFFER_LENGTH + LIBUS_RECV_BUFFER_PADDING * 2);
loop->data.send_buf = malloc(LIBUS_SEND_BUFFER_LENGTH);
loop->data.ssl_data = 0;
loop->data.head = 0;
loop->data.iterator = 0;
loop->data.closed_udp_head = 0;
loop->data.closed_head = 0;
loop->data.low_prio_head = 0;
loop->data.low_prio_budget = 0;

loop->data.pre_cb = pre_cb;
loop->data.post_cb = post_cb;
loop->data.iteration_nr = 0;

loop->data.closed_connecting_head = 0;
loop->data.dns_ready_head = 0;
loop->data.mutex = 0;

loop->data.parent_ptr = 0;
loop->data.parent_tag = 0;

loop->data.closed_context_head = 0;
loop->data.jsc_vm = 0;

loop->data.wakeup_async = us_internal_create_async(loop, 1, 0);
us_internal_async_set(loop->data.wakeup_async, (void (*)(struct us_internal_async *)) wakeup_cb);
#if ASSERT_ENABLED
if (Bun__lock__size != sizeof(loop->data.mutex)) {
BUN_PANIC("The size of the mutex must match the size of the lock");
}
#endif
}

void us_internal_loop_data_free(struct us_loop_t *loop) {
Expand Down
5 changes: 3 additions & 2 deletions packages/bun-uws/src/HttpResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,9 @@ struct HttpResponse : public AsyncSocket<SSL> {

/* Try and end the response. Returns [true, true] on success.
* Starts a timeout in some cases. Returns [ok, hasResponded] */
std::pair<bool, bool> tryEnd(std::string_view data, uint64_t totalSize = 0, bool closeConnection = false) {
return {internalEnd(data, totalSize, true, true, closeConnection), hasResponded()};
std::pair<bool, bool> tryEnd(std::string_view data, uintmax_t totalSize = 0, bool closeConnection = false) {
bool ok = internalEnd(data, totalSize, true, true, closeConnection);
return {ok, hasResponded()};
}

/* Write the end of chunked encoded stream */
Expand Down
21 changes: 15 additions & 6 deletions packages/bun-uws/src/HttpRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ struct HttpRouter {
std::string segment = std::string(getUrlSegment(i).first);
Node *next = nullptr;
for (std::unique_ptr<Node> &child : n->children) {
if (child->name == segment && child->isHighPriority == (priority == HIGH_PRIORITY)) {
if (((segment.length() && child->name.length() && segment[0] == ':' && child->name[0] == ':') || child->name == segment) && child->isHighPriority == (priority == HIGH_PRIORITY)) {
next = child.get();
break;
}
Expand Down Expand Up @@ -304,12 +304,19 @@ struct HttpRouter {
for (auto &p : root.children) {
if (p->name == method) {
/* Then route the url */
return executeHandlers(p.get(), 0, userData);
if (executeHandlers(p.get(), 0, userData)) {
return true;
} else {
break;
}
}
}

/* We did not find any handler for this method and url */
return false;
/* Always test any route last (this check should not be necessary if we always have at least one handler) */
if (root.children.empty()) [[unlikely]] {
return false;
}
return executeHandlers(root.children.back().get(), 0, userData);
}

/* Adds the corresponding entires in matching tree and handler list */
Expand Down Expand Up @@ -379,11 +386,11 @@ struct HttpRouter {
/* Removes ALL routes with the same handler as can be found with the given parameters.
* Removing a wildcard is done by removing ONE OF the methods the wildcard would match with.
* Example: If wildcard includes POST, GET, PUT, you can remove ALL THREE by removing GET. */
void remove(std::string method, std::string pattern, uint32_t priority) {
bool remove(std::string method, std::string pattern, uint32_t priority) {
uint32_t handler = findHandler(method, pattern, priority);
if (handler == UINT32_MAX) {
/* Not found or already removed, do nothing */
return;
return false;
}

/* Cull the entire tree */
Expand All @@ -394,6 +401,8 @@ struct HttpRouter {

/* Now remove the actual handler */
handlers.erase(handlers.begin() + (handler & HANDLER_MASK));

return true;
}
};

Expand Down
26 changes: 19 additions & 7 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,28 @@ function cmakePath(path) {
return path.replace(/\\/g, "/");
}

/** @param {string} str */
const toAlphaNumeric = str => str.replace(/[^a-z0-9]/gi, "-");
function getCachePath(branch) {
const buildPath = process.env.BUILDKITE_BUILD_PATH;
const repository = process.env.BUILDKITE_REPO;
const fork = process.env.BUILDKITE_PULL_REQUEST_REPO;
const repositoryKey = (fork || repository).replace(/[^a-z0-9]/gi, "-");
const branchName = (branch || process.env.BUILDKITE_BRANCH).replace(/[^a-z0-9]/gi, "-");
const {
BUILDKITE_BUILD_PATH: buildPath,
BUILDKITE_REPO: repository,
BUILDKITE_PULL_REQUEST_REPO: fork,
BUILDKITE_BRANCH,
BUILDKITE_STEP_KEY,
} = process.env;

// NOTE: settings that could be long should be truncated to avoid hitting max
// path length limit on windows (4096)
const repositoryKey = toAlphaNumeric(
// remove domain name, only leaving 'org/repo'
(fork || repository).replace(/^https?:\/\/github\.com\/?/, ""),
);
const branchName = toAlphaNumeric(branch || BUILDKITE_BRANCH);
const branchKey = branchName.startsWith("gh-readonly-queue-")
? branchName.slice(18, branchName.indexOf("-pr-"))
: branchName;
const stepKey = process.env.BUILDKITE_STEP_KEY.replace(/[^a-z0-9]/gi, "-");
: branchName.slice(0, 32);
const stepKey = toAlphaNumeric(BUILDKITE_STEP_KEY);
return resolve(buildPath, "..", "cache", repositoryKey, branchKey, stepKey);
}

Expand Down
Loading

0 comments on commit c1dc1b7

Please sign in to comment.