Skip to content

Commit

Permalink
the events, they loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Mar 20, 2022
1 parent a6b1285 commit bc85dd2
Show file tree
Hide file tree
Showing 24 changed files with 2,391 additions and 26 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"src/deps/s2n-tls": true,
"src/deps/boringssl": true,
"src/deps/openssl": true,
"src/deps/uws": true,
"src/deps/zlib": true,
"src/deps/lol-html": true,
"integration/snippets/package-json-exports/_node_modules_copy": true
Expand Down
32 changes: 24 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ POSIX_PKG_MANAGER=sudo apt
STRIP=

ifeq ($(OS_NAME),darwin)
STRIP=strip
STRIP=/usr/bin/strip
endif

ifeq ($(OS_NAME),linux)
Expand All @@ -188,7 +188,7 @@ MAC_INCLUDE_DIRS := -I$(WEBKIT_RELEASE_DIR)/JavaScriptCore/PrivateHeaders \
LINUX_INCLUDE_DIRS := -I$(JSC_INCLUDE_DIR) \
-Isrc/javascript/jsc/bindings/

INCLUDE_DIRS :=
INCLUDE_DIRS := -I$(BUN_DEPS_DIR)/uws



Expand Down Expand Up @@ -243,7 +243,8 @@ CLANG_FLAGS = $(INCLUDE_DIRS) \
-DBUILDING_JSCONLY__ \
-DASSERT_ENABLED=0 \
-fvisibility=hidden \
-fvisibility-inlines-hidden
-fvisibility-inlines-hidden \
-fPIC -fno-semantic-interposition

PLATFORM_LINKER_FLAGS =

Expand All @@ -266,13 +267,13 @@ ARCHIVE_FILES_WITHOUT_LIBCRYPTO = $(MIMALLOC_FILE_PATH) \
$(BUN_DEPS_OUT_DIR)/libarchive.a \
$(BUN_DEPS_OUT_DIR)/libssl.a \
$(BUN_DEPS_OUT_DIR)/picohttpparser.o \
$(BUN_DEPS_OUT_DIR)/liblolhtml.a
$(BUN_DEPS_OUT_DIR)/liblolhtml.a \
$(BUN_DEPS_OUT_DIR)/uSockets.a \
$(BUN_DEPS_OUT_DIR)/libuwsockets.o

ARCHIVE_FILES = $(ARCHIVE_FILES_WITHOUT_LIBCRYPTO) $(BUN_DEPS_OUT_DIR)/libcrypto.boring.a




STATIC_MUSL_FLAG ?=

ifeq ($(OS_NAME), linux)
Expand All @@ -289,7 +290,8 @@ PLATFORM_LINKER_FLAGS = \
-static-libgcc \
-fno-omit-frame-pointer $(CFLAGS) \
-Wl,--compress-debug-sections,zlib \
${STATIC_MUSL_FLAG}
${STATIC_MUSL_FLAG} \
-Wl,-Bsymbolic-functions

ARCHIVE_FILES_WITHOUT_LIBCRYPTO += $(BUN_DEPS_OUT_DIR)/libbacktrace.a
endif
Expand Down Expand Up @@ -428,6 +430,19 @@ build-obj-wasm-small:
build-obj-safe:
$(ZIG) build obj -Drelease-safe

UWS_CC_FLAGS = -pthread -DLIBUS_USE_OPENSSL=1 -DLIBUS_USE_BORINGSSL=1 -DWITH_BORINGSSL=1 -Wpedantic -Wall -Wextra -Wsign-conversion -Wconversion -Isrc -IuSockets/src -DUWS_WITH_PROXY
UWS_CXX_FLAGS = $(UWS_CC_FLAGS) -std=gnu++17
UWS_LDFLAGS = -I$(BUN_DEPS_DIR)/boringssl/include

usockets:
rm -rf $(BUN_DEPS_DIR)/uws/uSockets/*.o $(BUN_DEPS_DIR)/uws/uSockets/*.a
cd $(BUN_DEPS_DIR)/uws/uSockets && \
$(CC) $(CFLAGS) $(UWS_CC_FLAGS) $(UWS_LDFLAGS) $(DEFAULT_LINKER_FLAGS) $(PLATFORM_LINKER_FLAGS) -O3 -g -c -c src/*.c src/eventing/*.c src/crypto/*.c -flto && \
$(CXX) $(CXXFLAGS) $(UWS_CXX_FLAGS) $(UWS_LDFLAGS) $(DEFAULT_LINKER_FLAGS) $(PLATFORM_LINKER_FLAGS) -O3 -g -c src/crypto/*.cpp && \
ar rvs $(BUN_DEPS_OUT_DIR)/uSockets.a *.o

uws: usockets
$(CXX) -I$(BUN_DEPS_DIR)/uws/uSockets/src $(CLANG_FLAGS) $(UWS_CXX_FLAGS) $(UWS_LDFLAGS) -c -flto -I$(BUN_DEPS_DIR) $(BUN_DEPS_OUT_DIR)/uSockets.a $(BUN_DEPS_DIR)/libuwsockets.cpp -o $(BUN_DEPS_OUT_DIR)/libuwsockets.o



Expand Down Expand Up @@ -984,7 +999,8 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
-g \
-fno-exceptions \
-ffunction-sections -fdata-sections -g \
-ferror-limit=1000
-ferror-limit=1000 \
-emit-llvm -flto -fno-semantic-interposition

sizegen:
$(CXX) src/javascript/jsc/headergen/sizegen.cpp -o $(BUN_TMP_DIR)/sizegen $(CLANG_FLAGS) -O1
Expand Down
9 changes: 8 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ fn addInternalPackages(step: *std.build.LibExeObjStep, _: std.mem.Allocator, tar
.path = pkgPath("src/jsc_stub.zig"),
};

var uws: std.build.Pkg = .{
.name = "uws",
.path = pkgPath("src/deps/uws.zig"),
};

var javascript_core = if (target.getOsTag() == .freestanding)
javascript_core_stub
else
Expand All @@ -128,7 +133,7 @@ fn addInternalPackages(step: *std.build.LibExeObjStep, _: std.mem.Allocator, tar

io.dependencies = &.{analytics};

javascript_core.dependencies = &.{ http, strings, picohttp, io };
javascript_core.dependencies = &.{ http, strings, picohttp, io, uws };
http.dependencies = &.{
strings,
picohttp,
Expand Down Expand Up @@ -162,6 +167,7 @@ fn addInternalPackages(step: *std.build.LibExeObjStep, _: std.mem.Allocator, tar
step.addPackage(crash_reporter);
step.addPackage(datetime);
step.addPackage(lol_html);
step.addPackage(uws);
}
var output_dir: []const u8 = "";
fn panicIfNotFound(comptime filepath: []const u8) []const u8 {
Expand Down Expand Up @@ -519,6 +525,7 @@ pub fn linkObjectFiles(b: *std.build.Builder, obj: *std.build.LibExeObjStep, tar
.{ "libbmalloc.a", "libbmalloc.a" },
.{ "libbacktrace.a", "libbacktrace.a" },
.{ "liblolhtml.a", "liblolhtml.a" },
.{ "uSockets.a", "uSockets.a" },
});

for (dirs_to_search.slice()) |deps_path| {
Expand Down
Binary file modified integration/scripts/bun.lockb
Binary file not shown.
Binary file modified packages/bun-error/bun.lockb
Binary file not shown.
8 changes: 2 additions & 6 deletions src/bun_js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,14 @@ pub const Run = struct {

pub fn start(this: *Run) void {
var promise = this.vm.loadEntryPoint(this.entry_path) catch return;
this.vm.tick();

while (promise.status(this.vm.global.vm()) == .Pending) {
this.vm.tick();
}

if (promise.status(this.vm.global.vm()) == .Rejected) {
this.vm.defaultErrorHandler(promise.result(this.vm.global.vm()), null);
Global.exit(1);
}

_ = promise.result(this.vm.global.vm());
const result = promise.result(this.vm.global.vm());
JSC.C.JSValueProtect(this.vm.global.ref(), result.asObjectRef());

if (this.vm.log.msgs.items.len > 0) {
if (Output.enable_ansi_colors) {
Expand Down
4 changes: 3 additions & 1 deletion src/bundler/entry_points.zig
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ pub const ServerEntryPoint = struct {
\\//Auto-generated file
\\import * as start from '{s}{s}';
\\export * from '{s}{s}';
\\var entryNamespace = start;
\\if ('default' in start && "__internalIsCommonJSNamespace" in globalThis && __internalIsCommonJSNamespace(start)) {{
\\ start.default();
\\ entryNamespace = start.default();
\\}}
\\if(entryNamespace && 'serverless' in entryNamespace) Bun.startServer(entryNamespace.serverless);
,
.{
dir_to_use,
Expand Down
Loading

0 comments on commit bc85dd2

Please sign in to comment.