Skip to content

Commit 4168d22

Browse files
bartlomiejuclaude
andauthored
feat: expose simdutf bindings behind cargo feature (#1928)
V8 bundles simdutf (SIMD-accelerated Unicode validation/transcoding), but consumers like deno_core can't use a separate simdutf Rust crate alongside rusty_v8 due to C++ symbol clashes. This exposes the bundled simdutf API through rusty_v8 behind a `simdutf` cargo feature flag. Changes: - Cargo.toml: add `simdutf` feature - BUILD.gn: conditionally link simdutf dep and define RUSTY_V8_ENABLE_SIMDUTF - build.rs: wire cargo feature to GN arg, add to prebuilt suffix - binding.cc: add ~250 lines of extern "C" wrappers for simdutf functions (validation, conversion, length calculation, base64), gated by preprocessor - simdutf.rs: safe Rust API wrapping all exposed simdutf operations - lib.rs: register simdutf module behind cfg(feature) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2739918 commit 4168d22

8 files changed

Lines changed: 1459 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions: write-all
1212

1313
jobs:
1414
build:
15-
name: ${{ matrix.config.variant }} ${{ matrix.config.target }} ${{ matrix.config.v8_enable_pointer_compression && 'ptrcomp' || '' }}
15+
name: ${{ matrix.config.variant }} ${{ matrix.config.target }} ${{ matrix.config.v8_enable_pointer_compression && 'ptrcomp' || '' }} ${{ matrix.config.simdutf && 'simdutf' || '' }}
1616
runs-on: ${{ matrix.config.os }}
1717
timeout-minutes: 180
1818
strategy:
@@ -117,13 +117,70 @@ jobs:
117117
v8_enable_pointer_compression: false
118118
cargo: cargo
119119

120+
# simdutf builds
121+
- os: macos-15-large
122+
target: x86_64-apple-darwin
123+
variant: debug
124+
v8_enable_pointer_compression: false
125+
simdutf: true
126+
cargo: cargo
127+
128+
- os: macos-15-large
129+
target: x86_64-apple-darwin
130+
variant: release
131+
v8_enable_pointer_compression: false
132+
simdutf: true
133+
cargo: cargo
134+
135+
- os: macos-15
136+
target: aarch64-apple-darwin
137+
variant: debug
138+
v8_enable_pointer_compression: false
139+
simdutf: true
140+
cargo: cargo
141+
142+
- os: macos-15
143+
target: aarch64-apple-darwin
144+
variant: release
145+
v8_enable_pointer_compression: false
146+
simdutf: true
147+
cargo: cargo
148+
149+
- os: ${{ github.repository == 'denoland/rusty_v8' && 'ubuntu-22.04-xl' || 'ubuntu-22.04' }}
150+
target: x86_64-unknown-linux-gnu
151+
variant: debug
152+
v8_enable_pointer_compression: false
153+
simdutf: true
154+
cargo: cargo
155+
156+
- os: ${{ github.repository == 'denoland/rusty_v8' && 'ubuntu-22.04-xl' || 'ubuntu-22.04' }}
157+
target: x86_64-unknown-linux-gnu
158+
variant: release
159+
v8_enable_pointer_compression: false
160+
simdutf: true
161+
cargo: cargo
162+
163+
- os: ${{ github.repository == 'denoland/rusty_v8' && 'ubuntu-22.04-xl' || 'ubuntu-22.04' }}
164+
target: aarch64-unknown-linux-gnu
165+
variant: debug
166+
v8_enable_pointer_compression: false
167+
simdutf: true
168+
cargo: cargo
169+
170+
- os: ${{ github.repository == 'denoland/rusty_v8' && 'ubuntu-22.04-xl' || 'ubuntu-22.04' }}
171+
target: aarch64-unknown-linux-gnu
172+
variant: release
173+
v8_enable_pointer_compression: false
174+
simdutf: true
175+
cargo: cargo
176+
120177
env:
121178
V8_FROM_SOURCE: true
122179
CARGO_VARIANT_FLAG: ${{ matrix.config.variant == 'release' && '--release' || '' }}
123-
CARGO_FEATURE_FLAGS: ${{ matrix.config.v8_enable_pointer_compression && '--features v8_enable_pointer_compression' || '' }}
180+
CARGO_FEATURE_FLAGS: ${{ format('{0} {1}', matrix.config.v8_enable_pointer_compression && '--features v8_enable_pointer_compression' || '', matrix.config.simdutf && '--features simdutf' || '') }}
124181
LIB_NAME: ${{ contains(matrix.config.target, 'windows') && 'rusty_v8' || 'librusty_v8' }}
125182
LIB_EXT: ${{ contains(matrix.config.target, 'windows') && 'lib' || 'a' }}
126-
FEATURES_SUFFIX: ${{ matrix.config.v8_enable_pointer_compression && '_ptrcomp' || '' }}
183+
FEATURES_SUFFIX: ${{ format('{0}{1}', matrix.config.v8_enable_pointer_compression && '_ptrcomp' || '', matrix.config.simdutf && '_simdutf' || '') }}
127184
RUSTFLAGS: -D warnings
128185

129186
steps:
@@ -187,7 +244,7 @@ jobs:
187244
target/*/.*
188245
target/*/build
189246
target/*/deps
190-
key: cargo1-${{ matrix.config.target }}-${{ matrix.config.variant }}-${{ matrix.config.v8_enable_pointer_compression }}-${{ hashFiles('Cargo.lock', 'build.rs', 'git_submodule_status.txt') }}
247+
key: cargo1-${{ matrix.config.target }}-${{ matrix.config.variant }}-${{ matrix.config.v8_enable_pointer_compression }}-${{ matrix.config.simdutf }}-${{ hashFiles('Cargo.lock', 'build.rs', 'git_submodule_status.txt') }}
191248
restore-keys: cargo1-${{ matrix.config.target }}-${{ matrix.config.variant }}-${{ matrix.config.v8_enable_pointer_compression }}-
192249

193250
- name: Install and start sccache

BUILD.gn

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
22
import("//build/config/host_byteorder.gni")
33

4+
declare_args() {
5+
rusty_v8_enable_simdutf = false
6+
}
7+
48
static_library("rusty_v8") {
59
complete_static_lib = true
610
sources = [
@@ -15,6 +19,9 @@ static_library("rusty_v8") {
1519
"//v8/third_party/inspector_protocol:crdtp",
1620
"//src/deno_inspector:deno_inspector_protocol",
1721
]
22+
if (rusty_v8_enable_simdutf) {
23+
deps += [ "//third_party/simdutf:simdutf" ]
24+
}
1825
configs -= [
1926
"//build/config/compiler:default_init_stack_vars",
2027
"//build/config/compiler:thin_archive",
@@ -40,14 +47,20 @@ config("rusty_v8_config") {
4047
include_dirs = [
4148
".",
4249
"v8",
50+
".",
4351
"$target_gen_dir",
4452
"$target_gen_dir/v8",
4553
"$target_gen_dir/src/inspector",
4654
"$target_gen_dir/src/deno_inspector",
4755
]
4856

57+
defines = []
4958
if (is_debug) {
50-
defines = [ "DEBUG" ]
59+
defines += [ "DEBUG" ]
60+
}
61+
62+
if (rusty_v8_enable_simdutf) {
63+
defines += [ "RUSTY_V8_ENABLE_SIMDUTF" ]
5164
}
5265

5366
if (is_clang) {

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ opt-level = 1
102102
[features]
103103
default = ["use_custom_libcxx"]
104104
use_custom_libcxx = []
105+
simdutf = []
105106
v8_enable_pointer_compression = []
106107
v8_enable_sandbox = ["v8_enable_pointer_compression"]
107108
v8_enable_v8_checks = []

build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ fn build_v8(is_asan: bool) {
311311
env::var("CARGO_FEATURE_V8_ENABLE_V8_CHECKS").is_ok()
312312
));
313313

314+
gn_args.push(format!(
315+
"rusty_v8_enable_simdutf={}",
316+
env::var("CARGO_FEATURE_SIMDUTF").is_ok()
317+
));
318+
314319
// Fix GN's host_cpu detection when using x86_64 bins on Apple Silicon
315320
if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") {
316321
gn_args.push("host_cpu=\"arm64\"".to_string());
@@ -538,6 +543,9 @@ fn prebuilt_features_suffix() -> String {
538543
if env::var("CARGO_FEATURE_V8_ENABLE_SANDBOX").is_ok() {
539544
features.push_str("_sandbox");
540545
}
546+
if env::var("CARGO_FEATURE_SIMDUTF").is_ok() {
547+
features.push_str("_simdutf");
548+
}
541549
features
542550
}
543551

0 commit comments

Comments
 (0)