Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions ffi/rs/allocator_library/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
load("@rules_rust//rust:defs.bzl", "rust_library")
load("@rules_rust//rust:defs.bzl", "rust_static_library")

# buildifier: disable=bzl-visibility
load(
"@rules_rust//rust/private:rust.bzl",
"rust_library_without_process_wrapper",
"rust_static_library_without_process_wrapper",
)

package(
default_visibility = ["@rules_rust//ffi/rs:__subpackages__"],
)

srcs = select({
# Windows doesn't support weak symbol linkage.
# If someone can make this work on Windows, please do!
# For now we will silently not supply any symbols, because it would be very messy to conditionally define the default allocator library on toolchains depending on the platform.
"@platforms//os:windows": ["empty.rs"],
"//conditions:default": ["allocator_library.rs"],
})
# When building a staticlib crate, rustc injects the default allocator
# redirections (e.g., __rust_alloc -> __rdl_alloc).
# So we use an empty static library to provide these.

rust_library(
rust_static_library(
name = "allocator_library",
srcs = srcs,
srcs = ["empty.rs"],
allocator_libraries = "@rules_rust//ffi/rs:empty_allocator_libraries",
edition = "2024",
tags = ["manual"],
)

rust_library_without_process_wrapper(
rust_static_library_without_process_wrapper(
name = "allocator_library_without_process_wrapper",
srcs = srcs,
srcs = ["empty.rs"],
allocator_libraries = "@rules_rust//ffi/rs:empty_allocator_libraries",
edition = "2024",
tags = ["manual"],
Expand Down
98 changes: 0 additions & 98 deletions ffi/rs/allocator_library/allocator_library.rs

This file was deleted.

20 changes: 20 additions & 0 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,26 @@ rust_library_without_process_wrapper = rule(
],
)

def _rust_static_library_without_process_wrapper_impl(ctx):
providers = _rust_static_library_impl(ctx)
return providers + [_RustBuiltWithoutProcessWrapperInfo()]

rust_static_library_without_process_wrapper = rule(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need a change to account for #3790

implementation = _rust_static_library_without_process_wrapper_impl,
doc = "A variant of `rust_static_library` that uses a minimal process wrapper for `Rustc` actions.",
attrs = dict(_common_attrs_for_binary_without_process_wrapper(_common_attrs).items()),
fragments = ["cpp"],
toolchains = [
str(Label("//rust:toolchain_type")),
config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False),
],
provides = [
CcInfo,
rust_common.test_crate_info,
_RustBuiltWithoutProcessWrapperInfo,
],
)

def _test_attrs_for_binary_without_process_wrapper(attrs):
new_attrs = {}
new_attrs.update(attrs)
Expand Down
3 changes: 3 additions & 0 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,9 @@ def establish_cc_info(ctx, attr, crate_info, toolchain, cc_toolchain, feature_co
cc_infos.append(libstd_and_allocator_cc_info)

providers = [cc_common.merge_cc_infos(cc_infos = cc_infos)]
if crate_info.type == "staticlib":
# The static archive is the output.
dot_a = crate_info.output
if dot_a:
providers.append(AllocatorLibrariesImplInfo(static_archive = dot_a))
return providers
Expand Down
24 changes: 0 additions & 24 deletions test/integration/cc_common_link/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,6 @@ bazel_dep(name = "platforms", version = "1.0.0")
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = "2018",
target_settings = [
"@rules_rust//rust/settings:experimental_use_allocator_libraries_with_mangled_symbols_off",
],
)

# Generate a toolchain to be used for rust-based allocator symbols.

# A recent enough version of rustc that mangles the internal allocator symbols.
VERSION = "nightly/2025-07-08"

rust.repository_set(
name = "rust_with_alloc_mangling_linux_x86_64",
allocator_library = "@rules_rust//ffi/rs:empty",
edition = "2021",
exec_triple = "x86_64-unknown-linux-gnu",
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
target_settings = [
"@rules_rust//rust/settings:experimental_use_allocator_libraries_with_mangled_symbols_on",
],
target_triple = "x86_64-unknown-linux-gnu",
versions = [VERSION],
)
use_repo(rust, "rust_toolchains")

Expand Down