From ebd4041fb7d111963d508bc7579760bfd6924280 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Wed, 2 Dec 2026 14:09:47 +0000 Subject: [PATCH 01/12] Shared: Use jemalloc as global allocator in Rust extractors Applies to the Rust, Ruby, QL and unified extractors on non-Windows targets. In Bazel, jemalloc is built from the BCR `jemalloc` module instead of the `tikv-jemalloc-sys` configure/make build script. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Cargo.lock | 40 ++++-- MODULE.bazel | 2 + misc/bazel/3rdparty/BUILD.bazel | 20 ++- .../BUILD.anstyle-query-1.1.5.bazel | 6 +- .../BUILD.anstyle-wincon-3.0.11.bazel | 6 +- .../3rdparty/rust_workspace_deps/BUILD.bazel | 12 ++ .../BUILD.errno-0.3.14.bazel | 6 +- .../BUILD.miow-0.6.1.bazel | 2 +- .../BUILD.nu-ansi-term-0.50.3.bazel | 12 +- .../BUILD.rustix-1.1.6.bazel | 6 +- .../BUILD.tempfile-3.27.0.bazel | 6 +- ...4ce1f1373e37dc865038e1bc8eeecf559ce8.bazel | 119 ++++++++++++++++++ .../BUILD.tikv-jemallocator-0.7.0.bazel | 119 ++++++++++++++++++ .../BUILD.winapi-util-0.1.11.bazel | 6 +- .../BUILD.windows-sys-0.60.2.bazel | 5 - .../BUILD.windows-sys-0.61.2.bazel | 9 ++ .../3rdparty/rust_workspace_deps/crates.bzl | 41 ++++++ .../tikv-jemallocator-0.7.0/BUILD.bazel | 15 +++ .../tikv-jemallocator/BUILD.bazel | 15 +++ ql/extractor/Cargo.toml | 3 + ql/extractor/src/main.rs | 4 + ruby/extractor/Cargo.toml | 3 + ruby/extractor/src/main.rs | 4 + rust/extractor/Cargo.toml | 3 + rust/extractor/src/main.rs | 4 + unified/extractor/Cargo.toml | 3 + unified/extractor/src/main.rs | 4 + 27 files changed, 436 insertions(+), 39 deletions(-) create mode 100644 misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel create mode 100644 misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemallocator-0.7.0.bazel create mode 100644 misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator-0.7.0/BUILD.bazel create mode 100644 misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator/BUILD.bazel diff --git a/Cargo.lock b/Cargo.lock index a4037e283442..5005cd2c797b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,7 +97,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -108,7 +108,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -471,6 +471,7 @@ dependencies = [ "codeql-extractor", "rayon", "regex", + "tikv-jemallocator", "tracing", "tracing-subscriber", "tree-sitter", @@ -491,6 +492,7 @@ dependencies = [ "rayon", "regex", "serde_json", + "tikv-jemallocator", "tracing", "tracing-subscriber", "tree-sitter", @@ -509,6 +511,7 @@ dependencies = [ "serde", "serde_json", "swift-syntax-rs", + "tikv-jemallocator", "tracing", "tracing-subscriber", "yeast", @@ -552,6 +555,7 @@ dependencies = [ "ra_ap_vfs", "serde", "serde_json", + "tikv-jemallocator", "toml", "tracing", "tracing-flame", @@ -925,7 +929,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -1428,7 +1432,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "536bfad37a309d62069485248eeaba1e8d9853aaf951caaeaed0585a95346f08" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -1492,7 +1496,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -2499,7 +2503,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -2819,7 +2823,7 @@ dependencies = [ "getrandom", "once_cell", "rustix", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -2883,6 +2887,26 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a2825c78386b4ae0314074867860ba9577875de945f05992c38815cbec327f0" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "249f09e49ab1609436f34c776e84231bead18d6a955f119f939bdc1d847561bd" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.3.55" @@ -3317,7 +3341,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] diff --git a/MODULE.bazel b/MODULE.bazel index c1c940ee744f..e6ab2bd53765 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -29,6 +29,7 @@ bazel_dep(name = "rules_kotlin", version = "2.4.21-codeql.1") bazel_dep(name = "gazelle", version = "0.54.0") bazel_dep(name = "rules_dotnet", version = "0.23.0-codeql.1") bazel_dep(name = "googletest", version = "1.18.0.bcr.1") +bazel_dep(name = "jemalloc", version = "5.3.1") bazel_dep(name = "rules_rust", version = "0.75.0") bazel_dep(name = "rules_swift", version = "4.3.0-codeql.1") bazel_dep(name = "swift-syntax", version = "604.0.0") @@ -178,6 +179,7 @@ use_repo( "vendor_rs__serde_yaml-0.9.34-deprecated", "vendor_rs__syn-3.0.9", "vendor_rs__tempfile-3.27.0", + "vendor_rs__tikv-jemallocator-0.7.0", "vendor_rs__toml-1.1.8-spec-1.1.0", "vendor_rs__tracing-0.1.44", "vendor_rs__tracing-flame-0.2.0", diff --git a/misc/bazel/3rdparty/BUILD.bazel b/misc/bazel/3rdparty/BUILD.bazel index 11af92613344..acdfed7bdb3e 100644 --- a/misc/bazel/3rdparty/BUILD.bazel +++ b/misc/bazel/3rdparty/BUILD.bazel @@ -1,8 +1,16 @@ -load("@rules_rust//crate_universe:defs.bzl", "crates_vendor") +load("@jemalloc//settings:config.bzl", "jemalloc") +load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor") # The targets in this file re-do the vendoring of the rust cargo dependencies. Use the update_all_rust_deps.sh script to run the targets, and do all the necessary work around vendoring. crates_vendor( name = "vendor_rust_workspace_deps", + annotations = { + "tikv-jemalloc-sys": [crate.annotation( + gen_build_script = False, + rustc_flags = ["--cfg=prefixed"], + deps = ["@codeql//misc/bazel/3rdparty:jemalloc"], + )], + }, cargo_lockfile = "//:Cargo.lock", generate_build_scripts = True, manifests = ["//:Cargo.toml"], @@ -22,3 +30,13 @@ crates_vendor( tags = ["manual"], vendor_path = "py_deps", ) + +# jemalloc built hermetically by Bazel, replacing `tikv-jemalloc-sys`'s configure/make build script. +# Configured like that build script does by default (`_rjem_` prefix, matching `--cfg=prefixed`). +jemalloc( + name = "jemalloc", + cxx = "False", + jemalloc_prefix = "_rjem_", + stats = "False", + visibility = ["//visibility:public"], +) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-query-1.1.5.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-query-1.1.5.bazel index 3856a392a925..c39b65a376ea 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-query-1.1.5.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-query-1.1.5.bazel @@ -110,13 +110,13 @@ rust_library( version = "1.1.5", deps = select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "//conditions:default": [], }), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-wincon-3.0.11.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-wincon-3.0.11.bazel index adb633f723e5..0ff8c8277eb3 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-wincon-3.0.11.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-wincon-3.0.11.bazel @@ -113,15 +113,15 @@ rust_library( ] + select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ "@vendor_rs__once_cell_polyfill-1.70.2//:once_cell_polyfill", # cfg(windows) - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ "@vendor_rs__once_cell_polyfill-1.70.2//:once_cell_polyfill", # cfg(windows) - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ "@vendor_rs__once_cell_polyfill-1.70.2//:once_cell_polyfill", # cfg(windows) - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "//conditions:default": [], }), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.bazel index 372295f1fb21..06cf9bf2e13b 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.bazel @@ -601,6 +601,18 @@ alias( tags = ["manual"], ) +alias( + name = "tikv-jemallocator-0.7.0", + actual = "@vendor_rs__tikv-jemallocator-0.7.0//:tikv_jemallocator", + tags = ["manual"], +) + +alias( + name = "tikv-jemallocator", + actual = "@vendor_rs__tikv-jemallocator-0.7.0//:tikv_jemallocator", + tags = ["manual"], +) + alias( name = "toml-1.1.8+spec-1.1.0", actual = "@vendor_rs__toml-1.1.8-spec-1.1.0//:toml", diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.errno-0.3.14.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.errno-0.3.14.bazel index b21586c026ba..d72fa46bb97e 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.errno-0.3.14.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.errno-0.3.14.bazel @@ -128,7 +128,7 @@ rust_library( "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) ], "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [ "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) @@ -161,7 +161,7 @@ rust_library( "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-unknown-freebsd": [ "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) @@ -221,7 +221,7 @@ rust_library( "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-unknown-freebsd": [ "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.miow-0.6.1.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.miow-0.6.1.bazel index 0e5f25419011..4d8ec819dc97 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.miow-0.6.1.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.miow-0.6.1.bazel @@ -109,6 +109,6 @@ rust_library( }), version = "0.6.1", deps = [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", + "@vendor_rs__windows-sys-0.61.2//:windows_sys", ], ) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.nu-ansi-term-0.50.3.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.nu-ansi-term-0.50.3.bazel index da5447757deb..50ca24bca7b9 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.nu-ansi-term-0.50.3.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.nu-ansi-term-0.50.3.bazel @@ -24,13 +24,13 @@ rust_library( ), aliases = select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": { - "@vendor_rs__windows-sys-0.60.2//:windows_sys": "windows", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys": "windows", # cfg(windows) }, "@rules_rust//rust/platform:i686-pc-windows-msvc": { - "@vendor_rs__windows-sys-0.60.2//:windows_sys": "windows", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys": "windows", # cfg(windows) }, "@rules_rust//rust/platform:x86_64-pc-windows-msvc": { - "@vendor_rs__windows-sys-0.60.2//:windows_sys": "windows", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys": "windows", # cfg(windows) }, "//conditions:default": {}, }), @@ -126,13 +126,13 @@ rust_library( version = "0.50.3", deps = select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "//conditions:default": [], }), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.rustix-1.1.6.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.rustix-1.1.6.bazel index d557e3cdef74..449a5a54d32c 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.rustix-1.1.6.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.rustix-1.1.6.bazel @@ -286,7 +286,7 @@ rust_library( ], "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(windows) - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [ "@vendor_rs__errno-0.3.14//:errno", # aarch64-unknown-fuchsia, cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))))) @@ -335,7 +335,7 @@ rust_library( ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(windows) - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-unknown-freebsd": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))))), i686-unknown-freebsd @@ -459,7 +459,7 @@ rust_library( ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(windows) - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-unknown-freebsd": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))))), x86_64-unknown-freebsd diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tempfile-3.27.0.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tempfile-3.27.0.bazel index f4989937959c..bc7c26c16c1f 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tempfile-3.27.0.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tempfile-3.27.0.bazel @@ -138,7 +138,7 @@ rust_library( ], "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # aarch64-pc-windows-msvc - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # aarch64-unknown-fuchsia @@ -182,7 +182,7 @@ rust_library( ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # i686-pc-windows-msvc - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-unknown-freebsd": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # i686-unknown-freebsd @@ -262,7 +262,7 @@ rust_library( ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # x86_64-pc-windows-msvc - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-unknown-freebsd": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # x86_64-unknown-freebsd diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel new file mode 100644 index 000000000000..5a48dd7ac239 --- /dev/null +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel @@ -0,0 +1,119 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @@//misc/bazel/3rdparty:vendor_rust_workspace_deps +############################################################################### + +load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +cargo_toml_env_vars( + name = "cargo_toml_env_vars", + src = "Cargo.toml", +) + +rust_library( + name = "tikv_jemalloc_sys", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "background_threads_runtime_support", + ], + crate_root = "src/lib.rs", + edition = "2018", + rustc_env_files = [ + ":cargo_toml_env_vars", + ], + rustc_flags = [ + "--cap-lints=allow", + "--cfg=prefixed", + ], + tags = [ + "cargo-bazel", + "crate-name=tikv-jemalloc-sys", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-macabi": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-none": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:aarch64-unknown-uefi": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:arm-unknown-linux-musleabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:loongarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:mips-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imac-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-fuchsia": [], + "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:sparc64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:sparc64-unknown-netbsd": [], + "@rules_rust//rust/platform:sparc64-unknown-openbsd": [], + "@rules_rust//rust/platform:thumbv6m-none-eabi": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv7em-none-eabihf": [], + "@rules_rust//rust/platform:thumbv7m-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabihf": [], + "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasip1": [], + "@rules_rust//rust/platform:wasm32-wasip1-threads": [], + "@rules_rust//rust/platform:wasm32-wasip2": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-apple-ios-macabi": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "@rules_rust//rust/platform:x86_64-unknown-uefi": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8", + deps = [ + "@codeql//misc/bazel/3rdparty:jemalloc", + "@vendor_rs__libc-0.2.189//:libc", + ], +) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemallocator-0.7.0.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemallocator-0.7.0.bazel new file mode 100644 index 000000000000..76bd13b125eb --- /dev/null +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemallocator-0.7.0.bazel @@ -0,0 +1,119 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @@//misc/bazel/3rdparty:vendor_rust_workspace_deps +############################################################################### + +load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +cargo_toml_env_vars( + name = "cargo_toml_env_vars", + src = "Cargo.toml", +) + +rust_library( + name = "tikv_jemallocator", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "background_threads_runtime_support", + "default", + ], + crate_root = "src/lib.rs", + edition = "2018", + rustc_env_files = [ + ":cargo_toml_env_vars", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=tikv-jemallocator", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-macabi": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-none": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:aarch64-unknown-uefi": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:arm-unknown-linux-musleabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:loongarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:mips-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imac-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-fuchsia": [], + "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:sparc64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:sparc64-unknown-netbsd": [], + "@rules_rust//rust/platform:sparc64-unknown-openbsd": [], + "@rules_rust//rust/platform:thumbv6m-none-eabi": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv7em-none-eabihf": [], + "@rules_rust//rust/platform:thumbv7m-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabihf": [], + "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasip1": [], + "@rules_rust//rust/platform:wasm32-wasip1-threads": [], + "@rules_rust//rust/platform:wasm32-wasip2": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-apple-ios-macabi": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "@rules_rust//rust/platform:x86_64-unknown-uefi": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "0.7.0", + deps = [ + "@vendor_rs__libc-0.2.189//:libc", + "@vendor_rs__tikv-jemalloc-sys-0.7.1-5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8//:tikv_jemalloc_sys", + ], +) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.winapi-util-0.1.11.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.winapi-util-0.1.11.bazel index b1c2a799a889..6dc9da37431d 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.winapi-util-0.1.11.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.winapi-util-0.1.11.bazel @@ -110,13 +110,13 @@ rust_library( version = "0.1.11", deps = select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) ], "//conditions:default": [], }), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.60.2.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.60.2.bazel index 7e3a6c212fa5..d0c8f9764fd0 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.60.2.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.60.2.bazel @@ -37,16 +37,11 @@ rust_library( crate_features = [ "Win32", "Win32_Foundation", - "Win32_Networking", - "Win32_Networking_WinSock", "Win32_Security", "Win32_Storage", "Win32_Storage_FileSystem", "Win32_System", - "Win32_System_Console", "Win32_System_IO", - "Win32_System_Pipes", - "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_System_WindowsProgramming", "default", diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.61.2.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.61.2.bazel index d4350c80f031..468b10a4139c 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.61.2.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.61.2.bazel @@ -37,8 +37,17 @@ rust_library( crate_features = [ "Win32", "Win32_Foundation", + "Win32_Networking", + "Win32_Networking_WinSock", + "Win32_Security", + "Win32_Storage", + "Win32_Storage_FileSystem", "Win32_System", + "Win32_System_Console", + "Win32_System_IO", + "Win32_System_Pipes", "Win32_System_ProcessStatus", + "Win32_System_SystemInformation", "Win32_System_Threading", "default", ], diff --git a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl index 8216914f89b6..85a5b1c4d4b8 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl +++ b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl @@ -388,6 +388,9 @@ _NORMAL_DEPENDENCIES = { "tree-sitter-ql": Label("@vendor_rs//tree-sitter-ql-0.23.1"), "tree-sitter-ql-dbscheme": Label("@vendor_rs//tree-sitter-ql-dbscheme-0.23.0"), }, + "cfg(not(windows))": { + "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), + }, }, "ruby/extractor": { _COMMON_CONDITION: { @@ -402,6 +405,9 @@ _NORMAL_DEPENDENCIES = { "tree-sitter-embedded-template": Label("@vendor_rs//tree-sitter-embedded-template-0.25.0"), "tree-sitter-ruby": Label("@vendor_rs//tree-sitter-ruby-0.23.1"), }, + "cfg(not(windows))": { + "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), + }, }, "rust/ast-generator": { _COMMON_CONDITION: { @@ -454,6 +460,9 @@ _NORMAL_DEPENDENCIES = { "tracing-subscriber": Label("@vendor_rs//tracing-subscriber-0.3.23"), "triomphe": Label("@vendor_rs//triomphe-0.1.17"), }, + "cfg(not(windows))": { + "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), + }, }, "shared/extractor-common": { }, @@ -508,6 +517,9 @@ _NORMAL_DEPENDENCIES = { "tracing": Label("@vendor_rs//tracing-0.1.44"), "tracing-subscriber": Label("@vendor_rs//tracing-subscriber-0.3.23"), }, + "cfg(not(windows))": { + "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), + }, }, "unified/extractor-unsupported-os": { }, @@ -535,10 +547,14 @@ _NORMAL_ALIASES = { "ql/extractor": { _COMMON_CONDITION: { }, + "cfg(not(windows))": { + }, }, "ruby/extractor": { _COMMON_CONDITION: { }, + "cfg(not(windows))": { + }, }, "rust/ast-generator": { _COMMON_CONDITION: { @@ -550,6 +566,8 @@ _NORMAL_ALIASES = { "rust/extractor": { _COMMON_CONDITION: { }, + "cfg(not(windows))": { + }, }, "shared/extractor-common": { }, @@ -572,6 +590,8 @@ _NORMAL_ALIASES = { "unified/extractor": { _COMMON_CONDITION: { }, + "cfg(not(windows))": { + }, }, "unified/extractor-unsupported-os": { }, @@ -3794,6 +3814,26 @@ def crate_repositories(): build_file = Label("//misc/bazel/3rdparty/rust_workspace_deps:BUILD.thread_local-1.1.10.bazel"), ) + maybe( + http_archive, + name = "vendor_rs__tikv-jemalloc-sys-0.7.1-5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8", + sha256 = "1a2825c78386b4ae0314074867860ba9577875de945f05992c38815cbec327f0", + type = "tar.gz", + urls = ["https://static.crates.io/crates/tikv-jemalloc-sys/0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/download"], + strip_prefix = "tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8", + build_file = Label("//misc/bazel/3rdparty/rust_workspace_deps:BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel"), + ) + + maybe( + http_archive, + name = "vendor_rs__tikv-jemallocator-0.7.0", + sha256 = "249f09e49ab1609436f34c776e84231bead18d6a955f119f939bdc1d847561bd", + type = "tar.gz", + urls = ["https://static.crates.io/crates/tikv-jemallocator/0.7.0/download"], + strip_prefix = "tikv-jemallocator-0.7.0", + build_file = Label("//misc/bazel/3rdparty/rust_workspace_deps:BUILD.tikv-jemallocator-0.7.0.bazel"), + ) + maybe( http_archive, name = "vendor_rs__time-0.3.55", @@ -4591,6 +4631,7 @@ def crate_repositories(): struct(repo = "vendor_rs__serde_yaml-0.9.34-deprecated", is_dev_dep = False), struct(repo = "vendor_rs__syn-3.0.9", is_dev_dep = False), struct(repo = "vendor_rs__tempfile-3.27.0", is_dev_dep = False), + struct(repo = "vendor_rs__tikv-jemallocator-0.7.0", is_dev_dep = False), struct(repo = "vendor_rs__toml-1.1.8-spec-1.1.0", is_dev_dep = False), struct(repo = "vendor_rs__tracing-0.1.44", is_dev_dep = False), struct(repo = "vendor_rs__tracing-flame-0.2.0", is_dev_dep = False), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator-0.7.0/BUILD.bazel b/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator-0.7.0/BUILD.bazel new file mode 100644 index 000000000000..4dc2adbe6c8c --- /dev/null +++ b/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator-0.7.0/BUILD.bazel @@ -0,0 +1,15 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @@//misc/bazel/3rdparty:vendor_rust_workspace_deps +############################################################################### + +package(default_visibility = ["//visibility:public"]) + +alias( + name = "tikv-jemallocator-0.7.0", + actual = "@vendor_rs__tikv-jemallocator-0.7.0//:tikv_jemallocator", + tags = ["manual"], +) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator/BUILD.bazel b/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator/BUILD.bazel new file mode 100644 index 000000000000..9ca1b57bc465 --- /dev/null +++ b/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator/BUILD.bazel @@ -0,0 +1,15 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @@//misc/bazel/3rdparty:vendor_rust_workspace_deps +############################################################################### + +package(default_visibility = ["//visibility:public"]) + +alias( + name = "tikv-jemallocator", + actual = "@vendor_rs__tikv-jemallocator-0.7.0//:tikv_jemallocator", + tags = ["manual"], +) diff --git a/ql/extractor/Cargo.toml b/ql/extractor/Cargo.toml index 8f68f9331741..d1eb44e8fc8b 100644 --- a/ql/extractor/Cargo.toml +++ b/ql/extractor/Cargo.toml @@ -21,3 +21,6 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } rayon = "1.9.0" regex = "1.10.4" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } + +[target.'cfg(not(windows))'.dependencies] +tikv-jemallocator = "0.7.0" diff --git a/ql/extractor/src/main.rs b/ql/extractor/src/main.rs index e6721d4e2243..ada03216a883 100644 --- a/ql/extractor/src/main.rs +++ b/ql/extractor/src/main.rs @@ -4,6 +4,10 @@ mod autobuilder; mod extractor; mod generator; +#[cfg(not(windows))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + #[derive(Parser)] #[command(author, version, about)] enum Cli { diff --git a/ruby/extractor/Cargo.toml b/ruby/extractor/Cargo.toml index e9b8af450b5c..6c9d9db887cf 100644 --- a/ruby/extractor/Cargo.toml +++ b/ruby/extractor/Cargo.toml @@ -23,3 +23,6 @@ serde_json = "1.0.154" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } extractor-common = { path = "../../shared/extractor-common" } + +[target.'cfg(not(windows))'.dependencies] +tikv-jemallocator = "0.7.0" diff --git a/ruby/extractor/src/main.rs b/ruby/extractor/src/main.rs index 7768a535bc30..1ad4dd6baec9 100644 --- a/ruby/extractor/src/main.rs +++ b/ruby/extractor/src/main.rs @@ -4,6 +4,10 @@ mod autobuilder; mod extractor; mod generator; +#[cfg(not(windows))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + #[derive(Parser)] #[command(author, version, about)] enum Cli { diff --git a/rust/extractor/Cargo.toml b/rust/extractor/Cargo.toml index f013fb07ea76..e4e8b0ba624a 100644 --- a/rust/extractor/Cargo.toml +++ b/rust/extractor/Cargo.toml @@ -44,3 +44,6 @@ tracing = "0.1.44" tracing-flame = "0.2.0" tracing-subscriber = "0.3.23" mustache = "0.9.0" + +[target.'cfg(not(windows))'.dependencies] +tikv-jemallocator = "0.7.0" diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 92f119b68777..548f89f04123 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -37,6 +37,10 @@ mod translate; pub mod trap; mod util; +#[cfg(not(windows))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + struct Extractor<'a> { archiver: &'a Archiver, traps: &'a trap::TrapFileProvider, diff --git a/unified/extractor/Cargo.toml b/unified/extractor/Cargo.toml index 6843d3e6d7bd..65ccfab67c2a 100644 --- a/unified/extractor/Cargo.toml +++ b/unified/extractor/Cargo.toml @@ -21,3 +21,6 @@ serde_json = { version = "1.0.154", features = ["unbounded_depth"] } codeql-extractor = { path = "../../shared/tree-sitter-extractor" } yeast = { path = "../../shared/yeast" } swift-syntax-rs = { path = "../swift-syntax-rs" } + +[target.'cfg(not(windows))'.dependencies] +tikv-jemallocator = "0.7.0" diff --git a/unified/extractor/src/main.rs b/unified/extractor/src/main.rs index 5a3407c37a29..203791402995 100644 --- a/unified/extractor/src/main.rs +++ b/unified/extractor/src/main.rs @@ -5,6 +5,10 @@ mod extractor; mod generator; mod languages; +#[cfg(not(windows))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + #[derive(Parser)] #[command(author, version, about)] enum Cli { From 226b91c796bfd01d346f44800c51edcf64a997f6 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Wed, 2 Dec 2026 15:01:02 +0000 Subject: [PATCH 02/12] Bazel: Don't register jemalloc as default malloc zone on macOS Matches the Cargo build, where only Rust allocations go through jemalloc. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- misc/bazel/3rdparty/BUILD.bazel | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/bazel/3rdparty/BUILD.bazel b/misc/bazel/3rdparty/BUILD.bazel index acdfed7bdb3e..b45f747030b3 100644 --- a/misc/bazel/3rdparty/BUILD.bazel +++ b/misc/bazel/3rdparty/BUILD.bazel @@ -32,11 +32,13 @@ crates_vendor( ) # jemalloc built hermetically by Bazel, replacing `tikv-jemalloc-sys`'s configure/make build script. -# Configured like that build script does by default (`_rjem_` prefix, matching `--cfg=prefixed`). +# Configured like that build script does by default (`_rjem_` prefix, matching `--cfg=prefixed`), and without +# registering as the macOS default malloc zone, so only Rust allocations go through jemalloc. jemalloc( name = "jemalloc", cxx = "False", jemalloc_prefix = "_rjem_", stats = "False", visibility = ["//visibility:public"], + zone_allocator = "no", ) From 4288be5ef4b30babe8b693c73683abdbdabbf6e4 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Wed, 2 Dec 2026 15:08:08 +0000 Subject: [PATCH 03/12] Shared: Restrict jemalloc to the Rust extractor Other extractors are left for a separate, measured follow-up. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Cargo.lock | 3 --- .../bazel/3rdparty/rust_workspace_deps/crates.bzl | 15 --------------- ql/extractor/Cargo.toml | 3 --- ql/extractor/src/main.rs | 4 ---- ruby/extractor/Cargo.toml | 3 --- ruby/extractor/src/main.rs | 4 ---- unified/extractor/Cargo.toml | 3 --- unified/extractor/src/main.rs | 4 ---- 8 files changed, 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5005cd2c797b..0a379fc64091 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,7 +471,6 @@ dependencies = [ "codeql-extractor", "rayon", "regex", - "tikv-jemallocator", "tracing", "tracing-subscriber", "tree-sitter", @@ -492,7 +491,6 @@ dependencies = [ "rayon", "regex", "serde_json", - "tikv-jemallocator", "tracing", "tracing-subscriber", "tree-sitter", @@ -511,7 +509,6 @@ dependencies = [ "serde", "serde_json", "swift-syntax-rs", - "tikv-jemallocator", "tracing", "tracing-subscriber", "yeast", diff --git a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl index 85a5b1c4d4b8..39139d38d988 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl +++ b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl @@ -388,9 +388,6 @@ _NORMAL_DEPENDENCIES = { "tree-sitter-ql": Label("@vendor_rs//tree-sitter-ql-0.23.1"), "tree-sitter-ql-dbscheme": Label("@vendor_rs//tree-sitter-ql-dbscheme-0.23.0"), }, - "cfg(not(windows))": { - "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), - }, }, "ruby/extractor": { _COMMON_CONDITION: { @@ -405,9 +402,6 @@ _NORMAL_DEPENDENCIES = { "tree-sitter-embedded-template": Label("@vendor_rs//tree-sitter-embedded-template-0.25.0"), "tree-sitter-ruby": Label("@vendor_rs//tree-sitter-ruby-0.23.1"), }, - "cfg(not(windows))": { - "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), - }, }, "rust/ast-generator": { _COMMON_CONDITION: { @@ -517,9 +511,6 @@ _NORMAL_DEPENDENCIES = { "tracing": Label("@vendor_rs//tracing-0.1.44"), "tracing-subscriber": Label("@vendor_rs//tracing-subscriber-0.3.23"), }, - "cfg(not(windows))": { - "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), - }, }, "unified/extractor-unsupported-os": { }, @@ -547,14 +538,10 @@ _NORMAL_ALIASES = { "ql/extractor": { _COMMON_CONDITION: { }, - "cfg(not(windows))": { - }, }, "ruby/extractor": { _COMMON_CONDITION: { }, - "cfg(not(windows))": { - }, }, "rust/ast-generator": { _COMMON_CONDITION: { @@ -590,8 +577,6 @@ _NORMAL_ALIASES = { "unified/extractor": { _COMMON_CONDITION: { }, - "cfg(not(windows))": { - }, }, "unified/extractor-unsupported-os": { }, diff --git a/ql/extractor/Cargo.toml b/ql/extractor/Cargo.toml index d1eb44e8fc8b..8f68f9331741 100644 --- a/ql/extractor/Cargo.toml +++ b/ql/extractor/Cargo.toml @@ -21,6 +21,3 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } rayon = "1.9.0" regex = "1.10.4" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } - -[target.'cfg(not(windows))'.dependencies] -tikv-jemallocator = "0.7.0" diff --git a/ql/extractor/src/main.rs b/ql/extractor/src/main.rs index ada03216a883..e6721d4e2243 100644 --- a/ql/extractor/src/main.rs +++ b/ql/extractor/src/main.rs @@ -4,10 +4,6 @@ mod autobuilder; mod extractor; mod generator; -#[cfg(not(windows))] -#[global_allocator] -static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; - #[derive(Parser)] #[command(author, version, about)] enum Cli { diff --git a/ruby/extractor/Cargo.toml b/ruby/extractor/Cargo.toml index 6c9d9db887cf..e9b8af450b5c 100644 --- a/ruby/extractor/Cargo.toml +++ b/ruby/extractor/Cargo.toml @@ -23,6 +23,3 @@ serde_json = "1.0.154" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } extractor-common = { path = "../../shared/extractor-common" } - -[target.'cfg(not(windows))'.dependencies] -tikv-jemallocator = "0.7.0" diff --git a/ruby/extractor/src/main.rs b/ruby/extractor/src/main.rs index 1ad4dd6baec9..7768a535bc30 100644 --- a/ruby/extractor/src/main.rs +++ b/ruby/extractor/src/main.rs @@ -4,10 +4,6 @@ mod autobuilder; mod extractor; mod generator; -#[cfg(not(windows))] -#[global_allocator] -static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; - #[derive(Parser)] #[command(author, version, about)] enum Cli { diff --git a/unified/extractor/Cargo.toml b/unified/extractor/Cargo.toml index 65ccfab67c2a..6843d3e6d7bd 100644 --- a/unified/extractor/Cargo.toml +++ b/unified/extractor/Cargo.toml @@ -21,6 +21,3 @@ serde_json = { version = "1.0.154", features = ["unbounded_depth"] } codeql-extractor = { path = "../../shared/tree-sitter-extractor" } yeast = { path = "../../shared/yeast" } swift-syntax-rs = { path = "../swift-syntax-rs" } - -[target.'cfg(not(windows))'.dependencies] -tikv-jemallocator = "0.7.0" diff --git a/unified/extractor/src/main.rs b/unified/extractor/src/main.rs index 203791402995..5a3407c37a29 100644 --- a/unified/extractor/src/main.rs +++ b/unified/extractor/src/main.rs @@ -5,10 +5,6 @@ mod extractor; mod generator; mod languages; -#[cfg(not(windows))] -#[global_allocator] -static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; - #[derive(Parser)] #[command(author, version, about)] enum Cli { From 4000b93ffc0bf09a791ef5688f4dd91d83a056e3 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Wed, 2 Dec 2026 15:37:01 +0000 Subject: [PATCH 04/12] Rust: Fix jemalloc Bazel build with cc_common linking and on macOS When linking through `cc_common` with mangled allocator symbols, the default allocator shim clashes with the `__rust_alloc*` symbols emitted for the `#[global_allocator]`. Give the extractor its own shim providing only the remaining symbol. On macOS the C++ toolchain declares no `nm`, which jemalloc needs to generate its private namespace header, so point jemalloc at Xcode's. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .bazelrc | 3 +++ misc/bazel/3rdparty/BUILD.bazel | 8 ++++++++ misc/bazel/3rdparty/xcrun_nm.sh | 2 ++ misc/bazel/global_allocator/BUILD.bazel | 22 ++++++++++++++++++++++ misc/bazel/global_allocator/shim.rs | 7 +++++++ rust/extractor/BUILD.bazel | 6 ++++++ 6 files changed, 48 insertions(+) create mode 100755 misc/bazel/3rdparty/xcrun_nm.sh create mode 100644 misc/bazel/global_allocator/BUILD.bazel create mode 100644 misc/bazel/global_allocator/shim.rs diff --git a/.bazelrc b/.bazelrc index af13e1838e49..1ca64e82cc6c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -41,6 +41,9 @@ common --@rules_dotnet//dotnet/settings:strict_deps=false # we only configure a nightly toolchain common --@rules_rust//rust/toolchain/channel=nightly +# the macOS C++ toolchain declares no `nm`, needed by jemalloc +common:macos --@jemalloc//settings/flags:nm=//misc/bazel/3rdparty:xcrun_nm + # Reduce this eventually to empty, once we've fixed all our usages of java, and https://github.com/bazel-contrib/rules_go/issues/4193 is fixed common --incompatible_autoload_externally="+@rules_cc,+@rules_java,+@rules_shell" diff --git a/misc/bazel/3rdparty/BUILD.bazel b/misc/bazel/3rdparty/BUILD.bazel index b45f747030b3..32ab8e921972 100644 --- a/misc/bazel/3rdparty/BUILD.bazel +++ b/misc/bazel/3rdparty/BUILD.bazel @@ -1,5 +1,6 @@ load("@jemalloc//settings:config.bzl", "jemalloc") load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor") +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") # The targets in this file re-do the vendoring of the rust cargo dependencies. Use the update_all_rust_deps.sh script to run the targets, and do all the necessary work around vendoring. crates_vendor( @@ -42,3 +43,10 @@ jemalloc( visibility = ["//visibility:public"], zone_allocator = "no", ) + +# The macOS C++ toolchain declares no `nm`, which jemalloc needs to generate its private namespace header. +# Selected in `.bazelrc` via `@jemalloc//settings/flags:nm`. +sh_binary( + name = "xcrun_nm", + srcs = ["xcrun_nm.sh"], +) diff --git a/misc/bazel/3rdparty/xcrun_nm.sh b/misc/bazel/3rdparty/xcrun_nm.sh new file mode 100755 index 000000000000..481d037f11f3 --- /dev/null +++ b/misc/bazel/3rdparty/xcrun_nm.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exec /usr/bin/xcrun nm "$@" diff --git a/misc/bazel/global_allocator/BUILD.bazel b/misc/bazel/global_allocator/BUILD.bazel new file mode 100644 index 000000000000..232600872c53 --- /dev/null +++ b/misc/bazel/global_allocator/BUILD.bazel @@ -0,0 +1,22 @@ +load("@rules_rust//rust:defs.bzl", "rust_library") + +# buildifier: disable=bzl-visibility +load("@rules_rust//rust/private:rust_allocator_libraries.bzl", "rust_allocator_libraries") + +# Allocator shim for `rust_binary` targets defining a `#[global_allocator]`, to be passed as their +# `allocator_libraries`. It is only used when linking with `cc_common` and mangled allocator symbols, +# where the default shim would clash with the `__rust_alloc*` symbols emitted for the global +# allocator. The upstream `experimental_use_global_allocator` setting cannot be used instead, as it +# is toolchain-wide and its shim lags behind current nightly rustc. +rust_allocator_libraries( + name = "global_allocator", + allocator_library = ":shim", + visibility = ["//visibility:public"], +) + +rust_library( + name = "shim", + srcs = ["shim.rs"], + allocator_libraries = "@rules_rust//ffi/rs:empty_allocator_libraries", + edition = "2024", +) diff --git a/misc/bazel/global_allocator/shim.rs b/misc/bazel/global_allocator/shim.rs new file mode 100644 index 000000000000..3dcadc699565 --- /dev/null +++ b/misc/bazel/global_allocator/shim.rs @@ -0,0 +1,7 @@ +// The only allocator shim symbol not provided by `std` or by `#[global_allocator]` itself. +#![no_std] +#![allow(internal_features)] +#![feature(rustc_attrs)] + +#[rustc_std_internal_symbol] +fn __rust_no_alloc_shim_is_unstable_v2() {} diff --git a/rust/extractor/BUILD.bazel b/rust/extractor/BUILD.bazel index 0ed545a7f37e..66eec0a02ae7 100644 --- a/rust/extractor/BUILD.bazel +++ b/rust/extractor/BUILD.bazel @@ -1,3 +1,4 @@ +load("//misc/bazel:os.bzl", "os_select") load("//misc/bazel:rust.bzl", "codeql_rust_binary") load("//misc/bazel/3rdparty/rust_workspace_deps:defs.bzl", "aliases", "all_crate_deps") @@ -7,6 +8,11 @@ codeql_rust_binary( name = "extractor", srcs = glob(["src/**/*.rs"]), aliases = aliases(), + # matches the `cfg(not(windows))` jemalloc `#[global_allocator]` + allocator_libraries = os_select( + posix = "//misc/bazel/global_allocator", + windows = "@rules_rust//ffi/rs:default_allocator_libraries", + ), compile_data = [ "src/qltest_cargo.mustache", "src/nightly-toolchain/rust-toolchain.toml", From 4429ba98b10008c6a1ef0c1d06ae144c7a076429 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Wed, 2 Dec 2026 15:52:26 +0000 Subject: [PATCH 05/12] Shared: Use jemalloc in the Ruby, QL and unified extractors Also move the Bazel allocator shim wiring into a `global_allocator` option of `codeql_rust_binary`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Cargo.lock | 3 +++ .../bazel/3rdparty/rust_workspace_deps/crates.bzl | 15 +++++++++++++++ misc/bazel/global_allocator/BUILD.bazel | 3 +-- misc/bazel/rust.bzl | 10 ++++++++++ ql/extractor/Cargo.toml | 3 +++ ql/extractor/src/main.rs | 4 ++++ ruby/extractor/BUILD.bazel | 1 + ruby/extractor/Cargo.toml | 3 +++ ruby/extractor/src/main.rs | 4 ++++ rust/extractor/BUILD.bazel | 7 +------ unified/extractor/BUILD.bazel | 1 + unified/extractor/Cargo.toml | 3 +++ unified/extractor/src/main.rs | 4 ++++ 13 files changed, 53 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a379fc64091..5005cd2c797b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,6 +471,7 @@ dependencies = [ "codeql-extractor", "rayon", "regex", + "tikv-jemallocator", "tracing", "tracing-subscriber", "tree-sitter", @@ -491,6 +492,7 @@ dependencies = [ "rayon", "regex", "serde_json", + "tikv-jemallocator", "tracing", "tracing-subscriber", "tree-sitter", @@ -509,6 +511,7 @@ dependencies = [ "serde", "serde_json", "swift-syntax-rs", + "tikv-jemallocator", "tracing", "tracing-subscriber", "yeast", diff --git a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl index 39139d38d988..85a5b1c4d4b8 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl +++ b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl @@ -388,6 +388,9 @@ _NORMAL_DEPENDENCIES = { "tree-sitter-ql": Label("@vendor_rs//tree-sitter-ql-0.23.1"), "tree-sitter-ql-dbscheme": Label("@vendor_rs//tree-sitter-ql-dbscheme-0.23.0"), }, + "cfg(not(windows))": { + "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), + }, }, "ruby/extractor": { _COMMON_CONDITION: { @@ -402,6 +405,9 @@ _NORMAL_DEPENDENCIES = { "tree-sitter-embedded-template": Label("@vendor_rs//tree-sitter-embedded-template-0.25.0"), "tree-sitter-ruby": Label("@vendor_rs//tree-sitter-ruby-0.23.1"), }, + "cfg(not(windows))": { + "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), + }, }, "rust/ast-generator": { _COMMON_CONDITION: { @@ -511,6 +517,9 @@ _NORMAL_DEPENDENCIES = { "tracing": Label("@vendor_rs//tracing-0.1.44"), "tracing-subscriber": Label("@vendor_rs//tracing-subscriber-0.3.23"), }, + "cfg(not(windows))": { + "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), + }, }, "unified/extractor-unsupported-os": { }, @@ -538,10 +547,14 @@ _NORMAL_ALIASES = { "ql/extractor": { _COMMON_CONDITION: { }, + "cfg(not(windows))": { + }, }, "ruby/extractor": { _COMMON_CONDITION: { }, + "cfg(not(windows))": { + }, }, "rust/ast-generator": { _COMMON_CONDITION: { @@ -577,6 +590,8 @@ _NORMAL_ALIASES = { "unified/extractor": { _COMMON_CONDITION: { }, + "cfg(not(windows))": { + }, }, "unified/extractor-unsupported-os": { }, diff --git a/misc/bazel/global_allocator/BUILD.bazel b/misc/bazel/global_allocator/BUILD.bazel index 232600872c53..ea440f22a4f8 100644 --- a/misc/bazel/global_allocator/BUILD.bazel +++ b/misc/bazel/global_allocator/BUILD.bazel @@ -3,8 +3,7 @@ load("@rules_rust//rust:defs.bzl", "rust_library") # buildifier: disable=bzl-visibility load("@rules_rust//rust/private:rust_allocator_libraries.bzl", "rust_allocator_libraries") -# Allocator shim for `rust_binary` targets defining a `#[global_allocator]`, to be passed as their -# `allocator_libraries`. It is only used when linking with `cc_common` and mangled allocator symbols, +# Allocator shim for binaries defining a `#[global_allocator]`, see `codeql_rust_binary`. It is only used when linking with `cc_common` and mangled allocator symbols, # where the default shim would clash with the `__rust_alloc*` symbols emitted for the global # allocator. The upstream `experimental_use_global_allocator` setting cannot be used instead, as it # is toolchain-wide and its shim lags behind current nightly rustc. diff --git a/misc/bazel/rust.bzl b/misc/bazel/rust.bzl index 97afee4ba1c1..63c3809d2a0d 100644 --- a/misc/bazel/rust.bzl +++ b/misc/bazel/rust.bzl @@ -1,13 +1,18 @@ load("@rules_rust//rust:defs.bzl", "rust_binary") load("@semmle_code//buildutils-internal:glibc_symbols_check.bzl", "glibc_symbols_check") load("@semmle_code//buildutils-internal:lipo.bzl", "universal_binary") +load("//misc/bazel:os.bzl", "os_select") def codeql_rust_binary( name, target_compatible_with = None, visibility = None, symbols_test = True, + global_allocator = False, **kwargs): + """ + `global_allocator` must be set when the crate defines a `#[global_allocator]` on non-Windows targets. + """ rust_label_name = "single_arch/" + name universal_binary( name = name, @@ -15,6 +20,11 @@ def codeql_rust_binary( target_compatible_with = target_compatible_with, visibility = visibility, ) + if global_allocator: + kwargs["allocator_libraries"] = os_select( + posix = Label("//misc/bazel/global_allocator"), + windows = "@rules_rust//ffi/rs:default_allocator_libraries", + ) rust_binary( name = rust_label_name, **kwargs diff --git a/ql/extractor/Cargo.toml b/ql/extractor/Cargo.toml index 8f68f9331741..d1eb44e8fc8b 100644 --- a/ql/extractor/Cargo.toml +++ b/ql/extractor/Cargo.toml @@ -21,3 +21,6 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } rayon = "1.9.0" regex = "1.10.4" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } + +[target.'cfg(not(windows))'.dependencies] +tikv-jemallocator = "0.7.0" diff --git a/ql/extractor/src/main.rs b/ql/extractor/src/main.rs index e6721d4e2243..ada03216a883 100644 --- a/ql/extractor/src/main.rs +++ b/ql/extractor/src/main.rs @@ -4,6 +4,10 @@ mod autobuilder; mod extractor; mod generator; +#[cfg(not(windows))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + #[derive(Parser)] #[command(author, version, about)] enum Cli { diff --git a/ruby/extractor/BUILD.bazel b/ruby/extractor/BUILD.bazel index 8c93cec30785..7d0f152f77fe 100644 --- a/ruby/extractor/BUILD.bazel +++ b/ruby/extractor/BUILD.bazel @@ -7,6 +7,7 @@ codeql_rust_binary( name = "extractor", srcs = glob(["src/*.rs"]), aliases = aliases(), + global_allocator = True, proc_macro_deps = all_crate_deps( proc_macro = True, ), diff --git a/ruby/extractor/Cargo.toml b/ruby/extractor/Cargo.toml index e9b8af450b5c..6c9d9db887cf 100644 --- a/ruby/extractor/Cargo.toml +++ b/ruby/extractor/Cargo.toml @@ -23,3 +23,6 @@ serde_json = "1.0.154" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } extractor-common = { path = "../../shared/extractor-common" } + +[target.'cfg(not(windows))'.dependencies] +tikv-jemallocator = "0.7.0" diff --git a/ruby/extractor/src/main.rs b/ruby/extractor/src/main.rs index 7768a535bc30..1ad4dd6baec9 100644 --- a/ruby/extractor/src/main.rs +++ b/ruby/extractor/src/main.rs @@ -4,6 +4,10 @@ mod autobuilder; mod extractor; mod generator; +#[cfg(not(windows))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + #[derive(Parser)] #[command(author, version, about)] enum Cli { diff --git a/rust/extractor/BUILD.bazel b/rust/extractor/BUILD.bazel index 66eec0a02ae7..9e421551da55 100644 --- a/rust/extractor/BUILD.bazel +++ b/rust/extractor/BUILD.bazel @@ -1,4 +1,3 @@ -load("//misc/bazel:os.bzl", "os_select") load("//misc/bazel:rust.bzl", "codeql_rust_binary") load("//misc/bazel/3rdparty/rust_workspace_deps:defs.bzl", "aliases", "all_crate_deps") @@ -8,15 +7,11 @@ codeql_rust_binary( name = "extractor", srcs = glob(["src/**/*.rs"]), aliases = aliases(), - # matches the `cfg(not(windows))` jemalloc `#[global_allocator]` - allocator_libraries = os_select( - posix = "//misc/bazel/global_allocator", - windows = "@rules_rust//ffi/rs:default_allocator_libraries", - ), compile_data = [ "src/qltest_cargo.mustache", "src/nightly-toolchain/rust-toolchain.toml", ], + global_allocator = True, proc_macro_deps = all_crate_deps( proc_macro = True, ), diff --git a/unified/extractor/BUILD.bazel b/unified/extractor/BUILD.bazel index 73ce3ca0e810..15c482305a37 100644 --- a/unified/extractor/BUILD.bazel +++ b/unified/extractor/BUILD.bazel @@ -15,6 +15,7 @@ codeql_rust_binary( "swift_node_types.yml", ], data = ["//unified/swift-syntax-rs:swift_runtime"], + global_allocator = True, proc_macro_deps = all_crate_deps( proc_macro = True, ), diff --git a/unified/extractor/Cargo.toml b/unified/extractor/Cargo.toml index 6843d3e6d7bd..65ccfab67c2a 100644 --- a/unified/extractor/Cargo.toml +++ b/unified/extractor/Cargo.toml @@ -21,3 +21,6 @@ serde_json = { version = "1.0.154", features = ["unbounded_depth"] } codeql-extractor = { path = "../../shared/tree-sitter-extractor" } yeast = { path = "../../shared/yeast" } swift-syntax-rs = { path = "../swift-syntax-rs" } + +[target.'cfg(not(windows))'.dependencies] +tikv-jemallocator = "0.7.0" diff --git a/unified/extractor/src/main.rs b/unified/extractor/src/main.rs index 5a3407c37a29..203791402995 100644 --- a/unified/extractor/src/main.rs +++ b/unified/extractor/src/main.rs @@ -5,6 +5,10 @@ mod extractor; mod generator; mod languages; +#[cfg(not(windows))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + #[derive(Parser)] #[command(author, version, about)] enum Cli { From 625a554272cb0f2905decf1d4ecdd085be609722 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Wed, 2 Dec 2026 16:25:01 +0000 Subject: [PATCH 06/12] Unified: Use a single jemalloc arena in the extractor With default per-thread arenas, peak RSS on Alamofire was ~60% above the system allocator. narenas:1 brings it below that with no measured CPU or wall-time cost. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- unified/extractor/src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/unified/extractor/src/main.rs b/unified/extractor/src/main.rs index 203791402995..92895a0f0144 100644 --- a/unified/extractor/src/main.rs +++ b/unified/extractor/src/main.rs @@ -9,6 +9,12 @@ mod languages; #[global_allocator] static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; +// With jemalloc's default per-thread arenas, peak RSS was ~60% above the system allocator here; +// a single arena brings it below that at no measured CPU cost. +#[cfg(not(windows))] +#[unsafe(export_name = "_rjem_malloc_conf")] +static MALLOC_CONF: &[u8; 10] = b"narenas:1\0"; + #[derive(Parser)] #[command(author, version, about)] enum Cli { From e0166d5e3e2d063662319ea0b7f31753a255c84f Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 3 Dec 2026 08:48:21 +0000 Subject: [PATCH 07/12] Ruby, QL: Route tree-sitter allocations to jemalloc Calls tree_sitter::set_allocator with the prefixed jemalloc functions at the start of main, so the parser's C allocations share the Rust allocator. The Ruby external scanner keeps using libc for its own create/destroy pairs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ql/extractor/src/main.rs | 23 +++++++++++++++++++++++ ruby/extractor/src/main.rs | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/ql/extractor/src/main.rs b/ql/extractor/src/main.rs index ada03216a883..e07a4068ca15 100644 --- a/ql/extractor/src/main.rs +++ b/ql/extractor/src/main.rs @@ -8,6 +8,27 @@ mod generator; #[global_allocator] static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; +/// Routes tree-sitter's C allocations to the same (prefixed) jemalloc as Rust allocations. +#[cfg(not(windows))] +fn use_jemalloc_for_tree_sitter() { + use std::ffi::c_void; + unsafe extern "C" { + fn _rjem_malloc(size: usize) -> *mut c_void; + fn _rjem_calloc(count: usize, size: usize) -> *mut c_void; + fn _rjem_realloc(ptr: *mut c_void, size: usize) -> *mut c_void; + fn _rjem_free(ptr: *mut c_void); + } + // SAFETY: called first thing in `main`, before tree-sitter allocates anything. + unsafe { + tree_sitter::set_allocator( + Some(_rjem_malloc), + Some(_rjem_calloc), + Some(_rjem_realloc), + Some(_rjem_free), + ); + } +} + #[derive(Parser)] #[command(author, version, about)] enum Cli { @@ -17,6 +38,8 @@ enum Cli { } fn main() -> std::io::Result<()> { + #[cfg(not(windows))] + use_jemalloc_for_tree_sitter(); let cli = Cli::parse(); match cli { diff --git a/ruby/extractor/src/main.rs b/ruby/extractor/src/main.rs index 1ad4dd6baec9..e7c46fb35326 100644 --- a/ruby/extractor/src/main.rs +++ b/ruby/extractor/src/main.rs @@ -8,6 +8,27 @@ mod generator; #[global_allocator] static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; +/// Routes tree-sitter's C allocations to the same (prefixed) jemalloc as Rust allocations. +#[cfg(not(windows))] +fn use_jemalloc_for_tree_sitter() { + use std::ffi::c_void; + unsafe extern "C" { + fn _rjem_malloc(size: usize) -> *mut c_void; + fn _rjem_calloc(count: usize, size: usize) -> *mut c_void; + fn _rjem_realloc(ptr: *mut c_void, size: usize) -> *mut c_void; + fn _rjem_free(ptr: *mut c_void); + } + // SAFETY: called first thing in `main`, before tree-sitter allocates anything. + unsafe { + tree_sitter::set_allocator( + Some(_rjem_malloc), + Some(_rjem_calloc), + Some(_rjem_realloc), + Some(_rjem_free), + ); + } +} + #[derive(Parser)] #[command(author, version, about)] enum Cli { @@ -17,6 +38,8 @@ enum Cli { } fn main() -> std::io::Result<()> { + #[cfg(not(windows))] + use_jemalloc_for_tree_sitter(); let cli = Cli::parse(); match cli { From 1493072cc22eedb89a754d017d525ef683f98ef4 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 3 Dec 2026 09:07:04 +0000 Subject: [PATCH 08/12] Rust, Ruby, unified: Use jemalloc in Bazel builds only, on all platforms Replace tikv-jemallocator with a small Bazel-only adapter over the BCR jemalloc, enabled via `--cfg=codeql_jemalloc`, so Cargo builds never build or link jemalloc. QL is only built with Cargo and keeps the system allocator. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .bazelrc | 2 +- Cargo.lock | 40 ++---- Cargo.toml | 2 + MODULE.bazel | 1 - misc/bazel/3rdparty/BUILD.bazel | 30 +---- .../BUILD.anstyle-query-1.1.5.bazel | 6 +- .../BUILD.anstyle-wincon-3.0.11.bazel | 6 +- .../3rdparty/rust_workspace_deps/BUILD.bazel | 12 -- .../BUILD.errno-0.3.14.bazel | 6 +- .../BUILD.miow-0.6.1.bazel | 2 +- .../BUILD.nu-ansi-term-0.50.3.bazel | 12 +- .../BUILD.rustix-1.1.6.bazel | 6 +- .../BUILD.tempfile-3.27.0.bazel | 6 +- ...4ce1f1373e37dc865038e1bc8eeecf559ce8.bazel | 119 ------------------ .../BUILD.tikv-jemallocator-0.7.0.bazel | 119 ------------------ .../BUILD.winapi-util-0.1.11.bazel | 6 +- .../BUILD.windows-sys-0.60.2.bazel | 5 + .../BUILD.windows-sys-0.61.2.bazel | 9 -- .../3rdparty/rust_workspace_deps/crates.bzl | 41 ------ .../tikv-jemallocator-0.7.0/BUILD.bazel | 15 --- .../tikv-jemallocator/BUILD.bazel | 15 --- misc/bazel/global_allocator/BUILD.bazel | 21 ---- misc/bazel/jemalloc/BUILD.bazel | 49 ++++++++ misc/bazel/jemalloc/lib.rs | 72 +++++++++++ .../{global_allocator => jemalloc}/shim.rs | 0 misc/bazel/{3rdparty => jemalloc}/xcrun_nm.sh | 0 misc/bazel/rust.bzl | 15 ++- ql/extractor/Cargo.toml | 3 - ql/extractor/src/main.rs | 27 ---- ruby/extractor/BUILD.bazel | 2 +- ruby/extractor/Cargo.toml | 3 - ruby/extractor/src/main.rs | 23 ++-- rust/extractor/BUILD.bazel | 2 +- rust/extractor/Cargo.toml | 3 - rust/extractor/src/main.rs | 4 +- unified/extractor/BUILD.bazel | 2 +- unified/extractor/Cargo.toml | 3 - unified/extractor/src/main.rs | 6 +- 38 files changed, 186 insertions(+), 509 deletions(-) delete mode 100644 misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel delete mode 100644 misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemallocator-0.7.0.bazel delete mode 100644 misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator-0.7.0/BUILD.bazel delete mode 100644 misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator/BUILD.bazel delete mode 100644 misc/bazel/global_allocator/BUILD.bazel create mode 100644 misc/bazel/jemalloc/BUILD.bazel create mode 100644 misc/bazel/jemalloc/lib.rs rename misc/bazel/{global_allocator => jemalloc}/shim.rs (100%) rename misc/bazel/{3rdparty => jemalloc}/xcrun_nm.sh (100%) diff --git a/.bazelrc b/.bazelrc index 1ca64e82cc6c..9b0520f667e7 100644 --- a/.bazelrc +++ b/.bazelrc @@ -42,7 +42,7 @@ common --@rules_dotnet//dotnet/settings:strict_deps=false common --@rules_rust//rust/toolchain/channel=nightly # the macOS C++ toolchain declares no `nm`, needed by jemalloc -common:macos --@jemalloc//settings/flags:nm=//misc/bazel/3rdparty:xcrun_nm +common:macos --@jemalloc//settings/flags:nm=//misc/bazel/jemalloc:xcrun_nm # Reduce this eventually to empty, once we've fixed all our usages of java, and https://github.com/bazel-contrib/rules_go/issues/4193 is fixed common --incompatible_autoload_externally="+@rules_cc,+@rules_java,+@rules_shell" diff --git a/Cargo.lock b/Cargo.lock index 5005cd2c797b..a4037e283442 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,7 +97,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -108,7 +108,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -471,7 +471,6 @@ dependencies = [ "codeql-extractor", "rayon", "regex", - "tikv-jemallocator", "tracing", "tracing-subscriber", "tree-sitter", @@ -492,7 +491,6 @@ dependencies = [ "rayon", "regex", "serde_json", - "tikv-jemallocator", "tracing", "tracing-subscriber", "tree-sitter", @@ -511,7 +509,6 @@ dependencies = [ "serde", "serde_json", "swift-syntax-rs", - "tikv-jemallocator", "tracing", "tracing-subscriber", "yeast", @@ -555,7 +552,6 @@ dependencies = [ "ra_ap_vfs", "serde", "serde_json", - "tikv-jemallocator", "toml", "tracing", "tracing-flame", @@ -929,7 +925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -1432,7 +1428,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "536bfad37a309d62069485248eeaba1e8d9853aaf951caaeaed0585a95346f08" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -1496,7 +1492,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -2503,7 +2499,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -2823,7 +2819,7 @@ dependencies = [ "getrandom", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -2887,26 +2883,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "tikv-jemalloc-sys" -version = "0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a2825c78386b4ae0314074867860ba9577875de945f05992c38815cbec327f0" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "tikv-jemallocator" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "249f09e49ab1609436f34c776e84231bead18d6a955f119f939bdc1d847561bd" -dependencies = [ - "libc", - "tikv-jemalloc-sys", -] - [[package]] name = "time" version = "0.3.55" @@ -3341,7 +3317,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3b91087a7764..4c8f9798afc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,8 @@ edition = "2024" [workspace.lints.rust] redundant_imports = "warn" +# set by Bazel builds only, see `codeql_rust_binary` +unexpected_cfgs = { level = "warn", check-cfg = ["cfg(codeql_jemalloc)"] } [workspace.lints.clippy] all = { level = "warn", priority = -1 } diff --git a/MODULE.bazel b/MODULE.bazel index e6ab2bd53765..33691157a3f0 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -179,7 +179,6 @@ use_repo( "vendor_rs__serde_yaml-0.9.34-deprecated", "vendor_rs__syn-3.0.9", "vendor_rs__tempfile-3.27.0", - "vendor_rs__tikv-jemallocator-0.7.0", "vendor_rs__toml-1.1.8-spec-1.1.0", "vendor_rs__tracing-0.1.44", "vendor_rs__tracing-flame-0.2.0", diff --git a/misc/bazel/3rdparty/BUILD.bazel b/misc/bazel/3rdparty/BUILD.bazel index 32ab8e921972..11af92613344 100644 --- a/misc/bazel/3rdparty/BUILD.bazel +++ b/misc/bazel/3rdparty/BUILD.bazel @@ -1,17 +1,8 @@ -load("@jemalloc//settings:config.bzl", "jemalloc") -load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor") -load("@rules_shell//shell:sh_binary.bzl", "sh_binary") +load("@rules_rust//crate_universe:defs.bzl", "crates_vendor") # The targets in this file re-do the vendoring of the rust cargo dependencies. Use the update_all_rust_deps.sh script to run the targets, and do all the necessary work around vendoring. crates_vendor( name = "vendor_rust_workspace_deps", - annotations = { - "tikv-jemalloc-sys": [crate.annotation( - gen_build_script = False, - rustc_flags = ["--cfg=prefixed"], - deps = ["@codeql//misc/bazel/3rdparty:jemalloc"], - )], - }, cargo_lockfile = "//:Cargo.lock", generate_build_scripts = True, manifests = ["//:Cargo.toml"], @@ -31,22 +22,3 @@ crates_vendor( tags = ["manual"], vendor_path = "py_deps", ) - -# jemalloc built hermetically by Bazel, replacing `tikv-jemalloc-sys`'s configure/make build script. -# Configured like that build script does by default (`_rjem_` prefix, matching `--cfg=prefixed`), and without -# registering as the macOS default malloc zone, so only Rust allocations go through jemalloc. -jemalloc( - name = "jemalloc", - cxx = "False", - jemalloc_prefix = "_rjem_", - stats = "False", - visibility = ["//visibility:public"], - zone_allocator = "no", -) - -# The macOS C++ toolchain declares no `nm`, which jemalloc needs to generate its private namespace header. -# Selected in `.bazelrc` via `@jemalloc//settings/flags:nm`. -sh_binary( - name = "xcrun_nm", - srcs = ["xcrun_nm.sh"], -) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-query-1.1.5.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-query-1.1.5.bazel index c39b65a376ea..3856a392a925 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-query-1.1.5.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-query-1.1.5.bazel @@ -110,13 +110,13 @@ rust_library( version = "1.1.5", deps = select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "//conditions:default": [], }), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-wincon-3.0.11.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-wincon-3.0.11.bazel index 0ff8c8277eb3..adb633f723e5 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-wincon-3.0.11.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.anstyle-wincon-3.0.11.bazel @@ -113,15 +113,15 @@ rust_library( ] + select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ "@vendor_rs__once_cell_polyfill-1.70.2//:once_cell_polyfill", # cfg(windows) - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ "@vendor_rs__once_cell_polyfill-1.70.2//:once_cell_polyfill", # cfg(windows) - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ "@vendor_rs__once_cell_polyfill-1.70.2//:once_cell_polyfill", # cfg(windows) - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "//conditions:default": [], }), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.bazel index 06cf9bf2e13b..372295f1fb21 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.bazel @@ -601,18 +601,6 @@ alias( tags = ["manual"], ) -alias( - name = "tikv-jemallocator-0.7.0", - actual = "@vendor_rs__tikv-jemallocator-0.7.0//:tikv_jemallocator", - tags = ["manual"], -) - -alias( - name = "tikv-jemallocator", - actual = "@vendor_rs__tikv-jemallocator-0.7.0//:tikv_jemallocator", - tags = ["manual"], -) - alias( name = "toml-1.1.8+spec-1.1.0", actual = "@vendor_rs__toml-1.1.8-spec-1.1.0//:toml", diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.errno-0.3.14.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.errno-0.3.14.bazel index d72fa46bb97e..b21586c026ba 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.errno-0.3.14.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.errno-0.3.14.bazel @@ -128,7 +128,7 @@ rust_library( "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) ], "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [ "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) @@ -161,7 +161,7 @@ rust_library( "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-unknown-freebsd": [ "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) @@ -221,7 +221,7 @@ rust_library( "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-unknown-freebsd": [ "@vendor_rs__libc-0.2.189//:libc", # cfg(unix) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.miow-0.6.1.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.miow-0.6.1.bazel index 4d8ec819dc97..0e5f25419011 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.miow-0.6.1.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.miow-0.6.1.bazel @@ -109,6 +109,6 @@ rust_library( }), version = "0.6.1", deps = [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", + "@vendor_rs__windows-sys-0.60.2//:windows_sys", ], ) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.nu-ansi-term-0.50.3.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.nu-ansi-term-0.50.3.bazel index 50ca24bca7b9..da5447757deb 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.nu-ansi-term-0.50.3.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.nu-ansi-term-0.50.3.bazel @@ -24,13 +24,13 @@ rust_library( ), aliases = select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": { - "@vendor_rs__windows-sys-0.61.2//:windows_sys": "windows", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys": "windows", # cfg(windows) }, "@rules_rust//rust/platform:i686-pc-windows-msvc": { - "@vendor_rs__windows-sys-0.61.2//:windows_sys": "windows", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys": "windows", # cfg(windows) }, "@rules_rust//rust/platform:x86_64-pc-windows-msvc": { - "@vendor_rs__windows-sys-0.61.2//:windows_sys": "windows", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys": "windows", # cfg(windows) }, "//conditions:default": {}, }), @@ -126,13 +126,13 @@ rust_library( version = "0.50.3", deps = select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "//conditions:default": [], }), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.rustix-1.1.6.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.rustix-1.1.6.bazel index 449a5a54d32c..d557e3cdef74 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.rustix-1.1.6.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.rustix-1.1.6.bazel @@ -286,7 +286,7 @@ rust_library( ], "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(windows) - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [ "@vendor_rs__errno-0.3.14//:errno", # aarch64-unknown-fuchsia, cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))))) @@ -335,7 +335,7 @@ rust_library( ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(windows) - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-unknown-freebsd": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))))), i686-unknown-freebsd @@ -459,7 +459,7 @@ rust_library( ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(windows) - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-unknown-freebsd": [ "@vendor_rs__errno-0.3.14//:errno", # cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))))), x86_64-unknown-freebsd diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tempfile-3.27.0.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tempfile-3.27.0.bazel index bc7c26c16c1f..f4989937959c 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tempfile-3.27.0.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tempfile-3.27.0.bazel @@ -138,7 +138,7 @@ rust_library( ], "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # aarch64-pc-windows-msvc - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # aarch64-unknown-fuchsia @@ -182,7 +182,7 @@ rust_library( ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # i686-pc-windows-msvc - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-unknown-freebsd": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # i686-unknown-freebsd @@ -262,7 +262,7 @@ rust_library( ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # x86_64-pc-windows-msvc - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-unknown-freebsd": [ "@vendor_rs__getrandom-0.4.3//:getrandom", # x86_64-unknown-freebsd diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel deleted file mode 100644 index 5a48dd7ac239..000000000000 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel +++ /dev/null @@ -1,119 +0,0 @@ -############################################################################### -# @generated -# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To -# regenerate this file, run the following: -# -# bazel run @@//misc/bazel/3rdparty:vendor_rust_workspace_deps -############################################################################### - -load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") -load("@rules_rust//rust:defs.bzl", "rust_library") - -package(default_visibility = ["//visibility:public"]) - -cargo_toml_env_vars( - name = "cargo_toml_env_vars", - src = "Cargo.toml", -) - -rust_library( - name = "tikv_jemalloc_sys", - srcs = glob( - include = ["**/*.rs"], - allow_empty = True, - ), - compile_data = glob( - include = ["**"], - allow_empty = True, - exclude = [ - "**/* *", - ".tmp_git_root/**/*", - "BUILD", - "BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - ], - ), - crate_features = [ - "background_threads_runtime_support", - ], - crate_root = "src/lib.rs", - edition = "2018", - rustc_env_files = [ - ":cargo_toml_env_vars", - ], - rustc_flags = [ - "--cap-lints=allow", - "--cfg=prefixed", - ], - tags = [ - "cargo-bazel", - "crate-name=tikv-jemalloc-sys", - "manual", - "noclippy", - "norustfmt", - ], - target_compatible_with = select({ - "@rules_rust//rust/platform:aarch64-apple-darwin": [], - "@rules_rust//rust/platform:aarch64-apple-ios": [], - "@rules_rust//rust/platform:aarch64-apple-ios-macabi": [], - "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], - "@rules_rust//rust/platform:aarch64-linux-android": [], - "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], - "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], - "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-none": [], - "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], - "@rules_rust//rust/platform:aarch64-unknown-uefi": [], - "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:arm-unknown-linux-musleabi": [], - "@rules_rust//rust/platform:armv7-linux-androideabi": [], - "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:i686-apple-darwin": [], - "@rules_rust//rust/platform:i686-linux-android": [], - "@rules_rust//rust/platform:i686-pc-windows-msvc": [], - "@rules_rust//rust/platform:i686-unknown-freebsd": [], - "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], - "@rules_rust//rust/platform:loongarch64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:mips-unknown-linux-gnu": [], - "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], - "@rules_rust//rust/platform:riscv32imac-unknown-none-elf": [], - "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], - "@rules_rust//rust/platform:riscv64gc-unknown-fuchsia": [], - "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], - "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], - "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], - "@rules_rust//rust/platform:sparc64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:sparc64-unknown-netbsd": [], - "@rules_rust//rust/platform:sparc64-unknown-openbsd": [], - "@rules_rust//rust/platform:thumbv6m-none-eabi": [], - "@rules_rust//rust/platform:thumbv7em-none-eabi": [], - "@rules_rust//rust/platform:thumbv7em-none-eabihf": [], - "@rules_rust//rust/platform:thumbv7m-none-eabi": [], - "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], - "@rules_rust//rust/platform:thumbv8m.main-none-eabihf": [], - "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], - "@rules_rust//rust/platform:wasm32-unknown-unknown": [], - "@rules_rust//rust/platform:wasm32-wasip1": [], - "@rules_rust//rust/platform:wasm32-wasip1-threads": [], - "@rules_rust//rust/platform:wasm32-wasip2": [], - "@rules_rust//rust/platform:x86_64-apple-darwin": [], - "@rules_rust//rust/platform:x86_64-apple-ios": [], - "@rules_rust//rust/platform:x86_64-apple-ios-macabi": [], - "@rules_rust//rust/platform:x86_64-linux-android": [], - "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], - "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], - "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], - "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-none": [], - "@rules_rust//rust/platform:x86_64-unknown-uefi": [], - "//conditions:default": ["@platforms//:incompatible"], - }), - version = "0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8", - deps = [ - "@codeql//misc/bazel/3rdparty:jemalloc", - "@vendor_rs__libc-0.2.189//:libc", - ], -) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemallocator-0.7.0.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemallocator-0.7.0.bazel deleted file mode 100644 index 76bd13b125eb..000000000000 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.tikv-jemallocator-0.7.0.bazel +++ /dev/null @@ -1,119 +0,0 @@ -############################################################################### -# @generated -# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To -# regenerate this file, run the following: -# -# bazel run @@//misc/bazel/3rdparty:vendor_rust_workspace_deps -############################################################################### - -load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") -load("@rules_rust//rust:defs.bzl", "rust_library") - -package(default_visibility = ["//visibility:public"]) - -cargo_toml_env_vars( - name = "cargo_toml_env_vars", - src = "Cargo.toml", -) - -rust_library( - name = "tikv_jemallocator", - srcs = glob( - include = ["**/*.rs"], - allow_empty = True, - ), - compile_data = glob( - include = ["**"], - allow_empty = True, - exclude = [ - "**/* *", - ".tmp_git_root/**/*", - "BUILD", - "BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - ], - ), - crate_features = [ - "background_threads_runtime_support", - "default", - ], - crate_root = "src/lib.rs", - edition = "2018", - rustc_env_files = [ - ":cargo_toml_env_vars", - ], - rustc_flags = [ - "--cap-lints=allow", - ], - tags = [ - "cargo-bazel", - "crate-name=tikv-jemallocator", - "manual", - "noclippy", - "norustfmt", - ], - target_compatible_with = select({ - "@rules_rust//rust/platform:aarch64-apple-darwin": [], - "@rules_rust//rust/platform:aarch64-apple-ios": [], - "@rules_rust//rust/platform:aarch64-apple-ios-macabi": [], - "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], - "@rules_rust//rust/platform:aarch64-linux-android": [], - "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], - "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], - "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:aarch64-unknown-none": [], - "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], - "@rules_rust//rust/platform:aarch64-unknown-uefi": [], - "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:arm-unknown-linux-musleabi": [], - "@rules_rust//rust/platform:armv7-linux-androideabi": [], - "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], - "@rules_rust//rust/platform:i686-apple-darwin": [], - "@rules_rust//rust/platform:i686-linux-android": [], - "@rules_rust//rust/platform:i686-pc-windows-msvc": [], - "@rules_rust//rust/platform:i686-unknown-freebsd": [], - "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], - "@rules_rust//rust/platform:loongarch64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:mips-unknown-linux-gnu": [], - "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], - "@rules_rust//rust/platform:riscv32imac-unknown-none-elf": [], - "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], - "@rules_rust//rust/platform:riscv64gc-unknown-fuchsia": [], - "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], - "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], - "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], - "@rules_rust//rust/platform:sparc64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:sparc64-unknown-netbsd": [], - "@rules_rust//rust/platform:sparc64-unknown-openbsd": [], - "@rules_rust//rust/platform:thumbv6m-none-eabi": [], - "@rules_rust//rust/platform:thumbv7em-none-eabi": [], - "@rules_rust//rust/platform:thumbv7em-none-eabihf": [], - "@rules_rust//rust/platform:thumbv7m-none-eabi": [], - "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], - "@rules_rust//rust/platform:thumbv8m.main-none-eabihf": [], - "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], - "@rules_rust//rust/platform:wasm32-unknown-unknown": [], - "@rules_rust//rust/platform:wasm32-wasip1": [], - "@rules_rust//rust/platform:wasm32-wasip1-threads": [], - "@rules_rust//rust/platform:wasm32-wasip2": [], - "@rules_rust//rust/platform:x86_64-apple-darwin": [], - "@rules_rust//rust/platform:x86_64-apple-ios": [], - "@rules_rust//rust/platform:x86_64-apple-ios-macabi": [], - "@rules_rust//rust/platform:x86_64-linux-android": [], - "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], - "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], - "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], - "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], - "@rules_rust//rust/platform:x86_64-unknown-none": [], - "@rules_rust//rust/platform:x86_64-unknown-uefi": [], - "//conditions:default": ["@platforms//:incompatible"], - }), - version = "0.7.0", - deps = [ - "@vendor_rs__libc-0.2.189//:libc", - "@vendor_rs__tikv-jemalloc-sys-0.7.1-5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8//:tikv_jemalloc_sys", - ], -) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.winapi-util-0.1.11.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.winapi-util-0.1.11.bazel index 6dc9da37431d..b1c2a799a889 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.winapi-util-0.1.11.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.winapi-util-0.1.11.bazel @@ -110,13 +110,13 @@ rust_library( version = "0.1.11", deps = select({ "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:i686-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [ - "@vendor_rs__windows-sys-0.61.2//:windows_sys", # cfg(windows) + "@vendor_rs__windows-sys-0.60.2//:windows_sys", # cfg(windows) ], "//conditions:default": [], }), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.60.2.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.60.2.bazel index d0c8f9764fd0..7e3a6c212fa5 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.60.2.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.60.2.bazel @@ -37,11 +37,16 @@ rust_library( crate_features = [ "Win32", "Win32_Foundation", + "Win32_Networking", + "Win32_Networking_WinSock", "Win32_Security", "Win32_Storage", "Win32_Storage_FileSystem", "Win32_System", + "Win32_System_Console", "Win32_System_IO", + "Win32_System_Pipes", + "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_System_WindowsProgramming", "default", diff --git a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.61.2.bazel b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.61.2.bazel index 468b10a4139c..d4350c80f031 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.61.2.bazel +++ b/misc/bazel/3rdparty/rust_workspace_deps/BUILD.windows-sys-0.61.2.bazel @@ -37,17 +37,8 @@ rust_library( crate_features = [ "Win32", "Win32_Foundation", - "Win32_Networking", - "Win32_Networking_WinSock", - "Win32_Security", - "Win32_Storage", - "Win32_Storage_FileSystem", "Win32_System", - "Win32_System_Console", - "Win32_System_IO", - "Win32_System_Pipes", "Win32_System_ProcessStatus", - "Win32_System_SystemInformation", "Win32_System_Threading", "default", ], diff --git a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl index 85a5b1c4d4b8..8216914f89b6 100644 --- a/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl +++ b/misc/bazel/3rdparty/rust_workspace_deps/crates.bzl @@ -388,9 +388,6 @@ _NORMAL_DEPENDENCIES = { "tree-sitter-ql": Label("@vendor_rs//tree-sitter-ql-0.23.1"), "tree-sitter-ql-dbscheme": Label("@vendor_rs//tree-sitter-ql-dbscheme-0.23.0"), }, - "cfg(not(windows))": { - "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), - }, }, "ruby/extractor": { _COMMON_CONDITION: { @@ -405,9 +402,6 @@ _NORMAL_DEPENDENCIES = { "tree-sitter-embedded-template": Label("@vendor_rs//tree-sitter-embedded-template-0.25.0"), "tree-sitter-ruby": Label("@vendor_rs//tree-sitter-ruby-0.23.1"), }, - "cfg(not(windows))": { - "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), - }, }, "rust/ast-generator": { _COMMON_CONDITION: { @@ -460,9 +454,6 @@ _NORMAL_DEPENDENCIES = { "tracing-subscriber": Label("@vendor_rs//tracing-subscriber-0.3.23"), "triomphe": Label("@vendor_rs//triomphe-0.1.17"), }, - "cfg(not(windows))": { - "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), - }, }, "shared/extractor-common": { }, @@ -517,9 +508,6 @@ _NORMAL_DEPENDENCIES = { "tracing": Label("@vendor_rs//tracing-0.1.44"), "tracing-subscriber": Label("@vendor_rs//tracing-subscriber-0.3.23"), }, - "cfg(not(windows))": { - "tikv-jemallocator": Label("@vendor_rs//tikv-jemallocator-0.7.0"), - }, }, "unified/extractor-unsupported-os": { }, @@ -547,14 +535,10 @@ _NORMAL_ALIASES = { "ql/extractor": { _COMMON_CONDITION: { }, - "cfg(not(windows))": { - }, }, "ruby/extractor": { _COMMON_CONDITION: { }, - "cfg(not(windows))": { - }, }, "rust/ast-generator": { _COMMON_CONDITION: { @@ -566,8 +550,6 @@ _NORMAL_ALIASES = { "rust/extractor": { _COMMON_CONDITION: { }, - "cfg(not(windows))": { - }, }, "shared/extractor-common": { }, @@ -590,8 +572,6 @@ _NORMAL_ALIASES = { "unified/extractor": { _COMMON_CONDITION: { }, - "cfg(not(windows))": { - }, }, "unified/extractor-unsupported-os": { }, @@ -3814,26 +3794,6 @@ def crate_repositories(): build_file = Label("//misc/bazel/3rdparty/rust_workspace_deps:BUILD.thread_local-1.1.10.bazel"), ) - maybe( - http_archive, - name = "vendor_rs__tikv-jemalloc-sys-0.7.1-5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8", - sha256 = "1a2825c78386b4ae0314074867860ba9577875de945f05992c38815cbec327f0", - type = "tar.gz", - urls = ["https://static.crates.io/crates/tikv-jemalloc-sys/0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/download"], - strip_prefix = "tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8", - build_file = Label("//misc/bazel/3rdparty/rust_workspace_deps:BUILD.tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8.bazel"), - ) - - maybe( - http_archive, - name = "vendor_rs__tikv-jemallocator-0.7.0", - sha256 = "249f09e49ab1609436f34c776e84231bead18d6a955f119f939bdc1d847561bd", - type = "tar.gz", - urls = ["https://static.crates.io/crates/tikv-jemallocator/0.7.0/download"], - strip_prefix = "tikv-jemallocator-0.7.0", - build_file = Label("//misc/bazel/3rdparty/rust_workspace_deps:BUILD.tikv-jemallocator-0.7.0.bazel"), - ) - maybe( http_archive, name = "vendor_rs__time-0.3.55", @@ -4631,7 +4591,6 @@ def crate_repositories(): struct(repo = "vendor_rs__serde_yaml-0.9.34-deprecated", is_dev_dep = False), struct(repo = "vendor_rs__syn-3.0.9", is_dev_dep = False), struct(repo = "vendor_rs__tempfile-3.27.0", is_dev_dep = False), - struct(repo = "vendor_rs__tikv-jemallocator-0.7.0", is_dev_dep = False), struct(repo = "vendor_rs__toml-1.1.8-spec-1.1.0", is_dev_dep = False), struct(repo = "vendor_rs__tracing-0.1.44", is_dev_dep = False), struct(repo = "vendor_rs__tracing-flame-0.2.0", is_dev_dep = False), diff --git a/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator-0.7.0/BUILD.bazel b/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator-0.7.0/BUILD.bazel deleted file mode 100644 index 4dc2adbe6c8c..000000000000 --- a/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator-0.7.0/BUILD.bazel +++ /dev/null @@ -1,15 +0,0 @@ -############################################################################### -# @generated -# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To -# regenerate this file, run the following: -# -# bazel run @@//misc/bazel/3rdparty:vendor_rust_workspace_deps -############################################################################### - -package(default_visibility = ["//visibility:public"]) - -alias( - name = "tikv-jemallocator-0.7.0", - actual = "@vendor_rs__tikv-jemallocator-0.7.0//:tikv_jemallocator", - tags = ["manual"], -) diff --git a/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator/BUILD.bazel b/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator/BUILD.bazel deleted file mode 100644 index 9ca1b57bc465..000000000000 --- a/misc/bazel/3rdparty/rust_workspace_deps/tikv-jemallocator/BUILD.bazel +++ /dev/null @@ -1,15 +0,0 @@ -############################################################################### -# @generated -# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To -# regenerate this file, run the following: -# -# bazel run @@//misc/bazel/3rdparty:vendor_rust_workspace_deps -############################################################################### - -package(default_visibility = ["//visibility:public"]) - -alias( - name = "tikv-jemallocator", - actual = "@vendor_rs__tikv-jemallocator-0.7.0//:tikv_jemallocator", - tags = ["manual"], -) diff --git a/misc/bazel/global_allocator/BUILD.bazel b/misc/bazel/global_allocator/BUILD.bazel deleted file mode 100644 index ea440f22a4f8..000000000000 --- a/misc/bazel/global_allocator/BUILD.bazel +++ /dev/null @@ -1,21 +0,0 @@ -load("@rules_rust//rust:defs.bzl", "rust_library") - -# buildifier: disable=bzl-visibility -load("@rules_rust//rust/private:rust_allocator_libraries.bzl", "rust_allocator_libraries") - -# Allocator shim for binaries defining a `#[global_allocator]`, see `codeql_rust_binary`. It is only used when linking with `cc_common` and mangled allocator symbols, -# where the default shim would clash with the `__rust_alloc*` symbols emitted for the global -# allocator. The upstream `experimental_use_global_allocator` setting cannot be used instead, as it -# is toolchain-wide and its shim lags behind current nightly rustc. -rust_allocator_libraries( - name = "global_allocator", - allocator_library = ":shim", - visibility = ["//visibility:public"], -) - -rust_library( - name = "shim", - srcs = ["shim.rs"], - allocator_libraries = "@rules_rust//ffi/rs:empty_allocator_libraries", - edition = "2024", -) diff --git a/misc/bazel/jemalloc/BUILD.bazel b/misc/bazel/jemalloc/BUILD.bazel new file mode 100644 index 000000000000..a7bbadbbbf2a --- /dev/null +++ b/misc/bazel/jemalloc/BUILD.bazel @@ -0,0 +1,49 @@ +load("@jemalloc//settings:config.bzl", "jemalloc") +load("@rules_rust//rust:defs.bzl", "rust_library") + +# buildifier: disable=bzl-visibility +load("@rules_rust//rust/private:rust_allocator_libraries.bzl", "rust_allocator_libraries") +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") + +# jemalloc as Rust `#[global_allocator]`, see `codeql_rust_binary`. +rust_library( + name = "jemalloc", + srcs = ["lib.rs"], + crate_name = "codeql_jemalloc", + edition = "2024", + visibility = ["//visibility:public"], + deps = [":jemalloc_c"], +) + +# Prefixed, and not registered as the macOS default malloc zone, so it never replaces the process-wide `malloc`. +jemalloc( + name = "jemalloc_c", + cxx = "False", + jemalloc_prefix = "_rjem_", + stats = "False", + zone_allocator = "no", +) + +# Allocator shim for binaries defining a `#[global_allocator]`. It is only used when linking with `cc_common` and +# mangled allocator symbols, where the default shim would clash with the `__rust_alloc*` symbols emitted for the +# global allocator. The upstream `experimental_use_global_allocator` setting cannot be used instead, as it is +# toolchain-wide and its shim lags behind current nightly rustc. +rust_allocator_libraries( + name = "allocator_libraries", + allocator_library = ":shim", + visibility = ["//visibility:public"], +) + +rust_library( + name = "shim", + srcs = ["shim.rs"], + allocator_libraries = "@rules_rust//ffi/rs:empty_allocator_libraries", + edition = "2024", +) + +# The macOS C++ toolchain declares no `nm`, which jemalloc needs to generate its private namespace header. +# Selected in `.bazelrc` via `@jemalloc//settings/flags:nm`. +sh_binary( + name = "xcrun_nm", + srcs = ["xcrun_nm.sh"], +) diff --git a/misc/bazel/jemalloc/lib.rs b/misc/bazel/jemalloc/lib.rs new file mode 100644 index 000000000000..965918bc500c --- /dev/null +++ b/misc/bazel/jemalloc/lib.rs @@ -0,0 +1,72 @@ +//! `GlobalAlloc` over the `_rjem_`-prefixed jemalloc, as in `tikv-jemallocator`. + +use std::alloc::{GlobalAlloc, Layout}; +use std::ffi::{c_int, c_void}; + +unsafe extern "C" { + #[link_name = "_rjem_malloc"] + pub fn malloc(size: usize) -> *mut c_void; + #[link_name = "_rjem_calloc"] + pub fn calloc(count: usize, size: usize) -> *mut c_void; + #[link_name = "_rjem_realloc"] + pub fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void; + #[link_name = "_rjem_free"] + pub fn free(ptr: *mut c_void); + #[link_name = "_rjem_mallocx"] + fn mallocx(size: usize, flags: c_int) -> *mut c_void; + #[link_name = "_rjem_rallocx"] + fn rallocx(ptr: *mut c_void, size: usize, flags: c_int) -> *mut c_void; + #[link_name = "_rjem_sdallocx"] + fn sdallocx(ptr: *mut c_void, size: usize, flags: c_int); +} + +// Alignment guaranteed by plain `malloc` on the supported 64-bit targets. +const MIN_ALIGN: usize = 16; +const MALLOCX_ZERO: c_int = 0x40; + +/// `MALLOCX_LG_ALIGN` flags, or 0 if plain `malloc` already satisfies the alignment. +#[inline] +fn flags(layout: &Layout) -> c_int { + if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { + 0 + } else { + layout.align().trailing_zeros() as c_int + } +} + +pub struct Jemalloc; + +// `#[inline]` also places the `_rjem_*` references in the binary's own objects, which rules_rust links ahead of the +// jemalloc archive. + +// SAFETY: jemalloc honours the requested size and alignment, and `dealloc`/`realloc` get the original layout. +unsafe impl GlobalAlloc for Jemalloc { + #[inline] + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + match flags(&layout) { + 0 => unsafe { malloc(layout.size()) }.cast(), + f => unsafe { mallocx(layout.size(), f) }.cast(), + } + } + + #[inline] + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + match flags(&layout) { + 0 => unsafe { calloc(1, layout.size()) }.cast(), + f => unsafe { mallocx(layout.size(), f | MALLOCX_ZERO) }.cast(), + } + } + + #[inline] + unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + unsafe { sdallocx(ptr.cast(), layout.size(), flags(&layout)) } + } + + #[inline] + unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + match flags(&layout) { + 0 => unsafe { realloc(ptr.cast(), new_size) }.cast(), + f => unsafe { rallocx(ptr.cast(), new_size, f) }.cast(), + } + } +} diff --git a/misc/bazel/global_allocator/shim.rs b/misc/bazel/jemalloc/shim.rs similarity index 100% rename from misc/bazel/global_allocator/shim.rs rename to misc/bazel/jemalloc/shim.rs diff --git a/misc/bazel/3rdparty/xcrun_nm.sh b/misc/bazel/jemalloc/xcrun_nm.sh similarity index 100% rename from misc/bazel/3rdparty/xcrun_nm.sh rename to misc/bazel/jemalloc/xcrun_nm.sh diff --git a/misc/bazel/rust.bzl b/misc/bazel/rust.bzl index 63c3809d2a0d..6396a109d6f7 100644 --- a/misc/bazel/rust.bzl +++ b/misc/bazel/rust.bzl @@ -1,17 +1,17 @@ load("@rules_rust//rust:defs.bzl", "rust_binary") load("@semmle_code//buildutils-internal:glibc_symbols_check.bzl", "glibc_symbols_check") load("@semmle_code//buildutils-internal:lipo.bzl", "universal_binary") -load("//misc/bazel:os.bzl", "os_select") def codeql_rust_binary( name, target_compatible_with = None, visibility = None, symbols_test = True, - global_allocator = False, + jemalloc = False, **kwargs): """ - `global_allocator` must be set when the crate defines a `#[global_allocator]` on non-Windows targets. + `jemalloc` adds a `codeql_jemalloc` dependency and sets `--cfg=codeql_jemalloc`, under which the crate must use + `codeql_jemalloc::Jemalloc` as `#[global_allocator]`. Cargo builds keep the system allocator. """ rust_label_name = "single_arch/" + name universal_binary( @@ -20,11 +20,10 @@ def codeql_rust_binary( target_compatible_with = target_compatible_with, visibility = visibility, ) - if global_allocator: - kwargs["allocator_libraries"] = os_select( - posix = Label("//misc/bazel/global_allocator"), - windows = "@rules_rust//ffi/rs:default_allocator_libraries", - ) + if jemalloc: + kwargs["rustc_flags"] = kwargs.get("rustc_flags", []) + ["--cfg=codeql_jemalloc"] + kwargs["deps"] = kwargs.get("deps", []) + [Label("//misc/bazel/jemalloc")] + kwargs["allocator_libraries"] = Label("//misc/bazel/jemalloc:allocator_libraries") rust_binary( name = rust_label_name, **kwargs diff --git a/ql/extractor/Cargo.toml b/ql/extractor/Cargo.toml index d1eb44e8fc8b..8f68f9331741 100644 --- a/ql/extractor/Cargo.toml +++ b/ql/extractor/Cargo.toml @@ -21,6 +21,3 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } rayon = "1.9.0" regex = "1.10.4" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } - -[target.'cfg(not(windows))'.dependencies] -tikv-jemallocator = "0.7.0" diff --git a/ql/extractor/src/main.rs b/ql/extractor/src/main.rs index e07a4068ca15..e6721d4e2243 100644 --- a/ql/extractor/src/main.rs +++ b/ql/extractor/src/main.rs @@ -4,31 +4,6 @@ mod autobuilder; mod extractor; mod generator; -#[cfg(not(windows))] -#[global_allocator] -static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; - -/// Routes tree-sitter's C allocations to the same (prefixed) jemalloc as Rust allocations. -#[cfg(not(windows))] -fn use_jemalloc_for_tree_sitter() { - use std::ffi::c_void; - unsafe extern "C" { - fn _rjem_malloc(size: usize) -> *mut c_void; - fn _rjem_calloc(count: usize, size: usize) -> *mut c_void; - fn _rjem_realloc(ptr: *mut c_void, size: usize) -> *mut c_void; - fn _rjem_free(ptr: *mut c_void); - } - // SAFETY: called first thing in `main`, before tree-sitter allocates anything. - unsafe { - tree_sitter::set_allocator( - Some(_rjem_malloc), - Some(_rjem_calloc), - Some(_rjem_realloc), - Some(_rjem_free), - ); - } -} - #[derive(Parser)] #[command(author, version, about)] enum Cli { @@ -38,8 +13,6 @@ enum Cli { } fn main() -> std::io::Result<()> { - #[cfg(not(windows))] - use_jemalloc_for_tree_sitter(); let cli = Cli::parse(); match cli { diff --git a/ruby/extractor/BUILD.bazel b/ruby/extractor/BUILD.bazel index 7d0f152f77fe..40186b78a20e 100644 --- a/ruby/extractor/BUILD.bazel +++ b/ruby/extractor/BUILD.bazel @@ -7,7 +7,7 @@ codeql_rust_binary( name = "extractor", srcs = glob(["src/*.rs"]), aliases = aliases(), - global_allocator = True, + jemalloc = True, proc_macro_deps = all_crate_deps( proc_macro = True, ), diff --git a/ruby/extractor/Cargo.toml b/ruby/extractor/Cargo.toml index 6c9d9db887cf..e9b8af450b5c 100644 --- a/ruby/extractor/Cargo.toml +++ b/ruby/extractor/Cargo.toml @@ -23,6 +23,3 @@ serde_json = "1.0.154" codeql-extractor = { path = "../../shared/tree-sitter-extractor" } extractor-common = { path = "../../shared/extractor-common" } - -[target.'cfg(not(windows))'.dependencies] -tikv-jemallocator = "0.7.0" diff --git a/ruby/extractor/src/main.rs b/ruby/extractor/src/main.rs index e7c46fb35326..02069bfaad78 100644 --- a/ruby/extractor/src/main.rs +++ b/ruby/extractor/src/main.rs @@ -4,27 +4,20 @@ mod autobuilder; mod extractor; mod generator; -#[cfg(not(windows))] +#[cfg(codeql_jemalloc)] #[global_allocator] -static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; +static GLOBAL: codeql_jemalloc::Jemalloc = codeql_jemalloc::Jemalloc; /// Routes tree-sitter's C allocations to the same (prefixed) jemalloc as Rust allocations. -#[cfg(not(windows))] +#[cfg(codeql_jemalloc)] fn use_jemalloc_for_tree_sitter() { - use std::ffi::c_void; - unsafe extern "C" { - fn _rjem_malloc(size: usize) -> *mut c_void; - fn _rjem_calloc(count: usize, size: usize) -> *mut c_void; - fn _rjem_realloc(ptr: *mut c_void, size: usize) -> *mut c_void; - fn _rjem_free(ptr: *mut c_void); - } // SAFETY: called first thing in `main`, before tree-sitter allocates anything. unsafe { tree_sitter::set_allocator( - Some(_rjem_malloc), - Some(_rjem_calloc), - Some(_rjem_realloc), - Some(_rjem_free), + Some(codeql_jemalloc::malloc), + Some(codeql_jemalloc::calloc), + Some(codeql_jemalloc::realloc), + Some(codeql_jemalloc::free), ); } } @@ -38,7 +31,7 @@ enum Cli { } fn main() -> std::io::Result<()> { - #[cfg(not(windows))] + #[cfg(codeql_jemalloc)] use_jemalloc_for_tree_sitter(); let cli = Cli::parse(); diff --git a/rust/extractor/BUILD.bazel b/rust/extractor/BUILD.bazel index 9e421551da55..2de7e3687270 100644 --- a/rust/extractor/BUILD.bazel +++ b/rust/extractor/BUILD.bazel @@ -11,7 +11,7 @@ codeql_rust_binary( "src/qltest_cargo.mustache", "src/nightly-toolchain/rust-toolchain.toml", ], - global_allocator = True, + jemalloc = True, proc_macro_deps = all_crate_deps( proc_macro = True, ), diff --git a/rust/extractor/Cargo.toml b/rust/extractor/Cargo.toml index e4e8b0ba624a..f013fb07ea76 100644 --- a/rust/extractor/Cargo.toml +++ b/rust/extractor/Cargo.toml @@ -44,6 +44,3 @@ tracing = "0.1.44" tracing-flame = "0.2.0" tracing-subscriber = "0.3.23" mustache = "0.9.0" - -[target.'cfg(not(windows))'.dependencies] -tikv-jemallocator = "0.7.0" diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 548f89f04123..19b49702469c 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -37,9 +37,9 @@ mod translate; pub mod trap; mod util; -#[cfg(not(windows))] +#[cfg(codeql_jemalloc)] #[global_allocator] -static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; +static GLOBAL: codeql_jemalloc::Jemalloc = codeql_jemalloc::Jemalloc; struct Extractor<'a> { archiver: &'a Archiver, diff --git a/unified/extractor/BUILD.bazel b/unified/extractor/BUILD.bazel index 15c482305a37..006d334d77c8 100644 --- a/unified/extractor/BUILD.bazel +++ b/unified/extractor/BUILD.bazel @@ -15,7 +15,7 @@ codeql_rust_binary( "swift_node_types.yml", ], data = ["//unified/swift-syntax-rs:swift_runtime"], - global_allocator = True, + jemalloc = True, proc_macro_deps = all_crate_deps( proc_macro = True, ), diff --git a/unified/extractor/Cargo.toml b/unified/extractor/Cargo.toml index 65ccfab67c2a..6843d3e6d7bd 100644 --- a/unified/extractor/Cargo.toml +++ b/unified/extractor/Cargo.toml @@ -21,6 +21,3 @@ serde_json = { version = "1.0.154", features = ["unbounded_depth"] } codeql-extractor = { path = "../../shared/tree-sitter-extractor" } yeast = { path = "../../shared/yeast" } swift-syntax-rs = { path = "../swift-syntax-rs" } - -[target.'cfg(not(windows))'.dependencies] -tikv-jemallocator = "0.7.0" diff --git a/unified/extractor/src/main.rs b/unified/extractor/src/main.rs index 92895a0f0144..02b0ce33fd26 100644 --- a/unified/extractor/src/main.rs +++ b/unified/extractor/src/main.rs @@ -5,13 +5,13 @@ mod extractor; mod generator; mod languages; -#[cfg(not(windows))] +#[cfg(codeql_jemalloc)] #[global_allocator] -static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; +static GLOBAL: codeql_jemalloc::Jemalloc = codeql_jemalloc::Jemalloc; // With jemalloc's default per-thread arenas, peak RSS was ~60% above the system allocator here; // a single arena brings it below that at no measured CPU cost. -#[cfg(not(windows))] +#[cfg(codeql_jemalloc)] #[unsafe(export_name = "_rjem_malloc_conf")] static MALLOC_CONF: &[u8; 10] = b"narenas:1\0"; From 62f3db28d1265f7c71fa4d0e41964d0527a5381f Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 3 Dec 2026 09:23:08 +0000 Subject: [PATCH 09/12] Shared: Use the new size for jemalloc realloc flags Shrinking a block below its alignment otherwise picks plain `realloc`, which may return a pointer aligned only to the smaller size class. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- misc/bazel/jemalloc/BUILD.bazel | 7 +++++- misc/bazel/jemalloc/lib.rs | 38 +++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/misc/bazel/jemalloc/BUILD.bazel b/misc/bazel/jemalloc/BUILD.bazel index a7bbadbbbf2a..9361fbdd13f8 100644 --- a/misc/bazel/jemalloc/BUILD.bazel +++ b/misc/bazel/jemalloc/BUILD.bazel @@ -1,5 +1,5 @@ load("@jemalloc//settings:config.bzl", "jemalloc") -load("@rules_rust//rust:defs.bzl", "rust_library") +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") # buildifier: disable=bzl-visibility load("@rules_rust//rust/private:rust_allocator_libraries.bzl", "rust_allocator_libraries") @@ -15,6 +15,11 @@ rust_library( deps = [":jemalloc_c"], ) +rust_test( + name = "jemalloc_test", + crate = ":jemalloc", +) + # Prefixed, and not registered as the macOS default malloc zone, so it never replaces the process-wide `malloc`. jemalloc( name = "jemalloc_c", diff --git a/misc/bazel/jemalloc/lib.rs b/misc/bazel/jemalloc/lib.rs index 965918bc500c..79e4e0632f70 100644 --- a/misc/bazel/jemalloc/lib.rs +++ b/misc/bazel/jemalloc/lib.rs @@ -26,11 +26,11 @@ const MALLOCX_ZERO: c_int = 0x40; /// `MALLOCX_LG_ALIGN` flags, or 0 if plain `malloc` already satisfies the alignment. #[inline] -fn flags(layout: &Layout) -> c_int { - if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { +fn flags(align: usize, size: usize) -> c_int { + if align <= MIN_ALIGN && align <= size { 0 } else { - layout.align().trailing_zeros() as c_int + align.trailing_zeros() as c_int } } @@ -43,7 +43,7 @@ pub struct Jemalloc; unsafe impl GlobalAlloc for Jemalloc { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - match flags(&layout) { + match flags(layout.align(), layout.size()) { 0 => unsafe { malloc(layout.size()) }.cast(), f => unsafe { mallocx(layout.size(), f) }.cast(), } @@ -51,7 +51,7 @@ unsafe impl GlobalAlloc for Jemalloc { #[inline] unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - match flags(&layout) { + match flags(layout.align(), layout.size()) { 0 => unsafe { calloc(1, layout.size()) }.cast(), f => unsafe { mallocx(layout.size(), f | MALLOCX_ZERO) }.cast(), } @@ -59,14 +59,38 @@ unsafe impl GlobalAlloc for Jemalloc { #[inline] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - unsafe { sdallocx(ptr.cast(), layout.size(), flags(&layout)) } + unsafe { sdallocx(ptr.cast(), layout.size(), flags(layout.align(), layout.size())) } } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - match flags(&layout) { + match flags(layout.align(), new_size) { 0 => unsafe { realloc(ptr.cast(), new_size) }.cast(), f => unsafe { rallocx(ptr.cast(), new_size, f) }.cast(), } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn realloc_keeps_alignment_when_shrinking() { + let layout = Layout::from_size_align(32, 16).unwrap(); + let ptrs: Vec<_> = (0..=255u8).cycle().take(1000) + .map(|i| unsafe { + let p = Jemalloc.alloc(layout); + p.write_bytes(i, layout.size()); + let p = Jemalloc.realloc(p, layout, 8); + assert_eq!(p as usize % layout.align(), 0, "misaligned after shrink"); + assert!(std::slice::from_raw_parts(p, 8).iter().all(|&b| b == i)); + p + }) + .collect(); + let shrunk = Layout::from_size_align(8, 16).unwrap(); + for p in ptrs { + unsafe { Jemalloc.dealloc(p, shrunk) }; + } + } +} From 96302b5b5ca2fe84261dc04552743f93242f1a52 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 3 Dec 2026 10:52:54 +0000 Subject: [PATCH 10/12] Shared: Abort on OOM in jemalloc's C functions, test more layouts tree-sitter's default allocators abort when out of memory, but custom ones replace them outright. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- misc/bazel/jemalloc/lib.rs | 121 +++++++++++++++++++++++++++++++------ 1 file changed, 103 insertions(+), 18 deletions(-) diff --git a/misc/bazel/jemalloc/lib.rs b/misc/bazel/jemalloc/lib.rs index 79e4e0632f70..3433c732844a 100644 --- a/misc/bazel/jemalloc/lib.rs +++ b/misc/bazel/jemalloc/lib.rs @@ -5,11 +5,11 @@ use std::ffi::{c_int, c_void}; unsafe extern "C" { #[link_name = "_rjem_malloc"] - pub fn malloc(size: usize) -> *mut c_void; + fn je_malloc(size: usize) -> *mut c_void; #[link_name = "_rjem_calloc"] - pub fn calloc(count: usize, size: usize) -> *mut c_void; + fn je_calloc(count: usize, size: usize) -> *mut c_void; #[link_name = "_rjem_realloc"] - pub fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void; + fn je_realloc(ptr: *mut c_void, size: usize) -> *mut c_void; #[link_name = "_rjem_free"] pub fn free(ptr: *mut c_void); #[link_name = "_rjem_mallocx"] @@ -34,6 +34,38 @@ fn flags(align: usize, size: usize) -> c_int { } } +// C allocation functions for C libraries (`tree_sitter::set_allocator`). Like tree-sitter's defaults, they abort +// rather than return null when out of memory. + +fn check(ptr: *mut c_void, size: usize) -> *mut c_void { + if ptr.is_null() && size > 0 { + eprintln!("jemalloc failed to allocate {size} bytes"); + std::process::abort(); + } + ptr +} + +/// # Safety +/// As C `malloc`. +pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { + check(unsafe { je_malloc(size) }, size) +} + +/// # Safety +/// As C `calloc`. +pub unsafe extern "C" fn calloc(count: usize, size: usize) -> *mut c_void { + check( + unsafe { je_calloc(count, size) }, + count.saturating_mul(size), + ) +} + +/// # Safety +/// As C `realloc`. +pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void { + check(unsafe { je_realloc(ptr, size) }, size) +} + pub struct Jemalloc; // `#[inline]` also places the `_rjem_*` references in the binary's own objects, which rules_rust links ahead of the @@ -44,7 +76,7 @@ unsafe impl GlobalAlloc for Jemalloc { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { match flags(layout.align(), layout.size()) { - 0 => unsafe { malloc(layout.size()) }.cast(), + 0 => unsafe { je_malloc(layout.size()) }.cast(), f => unsafe { mallocx(layout.size(), f) }.cast(), } } @@ -52,20 +84,26 @@ unsafe impl GlobalAlloc for Jemalloc { #[inline] unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { match flags(layout.align(), layout.size()) { - 0 => unsafe { calloc(1, layout.size()) }.cast(), + 0 => unsafe { je_calloc(1, layout.size()) }.cast(), f => unsafe { mallocx(layout.size(), f | MALLOCX_ZERO) }.cast(), } } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - unsafe { sdallocx(ptr.cast(), layout.size(), flags(layout.align(), layout.size())) } + unsafe { + sdallocx( + ptr.cast(), + layout.size(), + flags(layout.align(), layout.size()), + ) + } } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { match flags(layout.align(), new_size) { - 0 => unsafe { realloc(ptr.cast(), new_size) }.cast(), + 0 => unsafe { je_realloc(ptr.cast(), new_size) }.cast(), f => unsafe { rallocx(ptr.cast(), new_size, f) }.cast(), } } @@ -75,22 +113,69 @@ unsafe impl GlobalAlloc for Jemalloc { mod tests { use super::*; - #[test] - fn realloc_keeps_alignment_when_shrinking() { - let layout = Layout::from_size_align(32, 16).unwrap(); - let ptrs: Vec<_> = (0..=255u8).cycle().take(1000) + // Allocates many live blocks of `layout`, checking alignment, zeroing and contents through a realloc to `new_size`. + fn roundtrip(layout: Layout, new_size: usize) { + let new_layout = Layout::from_size_align(new_size, layout.align()).unwrap(); + let kept = layout.size().min(new_size); + let ptrs: Vec<_> = (0..1000) .map(|i| unsafe { - let p = Jemalloc.alloc(layout); - p.write_bytes(i, layout.size()); - let p = Jemalloc.realloc(p, layout, 8); - assert_eq!(p as usize % layout.align(), 0, "misaligned after shrink"); - assert!(std::slice::from_raw_parts(p, 8).iter().all(|&b| b == i)); + let p = if i % 2 == 0 { + Jemalloc.alloc(layout) + } else { + let p = Jemalloc.alloc_zeroed(layout); + assert!( + std::slice::from_raw_parts(p, layout.size()) + .iter() + .all(|&b| b == 0) + ); + p + }; + assert_eq!(p as usize % layout.align(), 0, "misaligned {layout:?}"); + p.write_bytes(i as u8, layout.size()); + let p = Jemalloc.realloc(p, layout, new_size); + assert_eq!( + p as usize % layout.align(), + 0, + "misaligned {layout:?} -> {new_size}" + ); + assert!( + std::slice::from_raw_parts(p, kept) + .iter() + .all(|&b| b == i as u8) + ); p }) .collect(); - let shrunk = Layout::from_size_align(8, 16).unwrap(); for p in ptrs { - unsafe { Jemalloc.dealloc(p, shrunk) }; + unsafe { Jemalloc.dealloc(p, new_layout) }; + } + } + + #[test] + fn ordinary_layouts() { + roundtrip(Layout::from_size_align(24, 8).unwrap(), 100); + roundtrip(Layout::from_size_align(100, 8).unwrap(), 24); + } + + #[test] + fn realloc_keeps_alignment_when_shrinking() { + roundtrip(Layout::from_size_align(32, 16).unwrap(), 8); + } + + #[test] + fn over_aligned_layouts() { + roundtrip(Layout::from_size_align(8, 64).unwrap(), 200); + roundtrip(Layout::from_size_align(5000, 4096).unwrap(), 16); + } + + #[test] + fn c_functions() { + unsafe { + let p = calloc(10, 10).cast::(); + assert!(std::slice::from_raw_parts(p, 100).iter().all(|&b| b == 0)); + let p = realloc(p.cast(), 1000); + free(p); + free(malloc(10)); } } } From a1e584ef3b41bc8aa8c7b0f2aa01bf246fde0bc3 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 3 Dec 2026 10:55:47 +0000 Subject: [PATCH 11/12] Shared: Test jemalloc's C functions abort on OOM Also match tree-sitter's `calloc` check, which only tests `count`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- misc/bazel/jemalloc/lib.rs | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/misc/bazel/jemalloc/lib.rs b/misc/bazel/jemalloc/lib.rs index 3433c732844a..61212350e009 100644 --- a/misc/bazel/jemalloc/lib.rs +++ b/misc/bazel/jemalloc/lib.rs @@ -37,9 +37,9 @@ fn flags(align: usize, size: usize) -> c_int { // C allocation functions for C libraries (`tree_sitter::set_allocator`). Like tree-sitter's defaults, they abort // rather than return null when out of memory. -fn check(ptr: *mut c_void, size: usize) -> *mut c_void { - if ptr.is_null() && size > 0 { - eprintln!("jemalloc failed to allocate {size} bytes"); +fn check(ptr: *mut c_void, count: usize) -> *mut c_void { + if ptr.is_null() && count > 0 { + eprintln!("jemalloc failed to allocate"); std::process::abort(); } ptr @@ -54,10 +54,7 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { /// # Safety /// As C `calloc`. pub unsafe extern "C" fn calloc(count: usize, size: usize) -> *mut c_void { - check( - unsafe { je_calloc(count, size) }, - count.saturating_mul(size), - ) + check(unsafe { je_calloc(count, size) }, count) } /// # Safety @@ -178,4 +175,43 @@ mod tests { free(malloc(10)); } } + + // Run by `c_functions_abort_on_oom` in a child process. + #[test] + fn oom_child() { + let Ok(f) = std::env::var("CODEQL_JEMALLOC_OOM") else { + return; + }; + let p = unsafe { + match f.as_str() { + "malloc" => malloc(usize::MAX), + "calloc" => calloc(usize::MAX, 2), + "realloc" => realloc(malloc(8), usize::MAX), + _ => unreachable!(), + } + }; + println!("returned {p:?}"); + } + + #[test] + fn c_functions_abort_on_oom() { + for f in ["malloc", "calloc", "realloc"] { + let out = std::process::Command::new(std::env::current_exe().unwrap()) + .args([ + "--exact", + "tests::oom_child", + "--nocapture", + "--test-threads=1", + ]) + .env("CODEQL_JEMALLOC_OOM", f) + .output() + .unwrap(); + let stderr = String::from_utf8_lossy(&out.stderr); + assert!(!out.status.success(), "{f} returned instead of aborting"); + assert!( + stderr.contains("jemalloc failed to allocate"), + "{f}: {stderr}" + ); + } + } } From 710a3da2205b2afc4c5762281e9977655d5874da Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 3 Dec 2026 11:03:26 +0000 Subject: [PATCH 12/12] Rust: Run the jemalloc allocator test in CI Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/rust.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 89d4d91f561c..e784d1063fac 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -63,6 +63,14 @@ jobs: - name: Compilation shell: bash run: cargo check + jemalloc: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v5 + - name: Test + shell: bash + run: bazel test //misc/bazel/jemalloc:jemalloc_test rust-codegen: runs-on: ubuntu-latest steps: