Skip to content

Commit 44cb35f

Browse files
authored
Use V8's Starlark transition API instead of patching pointer compression default (#486)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent cb87620 commit 44cb35f

4 files changed

Lines changed: 71 additions & 36 deletions

File tree

BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ cc_library(
134134
],
135135
deps = [
136136
":wasm_vm_headers",
137-
"@v8//:wee8",
137+
"//bazel:wee8_no_pointer_compression",
138138
],
139139
)
140140

bazel/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
load("@bazel_skylib//lib:selects.bzl", "selects")
16+
load(":v8_transition.bzl", "v8_lib_no_pointer_compression")
1617

1718
package(default_visibility = ["//visibility:public"])
1819

@@ -69,4 +70,11 @@ selects.config_setting_group(
6970
],
7071
)
7172

73+
# V8 library with pointer compression disabled using V8's Starlark transition.
74+
# This avoids the need to patch V8's default pointer compression setting.
75+
v8_lib_no_pointer_compression(
76+
name = "wee8_no_pointer_compression",
77+
library = "@v8//:wee8",
78+
)
79+
7280
exports_files(["tsan_suppressions.txt"])

bazel/external/v8.patch

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,7 @@
1-
From 3b6a69271801db1b1a411fb969b515c74c459f65 Mon Sep 17 00:00:00 2001
2-
From: Matt Leon <mattleon@google.com>
3-
Date: Wed, 16 Jul 2025 16:55:02 -0400
4-
Subject: [PATCH 1/7] Disable pointer compression
5-
6-
Pointer compression limits the maximum number of WasmVMs.
7-
8-
Signed-off-by: Matt Leon <mattleon@google.com>
9-
---
10-
BUILD.bazel | 2 +-
11-
1 file changed, 1 insertion(+), 1 deletion(-)
12-
13-
diff --git a/BUILD.bazel b/BUILD.bazel
14-
index b1a54b2b42c..96c8be8901f 100644
15-
--- a/BUILD.bazel
16-
+++ b/BUILD.bazel
17-
@@ -296,7 +296,7 @@ v8_int(
18-
# If no explicit value for v8_enable_pointer_compression, we set it to 'none'.
19-
v8_string(
20-
name = "v8_enable_pointer_compression",
21-
- default = "none",
22-
+ default = "False",
23-
)
24-
25-
# Default setting for v8_enable_pointer_compression.
26-
--
27-
2.52.0.457.g6b5491de43-goog
28-
29-
301
From aea5afcb03b19af37ed1c04cfdf294e9f4499f6b Mon Sep 17 00:00:00 2001
312
From: Matt Leon <mattleon@google.com>
323
Date: Wed, 16 Jul 2025 16:56:31 -0400
33-
Subject: [PATCH 2/7] Restore _allowlist_function_transition
4+
Subject: [PATCH 1/6] Restore _allowlist_function_transition
345

356
Reverts v8 commit b26554ec368e9553782012c96aa5e99b163eaff2, which removed use of
367
_allowlist_function_transition from v8 bazel/defs.bzl, since it is still required
@@ -85,7 +56,7 @@ index 8c929454840..57336154cf7 100644
8556
From 920ef0496317a512083a09caa905fbf87a01c14b Mon Sep 17 00:00:00 2001
8657
From: Matt Leon <mattleon@google.com>
8758
Date: Wed, 16 Jul 2025 16:56:52 -0400
88-
Subject: [PATCH 3/7] Don't expose Wasm C API (only Wasm C++ API).
59+
Subject: [PATCH 2/6] Don't expose Wasm C API (only Wasm C++ API).
8960

9061
Signed-off-by: Matt Leon <mattleon@google.com>
9162
---
@@ -118,7 +89,7 @@ index e7cf656ade4..660ed06021d 100644
11889
From f6379d9391b775f0459c3740302e435421a942c1 Mon Sep 17 00:00:00 2001
11990
From: Matt Leon <mattleon@google.com>
12091
Date: Wed, 16 Jul 2025 16:58:02 -0400
121-
Subject: [PATCH 4/7] Stub out fast_float for bazel-supplied version
92+
Subject: [PATCH 3/6] Stub out fast_float for bazel-supplied version
12293

12394
Signed-off-by: Matt Leon <mattleon@google.com>
12495
---
@@ -145,7 +116,7 @@ index 96c8be8901f..05630ab7035 100644
145116
From 98a46e051afa5186a07400c53923367b9bea0ebe Mon Sep 17 00:00:00 2001
146117
From: Matt Leon <mattleon@google.com>
147118
Date: Wed, 16 Jul 2025 20:04:05 -0400
148-
Subject: [PATCH 5/7] Stub out vendored dependencies for bazel-sourced versions
119+
Subject: [PATCH 4/6] Stub out vendored dependencies for bazel-sourced versions
149120

150121
Signed-off-by: Matt Leon <mattleon@google.com>
151122
---
@@ -177,7 +148,7 @@ index 05630ab7035..7f14a987148 100644
177148
From e3cebe8ca694935302a8c3806ab6398c593f31cd Mon Sep 17 00:00:00 2001
178149
From: Matt Leon <mattleon@google.com>
179150
Date: Wed, 16 Jul 2025 20:29:10 -0400
180-
Subject: [PATCH 6/7] Add build flags to make V8 compile with GCC
151+
Subject: [PATCH 5/6] Add build flags to make V8 compile with GCC
181152

182153
Signed-off-by: Matt Leon <mattleon@google.com>
183154
---
@@ -205,7 +176,7 @@ index ba8315bb938..277a07ef63d 100644
205176
From 5f9cd8cf1b1758678d41f96cd22477e052c787f8 Mon Sep 17 00:00:00 2001
206177
From: Matt Leon <mattleon@google.com>
207178
Date: Fri, 18 Jul 2025 17:28:42 -0400
208-
Subject: [PATCH 7/7] Hack out atomic simd support in V8.
179+
Subject: [PATCH 6/6] Hack out atomic simd support in V8.
209180

210181
Atomic simdutf requires __cpp_lib_atomic_ref >= 201806, which is only
211182
supported in clang libc++ 19+. The version of LLVM used in Envoy as of

bazel/v8_transition.bzl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Wrapper rule to apply V8's pointer compression transition to cc_library targets.
16+
17+
V8 provides v8_disable_pointer_compression transition and v8_binary_non_pointer_compression
18+
for cc_binary targets. This file provides the equivalent for cc_library targets by wrapping
19+
the same transition that V8 uses.
20+
"""
21+
22+
load("@v8//:bazel/v8-non-pointer-compression.bzl", "v8_disable_pointer_compression")
23+
24+
def _v8_lib_no_pointer_compression_impl(ctx):
25+
"""Forward providers from the library built with pointer compression disabled.
26+
27+
This is analogous to V8's _v8_binary_non_pointer_compression implementation,
28+
but for cc_library instead of cc_binary.
29+
"""
30+
31+
# The transition may create a list of configured targets, take the first one
32+
library = ctx.attr.library[0] if type(ctx.attr.library) == type([]) else ctx.attr.library
33+
return [library[CcInfo], library[DefaultInfo]]
34+
35+
v8_lib_no_pointer_compression = rule(
36+
implementation = _v8_lib_no_pointer_compression_impl,
37+
attrs = {
38+
"library": attr.label(
39+
cfg = v8_disable_pointer_compression,
40+
providers = [CcInfo],
41+
doc = "The V8 library to build with pointer compression disabled",
42+
),
43+
"_allowlist_function_transition": attr.label(
44+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
45+
),
46+
},
47+
provides = [CcInfo, DefaultInfo],
48+
doc = """Wraps a cc_library target with V8's pointer compression disabled.
49+
50+
This rule uses V8's v8_disable_pointer_compression transition (the same one used
51+
by v8_binary_non_pointer_compression) to ensure v8_enable_pointer_compression
52+
is set to False for the library and all its dependencies.
53+
54+
This is the library equivalent of V8's v8_binary_non_pointer_compression rule.
55+
""",
56+
)

0 commit comments

Comments
 (0)