Skip to content

Commit

Permalink
Merge branch 'main' into AdityaAtulTewari/http-request-cache-part1
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaAtulTewari committed Aug 7, 2024
2 parents bf88e9e + c404f95 commit e332edd
Show file tree
Hide file tree
Showing 39 changed files with 1,237 additions and 205 deletions.
11 changes: 11 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ build:v8-codegen-opt --per_file_copt=v8/src/objects@-O2
build:v8-codegen-opt --per_file_copt=v8/src/wasm@-O2
build:v8-codegen-opt --per_file_copt=v8/src/base@-O2

# Disable relaxing all jumps during LLVM codegen under -O0, which previously led to build
# performance improvements but makes code size worse. This will be the default in LLVM19.
# https://maskray.me/blog/2024-04-27-clang-o0-output-branch-displacement-and-size-increase
build:unix --copt="-mno-relax-all" --host_copt="-mno-relax-all"

# Limit transitive header includes within libc++. This improves compliance with IWYU, helps avoid
# errors with downstream projects that implicitly define this already and reduces total include size.
https://libcxx.llvm.org/DesignDocs/HeaderRemovalPolicy.html
build:unix --cxxopt=-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES
build:unix --host_cxxopt=-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES

# Need to redefine _WIN32_WINNT to build dawn on Windows
build:windows --per_file_copt='external/dawn@-Wno-macro-redefined'
build:windows --host_per_file_copt='external/dawn@-Wno-macro-redefined'
Expand Down
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ bazel_features_deps()

http_archive(
name = "capnp-cpp",
integrity = "sha256-r2LCeW0nWWzS72WLQaFpzbJ+f/F191Mze1PllHWGV6E=",
strip_prefix = "capnproto-capnproto-b343a79/c++",
integrity = "sha256-u4TajPQnM3yQIcLUghhNnEUslu0o3q0VdY3jRoPq7yM=",
strip_prefix = "capnproto-capnproto-6446b72/c++",
type = "tgz",
urls = ["https://github.com/capnproto/capnproto/tarball/b343a799317e6a4b83d2a27bf712498fd5346985"],
urls = ["https://github.com/capnproto/capnproto/tarball/6446b721a9860eebccf9d3c73b27610491359b5a"],
)

http_archive(
Expand Down
27 changes: 23 additions & 4 deletions build/wd_test.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

def wd_test(
src,
data = [],
Expand All @@ -11,23 +13,40 @@ def wd_test(
specified.) The extension `.wd-test` is also permitted instead of `.capnp`, in order to
avoid confusing other build systems that may assume a `.capnp` file should be compiled. As
an extension, `.gpu-wd-test` is supported to enable special handling for GPU tests.
data: Files which the .capnp config file may embed. Typically JavaScript files.
data: Additional files which the .capnp config file may embed. All TypeScript files will be compiled,
their resulting files will be passed to the test as well. Usually TypeScript or Javascript source files.
args: Additional arguments to pass to `workerd`. Typically used to pass `--experimental`.
"""

# Add workerd binary to "data" dependencies.
data = data + [src, "//src/workerd/server:workerd"]

ts_srcs = [src for src in data if src.endswith(".ts")]

# Default name based on src.
if name == None:
name = src.removesuffix(".capnp").removesuffix(".wd-test").removesuffix(".gpu-wd-test").removesuffix(".ts-wd-test")

if len(ts_srcs) != 0:
# TODO When TypeScript 5.6 comes out use noCheck so the test fails throwing a type error.
ts_project(
name = name + "@ts_project",
srcs = ts_srcs,
tsconfig = "tsconfig.json",
allow_js = True,
source_map = True,
composite = True,
deps = ["//src/node:node.capnp@tsproject"],
)
data += [js_src.removesuffix(".ts") + ".js" for js_src in ts_srcs]

# Add initial arguments for `workerd test` command.
args = [
"$(location //src/workerd/server:workerd)",
"test",
"$(location {})".format(src),
] + args

# Default name based on src.
if name == None:
name = src.removesuffix(".capnp").removesuffix(".wd-test").removesuffix(".gpu-wd-test")

_wd_test(
name = name,
Expand Down
1 change: 1 addition & 0 deletions build/wd_ts_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def wd_ts_bundle_capnp(
declaration = True,
tsconfig = name + "@tsconfig",
deps = deps,
visibility = ["//visibility:public"],
)

data = wd_js_bundle_capnp(
Expand Down
18 changes: 18 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
default:
@just --list

# Override this value by calling `just --set clang_version 18`
clang_version := "15"

prepare:
cargo install gen-compile-commands

Expand All @@ -6,3 +12,15 @@ compile-commands:

clean:
rm -f compile_commands.json

build *args="//...":
bazel build {{args}} --action_env=CC=clang-{{clang_version}} --action_env=CXX=clang++-{{clang_version}}

build-asan *args="//...":
just build {{args}} --config=asan --sandbox_debug

test *args="//...":
bazel test {{args}} --action_env=CC=clang-{{clang_version}} --action_env=CXX=clang++-{{clang_version}} --test_env=LLVM_SYMBOLIZER=llvm-symbolizer-{{clang_version}}

test-asan *args="//...":
just test {{args}} --config=asan
3 changes: 3 additions & 0 deletions src/node/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SlowBuffer,
isAscii,
isUtf8,
transcode,
} from 'node-internal:internal_buffer';

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand All @@ -30,6 +31,7 @@ export {
SlowBuffer,
isAscii,
isUtf8,
transcode,
};

export default {
Expand All @@ -46,4 +48,5 @@ export default {
SlowBuffer,
isAscii,
isUtf8,
transcode,
};
21 changes: 16 additions & 5 deletions src/node/internal/buffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,42 @@ interface CompareOptions {

type BufferSource = ArrayBufferView | ArrayBuffer;

export type Encoding = number;

export function byteLength(value: string): number;
export function compare(a: Uint8Array, b: Uint8Array, options?: CompareOptions): number;
export function concat(list: Uint8Array[], length: number): ArrayBuffer;
export function decodeString(value: string, encoding: string): ArrayBuffer;
export function decodeString(value: string, encoding: Encoding): ArrayBuffer;
export function fillImpl(buffer: Uint8Array,
value: string | BufferSource,
start: number,
end: number,
encoding?: string): void;
encoding?: Encoding): void;
export function indexOf(buffer: Uint8Array,
value: string | Uint8Array,
byteOffset?: number,
encoding?: string,
encoding?: Encoding,
findLast?: boolean): number | undefined;
export function swap(buffer: Uint8Array, size: 16|32|64): void;
export function toString(buffer: Uint8Array,
start: number,
end: number,
encoding: string): string;
encoding: Encoding): string;
export function write(buffer: Uint8Array,
value: string,
offset: number,
length: number,
encoding: string): void;
encoding: Encoding): void;
export function decode(buffer: Uint8Array, state: Uint8Array): string;
export function flush(state: Uint8Array): string;
export function isAscii(value: ArrayBufferView): boolean;
export function isUtf8(value: ArrayBufferView): boolean;
export function transcode(source: ArrayBufferView, fromEncoding: Encoding, toEncoding: Encoding): ArrayBuffer;

export const ASCII: Encoding;
export const LATIN1: Encoding;
export const UTF8: Encoding;
export const UTF16LE: Encoding;
export const BASE64: Encoding;
export const BASE64URL: Encoding;
export const HEX: Encoding;
2 changes: 1 addition & 1 deletion src/node/internal/crypto_dh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ let DiffieHellman = function (this: DiffieHellman, sizeOrKey: number|ArrayLike,
if (typeof sizeOrKey === 'number')
validateInt32(sizeOrKey, 'sizeOrKey');

if (keyEncoding && !Buffer.isEncoding(keyEncoding) && keyEncoding !== 'buffer') {
if (keyEncoding && keyEncoding !== 'buffer' && !Buffer.isEncoding(keyEncoding)) {
genEncoding = generator as any;
generator = keyEncoding;
keyEncoding = "utf-8"; // default encoding
Expand Down
10 changes: 0 additions & 10 deletions src/node/internal/crypto_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,10 @@ import {
} from 'node-internal:internal_errors';

import {
validateEncoding,
validateString,
validateUint32,
} from 'node-internal:validators';

import {
normalizeEncoding
} from 'node-internal:internal_utils';

import {
isArrayBufferView,
isCryptoKey,
Expand Down Expand Up @@ -129,9 +124,6 @@ Hash.prototype.copy = function(this: Hash, options?: HashOptions): Hash {
Hash.prototype._transform = function(this: Hash | Hmac, chunk: string | Buffer | ArrayBufferView,
encoding: string, callback: TransformCallback): void {
if (typeof chunk === 'string') {
encoding ??= 'utf-8';
validateEncoding(chunk, encoding);
encoding = normalizeEncoding(encoding)!;
chunk = Buffer.from(chunk, encoding);
}
this[kHandle].update(chunk);
Expand All @@ -155,8 +147,6 @@ Hash.prototype.update = function(this: Hash | Hmac, data: string | Buffer | Arra
throw new ERR_CRYPTO_HASH_FINALIZED();

if (typeof data === 'string') {
validateEncoding(data, encoding!);
encoding = normalizeEncoding(encoding);
data = Buffer.from(data, encoding);
} else if (!isArrayBufferView(data)) {
throw new ERR_INVALID_ARG_TYPE(
Expand Down
Loading

0 comments on commit e332edd

Please sign in to comment.