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

Upgrade to LLVM 17, fix linux debug build, upgrade JSC, remove some C API usages #10161

Merged
merged 34 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e85e95b
Upgrade to LLVM 17, JSC, remove more C API usages
Jarred-Sumner Apr 11, 2024
e2bc93d
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 11, 2024
630ed3d
Update scripts/setup.sh
Jarred-Sumner Apr 11, 2024
bece7c5
more
Jarred-Sumner Apr 11, 2024
ab3add3
update
Jarred-Sumner Apr 11, 2024
94cdff8
bump
Jarred-Sumner Apr 11, 2024
eee47fc
Merge branch 'main' into jarred/upgrade-llvm
Jarred-Sumner Apr 15, 2024
aeef150
Fix unused variable
Jarred-Sumner Apr 15, 2024
3dc7a2b
Fix merge conflict
Jarred-Sumner Apr 15, 2024
40efcb7
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 15, 2024
701d3a0
Increase limit
Jarred-Sumner Apr 15, 2024
47c50bd
double the limit
Jarred-Sumner Apr 15, 2024
cae2ed4
CI
Jarred-Sumner Apr 15, 2024
9cfb2a3
Update CMakeLists.txt
Jarred-Sumner Apr 15, 2024
23544d9
Update CMakeLists.txt
Jarred-Sumner Apr 15, 2024
cddf177
Merge branch 'main' into jarred/upgrade-llvm
Jarred-Sumner Apr 15, 2024
ff1a16a
Merge remote-tracking branch 'origin' into jarred/upgrade-llvm
Jarred-Sumner Apr 21, 2024
4685371
Upgrade
Jarred-Sumner Apr 21, 2024
9a1d6d5
Upgrade more things
Jarred-Sumner Apr 21, 2024
cbabb62
Bump
Jarred-Sumner Apr 21, 2024
38101d5
Remove ld64 flag
Jarred-Sumner Apr 21, 2024
0ad7021
typo
Jarred-Sumner Apr 21, 2024
390cf52
Update Dockerfile
Jarred-Sumner Apr 21, 2024
89ebef7
update
Jarred-Sumner Apr 21, 2024
fd320f4
Update
Jarred-Sumner Apr 21, 2024
ef94bfb
Up
Jarred-Sumner Apr 21, 2024
24ab7cb
asd
Jarred-Sumner Apr 21, 2024
9cb2b8f
up
Jarred-Sumner Apr 21, 2024
488a3b5
Upgrade
Jarred-Sumner Apr 21, 2024
2652c8f
Bump!
Jarred-Sumner Apr 21, 2024
9591b8b
Fix crash
Jarred-Sumner Apr 22, 2024
d199112
Remove unnecessary cahnge
Jarred-Sumner Apr 22, 2024
d677480
Propagate canary flag + bump macOS 13
Jarred-Sumner Apr 22, 2024
7bf2347
Upgrades
Jarred-Sumner Apr 22, 2024
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ endif()
# we do some extra work afterwards to double-check, and we will rerun BUN_FIND_LLVM if the compiler did not match.
#
# If the user passes -DLLVM_PREFIX, most of this logic is skipped, but we still warn if invalid.
set(LLVM_VERSION 16)
set(LLVM_VERSION 17)

macro(BUN_FIND_LLVM)
find_program(
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ARG ZIG_OPTIMIZE=ReleaseFast
ARG CMAKE_BUILD_TYPE=Release

ARG NODE_VERSION="20"
ARG LLVM_VERSION="16"
ARG LLVM_VERSION="17"
ARG ZIG_VERSION="0.12.0-dev.1828+225fe6ddb"

ARG SCCACHE_BUCKET
Expand All @@ -51,10 +51,10 @@ ENV CPU_TARGET=${CPU_TARGET}
ENV BUILDARCH=${BUILDARCH}
ENV BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR}

ENV CXX=clang++-16
ENV CC=clang-16
ENV AR=/usr/bin/llvm-ar-16
ENV LD=lld-16
ENV CXX=clang++-${LLVM_VERSION}
ENV CC=clang-${LLVM_VERSION}
ENV AR=/usr/bin/llvm-ar-${LLVM_VERSION}
ENV LD=lld-${LLVM_VERSION}

ENV SCCACHE_BUCKET=${SCCACHE_BUCKET}
ENV SCCACHE_REGION=${SCCACHE_REGION}
Expand Down
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ ZIG ?= $(shell which zig 2>/dev/null || echo -e "error: Missing zig. Please make
# This is easier to happen than you'd expect.
# Using realpath here causes issues because clang uses clang++ as a symlink
# so if that's resolved, it won't build for C++
REAL_CC = $(shell which clang-16 2>/dev/null || which clang 2>/dev/null)
REAL_CXX = $(shell which clang++-16 2>/dev/null || which clang++ 2>/dev/null)
REAL_CC = $(shell which clang-17 2>/dev/null || which clang 2>/dev/null)
REAL_CXX = $(shell which clang++-17 2>/dev/null || which clang++ 2>/dev/null)
CLANG_FORMAT = $(shell which clang-format-16 2>/dev/null || which clang-format 2>/dev/null)

CC = $(REAL_CC)
Expand All @@ -107,14 +107,14 @@ CC_WITH_CCACHE = $(CCACHE_PATH) $(CC)
ifeq ($(OS_NAME),darwin)
# Find LLVM
ifeq ($(wildcard $(LLVM_PREFIX)),)
LLVM_PREFIX = $(shell brew --prefix llvm@16)
LLVM_PREFIX = $(shell brew --prefix llvm@17)
endif
ifeq ($(wildcard $(LLVM_PREFIX)),)
LLVM_PREFIX = $(shell brew --prefix llvm)
endif
ifeq ($(wildcard $(LLVM_PREFIX)),)
# This is kinda ugly, but I can't find a better way to error :(
LLVM_PREFIX = $(shell echo -e "error: Unable to find llvm. Please run 'brew install llvm@16' or set LLVM_PREFIX=/path/to/llvm")
LLVM_PREFIX = $(shell echo -e "error: Unable to find llvm. Please run 'brew install llvm@17' or set LLVM_PREFIX=/path/to/llvm")
endif

LDFLAGS += -L$(LLVM_PREFIX)/lib
Expand Down Expand Up @@ -154,7 +154,7 @@ CMAKE_FLAGS_WITHOUT_RELEASE = -DCMAKE_C_COMPILER=$(CC) \
-DCMAKE_OSX_DEPLOYMENT_TARGET=$(MIN_MACOS_VERSION) \
$(CMAKE_CXX_COMPILER_LAUNCHER_FLAG) \
-DCMAKE_AR=$(AR) \
-DCMAKE_RANLIB=$(which llvm-16-ranlib 2>/dev/null || which llvm-ranlib 2>/dev/null)
-DCMAKE_RANLIB=$(which llvm-17-ranlib 2>/dev/null || which llvm-ranlib 2>/dev/null)



Expand Down Expand Up @@ -657,7 +657,7 @@ endif
.PHONY: assert-deps
assert-deps:
@echo "Checking if the required utilities are available..."
@if [ $(CLANG_VERSION) -lt "15" ]; then echo -e "ERROR: clang version >=15 required, found: $(CLANG_VERSION). Install with:\n\n $(POSIX_PKG_MANAGER) install llvm@16"; exit 1; fi
@if [ $(CLANG_VERSION) -lt "15" ]; then echo -e "ERROR: clang version >=15 required, found: $(CLANG_VERSION). Install with:\n\n $(POSIX_PKG_MANAGER) install llvm@17"; exit 1; fi
@cmake --version >/dev/null 2>&1 || (echo -e "ERROR: cmake is required."; exit 1)
@$(PYTHON) --version >/dev/null 2>&1 || (echo -e "ERROR: python is required."; exit 1)
@$(ESBUILD) --version >/dev/null 2>&1 || (echo -e "ERROR: esbuild is required."; exit 1)
Expand Down Expand Up @@ -1266,7 +1266,8 @@ jsc-build-linux-compile-config:
cmake \
-DPORT="JSCOnly" \
-DENABLE_STATIC_JSC=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_TYPE=Debug \
-DENABLE_BUN_SKIP_FAILING_ASSERTIONS=ON \
-DUSE_THIN_ARCHIVES=OFF \
-DUSE_BUN_JSC_ADDITIONS=ON \
-DENABLE_FTL_JIT=ON \
Expand Down
2 changes: 1 addition & 1 deletion docs/project/building-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The Zig compiler is automatically downloaded, installed, and updated by the buil
> irm https://get.scoop.sh | iex
> scoop install nodejs-lts go rust nasm ruby perl
# scoop seems to be buggy if you install llvm and the rest at the same time
> scoop llvm@16.0.4
> scoop llvm@17.0.6
```

If you intend on building WebKit locally (optional), you should install these packages:
Expand Down
8 changes: 4 additions & 4 deletions docs/project/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Bun requires LLVM 16 and Clang 16 (`clang` is part of LLVM). This version requir
{% codetabs %}

```bash#macOS (Homebrew)
$ brew install llvm@16
$ brew install llvm@17
```

```bash#Ubuntu/Debian
Expand Down Expand Up @@ -87,7 +87,7 @@ If none of the above solutions apply, you will have to install it [manually](htt
Make sure LLVM 16 is in your path:

```bash
$ which clang-16
$ which clang-17
```

If not, run this to manually link it:
Expand All @@ -96,7 +96,7 @@ If not, run this to manually link it:

```bash#macOS (Homebrew)
# use fish_add_path if you're using fish
$ export PATH="$(brew --prefix llvm@16)/bin:$PATH"
$ export PATH="$(brew --prefix llvm@17)/bin:$PATH"
```

```bash#Arch
Expand Down Expand Up @@ -262,7 +262,7 @@ The issue may manifest when initially running `bun setup` as Clang being unable
```
The C++ compiler

"/usr/bin/clang++-16"
"/usr/bin/clang++-17"

is not able to compile a simple test program.
```
Expand Down
4 changes: 2 additions & 2 deletions scripts/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps/}
export BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}

# this compiler detection could be better
export CC=${CC:-$(which clang-16 || which clang || which cc)}
export CXX=${CXX:-$(which clang++-16 || which clang++ || which c++)}
export CC=${CC:-$(which clang-17 || which clang || which cc)}
export CXX=${CXX:-$(which clang++-17 || which clang++ || which c++)}
export AR=${AR:-$(which llvm-ar || which ar)}
export CPUS=${CPUS:-$(nproc || sysctl -n hw.ncpu || echo 1)}

Expand Down
7 changes: 4 additions & 3 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ fail() {
printf "${C_RED}setup error${C_RESET}: %s\n" "$@"
}

LLVM_VERSION=16
LLVM_VERSION=17

# this compiler detection could be better
# it is copy pasted from ./env.sh
CC=${CC:-$(which clang-16 || which clang || which cc)}
CXX=${CXX:-$(which clang++-16 || which clang++ || which c++)}
CC=${CC:-$(which clang-17 || which clang || which cc)}
CXX=${CXX:-$(which clang++-17 || which clang++ || which c++)}

test -n "$CC" || fail "missing LLVM $LLVM_VERSION (could not find clang)"
test -n "$CXX" || fail "missing LLVM $LLVM_VERSION (could not find clang++)"
Expand Down Expand Up @@ -78,6 +78,7 @@ rm -f build/CMakeCache.txt
cmake -B build -S . \
-G Ninja \
-DUSE_DEBUG_JSC=ON \
-DWEBKIT_DIR="$(pwd)/src/bun.js/WebKit/WebKitBuild/Debug" \
Jarred-Sumner marked this conversation as resolved.
Show resolved Hide resolved
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER="$CC" \
-DCMAKE_CXX_COMPILER="$CXX" \
Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/ConsoleObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ const TablePrinter = struct {
var cols_iter = JSC.JSPropertyIterator(.{
.skip_empty_name = false,
.include_value = true,
}).init(this.globalObject, row_value.asObjectRef());
}).init(this.globalObject, row_value);
defer cols_iter.deinit();

while (cols_iter.next()) |col_key| {
Expand Down Expand Up @@ -524,7 +524,7 @@ const TablePrinter = struct {
var rows_iter = JSC.JSPropertyIterator(.{
.skip_empty_name = false,
.include_value = true,
}).init(globalObject, this.tabular_data.asObjectRef());
}).init(globalObject, this.tabular_data);
defer rows_iter.deinit();

while (rows_iter.next()) |row_key| {
Expand Down Expand Up @@ -597,7 +597,7 @@ const TablePrinter = struct {
var rows_iter = JSC.JSPropertyIterator(.{
.skip_empty_name = false,
.include_value = true,
}).init(globalObject, this.tabular_data.asObjectRef());
}).init(globalObject, this.tabular_data);
defer rows_iter.deinit();

while (rows_iter.next()) |row_key| {
Expand Down Expand Up @@ -2724,7 +2724,7 @@ pub const Formatter = struct {
.skip_empty_name = true,

.include_value = true,
}).init(this.globalThis, props.asObjectRef());
}).init(this.globalThis, props);
defer props_iter.deinit();

const children_prop = props.get(this.globalThis, "children");
Expand Down
6 changes: 3 additions & 3 deletions src/bun.js/api/JSBundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ pub const JSBundler = struct {
var define_iter = JSC.JSPropertyIterator(.{
.skip_empty_name = true,
.include_value = true,
}).init(globalThis, define.asObjectRef());
}).init(globalThis, define);
defer define_iter.deinit();

while (define_iter.next()) |prop| {
Expand Down Expand Up @@ -423,7 +423,7 @@ pub const JSBundler = struct {
var loader_iter = JSC.JSPropertyIterator(.{
.skip_empty_name = true,
.include_value = true,
}).init(globalThis, loaders.asObjectRef());
}).init(globalThis, loaders);
defer loader_iter.deinit();

var loader_names = try allocator.alloc(string, loader_iter.len);
Expand All @@ -432,7 +432,7 @@ pub const JSBundler = struct {
errdefer allocator.free(loader_values);

while (loader_iter.next()) |prop| {
if (!prop.hasPrefixChar('.') or prop.len < 2) {
if (!prop.hasPrefixComptime(".") or prop.length() < 2) {
globalThis.throwInvalidArguments("loader property names must be file extensions, such as '.txt'", .{});
return error.JSException;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/api/JSTranspiler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
.skip_empty_name = true,

.include_value = true,
}).init(globalThis, define.asObjectRef());
}).init(globalThis, define);
defer define_iter.deinit();

// cannot be a temporary because it may be loaded on different threads.
Expand Down Expand Up @@ -657,7 +657,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
var iter = JSC.JSPropertyIterator(.{
.skip_empty_name = true,
.include_value = true,
}).init(globalThis, replace.asObjectRef());
}).init(globalThis, replace);

if (iter.len > 0) {
errdefer iter.deinit();
Expand Down
7 changes: 2 additions & 5 deletions src/bun.js/api/bun/h2_frame_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1981,11 +1981,10 @@ pub const H2FrameParser = struct {

var encoded_size: usize = 0;

const headers_obj = headers_arg.asObjectRef();
var iter = JSC.JSPropertyIterator(.{
.skip_empty_name = false,
.include_value = true,
}).init(globalObject, headers_obj);
}).init(globalObject, headers_arg);
defer iter.deinit();

// TODO: support CONTINUE for more headers if headers are too big
Expand Down Expand Up @@ -2182,13 +2181,11 @@ pub const H2FrameParser = struct {
return JSC.JSValue.jsNumber(-1);
}

const headers_obj = headers_arg.asObjectRef();

// we iterate twice, because pseudo headers must be sent first, but can appear anywhere in the headers object
var iter = JSC.JSPropertyIterator(.{
.skip_empty_name = false,
.include_value = true,
}).init(globalObject, headers_obj);
}).init(globalObject, headers_arg);
defer iter.deinit();
for (0..2) |ignore_pseudo_headers| {
iter.reset();
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/bun/subprocess.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ pub const Subprocess = struct {
var object_iter = JSC.JSPropertyIterator(.{
.skip_empty_name = false,
.include_value = true,
}).init(globalThis, object.asObjectRef());
}).init(globalThis, object);
defer object_iter.deinit();
env_array.ensureTotalCapacityPrecise(allocator, object_iter.len +
// +1 incase there's IPC
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/ffi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ pub const FFI = struct {
.skip_empty_name = true,

.include_value = true,
}).init(global, object.asObjectRef());
}).init(global, object);
defer symbols_iter.deinit();

try symbols.ensureTotalCapacity(allocator, symbols_iter.len);
Expand Down
33 changes: 26 additions & 7 deletions src/bun.js/bindings/BunString.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

#include "root.h"
#include "headers-handwritten.h"
#include <JavaScriptCore/JSCJSValueInlines.h>

#include "JavaScriptCore/JSCJSValue.h"
#include "JavaScriptCore/PutPropertySlot.h"

#include "simdutf.h"
#include "JSDOMURL.h"
#include "DOMURL.h"
Expand Down Expand Up @@ -36,7 +41,7 @@ extern "C" BunString BunString__fromBytes(const char* bytes, size_t length);

extern "C" bool Bun__WTFStringImpl__hasPrefix(const WTF::StringImpl* impl, const char* bytes, size_t length)
{
return impl->startsWith(bytes, length);
return impl->startsWith({ bytes, length });
}

extern "C" void Bun__WTFStringImpl__deref(WTF::StringImpl* impl)
Expand All @@ -58,15 +63,15 @@ extern "C" bool BunString__fromJS(JSC::JSGlobalObject* globalObject, JSC::Encode
extern "C" BunString BunString__createAtom(const char* bytes, size_t length)
{
ASSERT(simdutf::validate_ascii(bytes, length));
auto atom = tryMakeAtomString(String(StringImpl::createWithoutCopying(bytes, length)));
auto atom = tryMakeAtomString(String(StringImpl::createWithoutCopying({ bytes, length })));
atom.impl()->ref();
return { BunStringTag::WTFStringImpl, { .wtf = atom.impl() } };
}

extern "C" BunString BunString__tryCreateAtom(const char* bytes, size_t length)
{
if (simdutf::validate_ascii(bytes, length)) {
auto atom = tryMakeAtomString(String(StringImpl::createWithoutCopying(bytes, length)));
auto atom = tryMakeAtomString(String(StringImpl::createWithoutCopying({ bytes, length })));
if (atom.isNull())
return { BunStringTag::Dead, {} };
atom.impl()->ref();
Expand Down Expand Up @@ -271,9 +276,9 @@ extern "C" BunString BunString__fromBytes(const char* bytes, size_t length)

extern "C" BunString BunString__createExternal(const char* bytes, size_t length, bool isLatin1, void* ctx, void (*callback)(void* arg0, void* arg1, size_t arg2))
{
Ref<WTF::ExternalStringImpl> impl = isLatin1 ? WTF::ExternalStringImpl::create(reinterpret_cast<const LChar*>(bytes), length, ctx, callback) :
Ref<WTF::ExternalStringImpl> impl = isLatin1 ? WTF::ExternalStringImpl::create({ reinterpret_cast<const LChar*>(bytes), length }, ctx, callback) :

WTF::ExternalStringImpl::create(reinterpret_cast<const UChar*>(bytes), length, ctx, callback);
WTF::ExternalStringImpl::create({ reinterpret_cast<const UChar*>(bytes), length }, ctx, callback);

return { BunStringTag::WTFStringImpl, { .wtf = &impl.leakRef() } };
}
Expand Down Expand Up @@ -532,7 +537,7 @@ extern "C" BunString BunString__createExternalGloballyAllocatedLatin1(
size_t length)
{
ASSERT(length > 0);
Ref<WTF::ExternalStringImpl> impl = WTF::ExternalStringImpl::create(bytes, length, nullptr, [](void*, void* ptr, size_t) {
Ref<WTF::ExternalStringImpl> impl = WTF::ExternalStringImpl::create({ bytes, length }, nullptr, [](void*, void* ptr, size_t) {
mi_free(ptr);
});
return { BunStringTag::WTFStringImpl, { .wtf = &impl.leakRef() } };
Expand All @@ -543,7 +548,7 @@ extern "C" BunString BunString__createExternalGloballyAllocatedUTF16(
size_t length)
{
ASSERT(length > 0);
Ref<WTF::ExternalStringImpl> impl = WTF::ExternalStringImpl::create(bytes, length, nullptr, [](void*, void* ptr, size_t) {
Ref<WTF::ExternalStringImpl> impl = WTF::ExternalStringImpl::create({ bytes, length }, nullptr, [](void*, void* ptr, size_t) {
mi_free(ptr);
});
return { BunStringTag::WTFStringImpl, { .wtf = &impl.leakRef() } };
Expand All @@ -565,4 +570,18 @@ extern "C" bool WTFStringImpl__isThreadSafe(
extern "C" void Bun__WTFStringImpl__ensureHash(WTF::StringImpl* str)
{
str->hash();
}

extern "C" void JSC__JSValue__putBunString(
JSC::EncodedJSValue encodedTarget,
JSC::JSGlobalObject* global,
const BunString* key,
JSC::EncodedJSValue encodedValue)
{
JSC::JSObject* target = JSC::JSValue::decode(encodedTarget).getObject();
JSC::JSValue value = JSC::JSValue::decode(encodedValue);
auto& vm = global->vm();
WTF::String str = key->toWTFString();
Identifier id = Identifier::fromString(vm, str);
target->putDirect(vm, id, value, 0);
}
Loading
Loading