Set up default allocator_library and global_allocator_library (#2172)

This makes C++ depending on Rust Just Work out of the box, while still
giving people
hooks to customise these if they need.

In particular, this means we can centrally manage and update our default
definition of these symbols, rather than require people to vendor them
and keep their copies up to date as new versions of Rust come out.

We provide this as a best-effort tool which we hope will be useful to
people, and will attempt to maintain the C++ code included here, but
make not guarantees about its universality or correctness. If you need
more specific behaviours, you should set your own `allocator_library`
and `global_allocator_library` attributes on your toolchains.
This commit is contained in:
Daniel Wagner-Hall 2023-09-29 14:45:38 +01:00 committed by GitHub
parent ac5aa1edc6
commit aa4b3a862a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 43 additions and 154 deletions

View File

@ -1225,7 +1225,7 @@ See `@rules_rust//rust:repositories.bzl` for examples of defining the `@rust_cpu
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="rust_toolchain-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="rust_toolchain-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>@rules_rust//ffi/cc/allocator_library</code> |
| <a id="rust_toolchain-binary_ext"></a>binary_ext | The extension for binaries created from rustc. | String | required | |
| <a id="rust_toolchain-cargo"></a>cargo | The location of the <code>cargo</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-clippy_driver"></a>clippy_driver | The location of the <code>clippy-driver</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
@ -1237,7 +1237,7 @@ See `@rules_rust//rust:repositories.bzl` for examples of defining the `@rust_cpu
| <a id="rust_toolchain-experimental_use_cc_common_link"></a>experimental_use_cc_common_link | Label to a boolean build setting that controls whether cc_common.link is used to link rust binaries. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>//rust/settings:experimental_use_cc_common_link</code> |
| <a id="rust_toolchain-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions for when a global allocator is present. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions for when a global allocator is present. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>@rules_rust//ffi/cc/global_allocator_library</code> |
| <a id="rust_toolchain-llvm_cov"></a>llvm_cov | The location of the <code>llvm-cov</code> binary. Can be a direct source or a filegroup containing one item. If None, rust code is not instrumented for coverage. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-llvm_profdata"></a>llvm_profdata | The location of the <code>llvm-profdata</code> binary. Can be a direct source or a filegroup containing one item. If <code>llvm_cov</code> is None, this can be None as well and rust code is not instrumented for coverage. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-llvm_tools"></a>llvm_tools | LLVM tools that are shipped with the Rust toolchain. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
@ -1300,14 +1300,14 @@ A given instance of this rule should be accompanied by a toolchain_repository_pr
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="rust_toolchain_tools_repository-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="rust_toolchain_tools_repository-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | String | optional | <code>"@rules_rust//ffi/cc/allocator_library"</code> |
| <a id="rust_toolchain_tools_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="rust_toolchain_tools_repository-dev_components"></a>dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | <code>False</code> |
| <a id="rust_toolchain_tools_repository-edition"></a>edition | The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its <code>edition</code> attribute. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-exec_triple"></a>exec_triple | The Rust-style target that this compiler runs on | String | required | |
| <a id="rust_toolchain_tools_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain_tools_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain_tools_repository-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when a global allocator is used with cc_common.link. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when a global allocator is used with cc_common.link. | String | optional | <code>"@rules_rust//ffi/cc/global_allocator_library"</code> |
| <a id="rust_toolchain_tools_repository-iso_date"></a>iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-opt_level"></a>opt_level | Rustc optimization levels. For more details see the documentation for <code>rust_toolchain.opt_level</code>. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="rust_toolchain_tools_repository-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |

View File

@ -93,7 +93,7 @@ See `@rules_rust//rust:repositories.bzl` for examples of defining the `@rust_cpu
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="rust_toolchain-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="rust_toolchain-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>@rules_rust//ffi/cc/allocator_library</code> |
| <a id="rust_toolchain-binary_ext"></a>binary_ext | The extension for binaries created from rustc. | String | required | |
| <a id="rust_toolchain-cargo"></a>cargo | The location of the <code>cargo</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-clippy_driver"></a>clippy_driver | The location of the <code>clippy-driver</code> binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
@ -105,7 +105,7 @@ See `@rules_rust//rust:repositories.bzl` for examples of defining the `@rust_cpu
| <a id="rust_toolchain-experimental_use_cc_common_link"></a>experimental_use_cc_common_link | Label to a boolean build setting that controls whether cc_common.link is used to link rust binaries. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>//rust/settings:experimental_use_cc_common_link</code> |
| <a id="rust_toolchain-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions for when a global allocator is present. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions for when a global allocator is present. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>@rules_rust//ffi/cc/global_allocator_library</code> |
| <a id="rust_toolchain-llvm_cov"></a>llvm_cov | The location of the <code>llvm-cov</code> binary. Can be a direct source or a filegroup containing one item. If None, rust code is not instrumented for coverage. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-llvm_profdata"></a>llvm_profdata | The location of the <code>llvm-profdata</code> binary. Can be a direct source or a filegroup containing one item. If <code>llvm_cov</code> is None, this can be None as well and rust code is not instrumented for coverage. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="rust_toolchain-llvm_tools"></a>llvm_tools | LLVM tools that are shipped with the Rust toolchain. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
@ -168,14 +168,14 @@ A given instance of this rule should be accompanied by a toolchain_repository_pr
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="rust_toolchain_tools_repository-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="rust_toolchain_tools_repository-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | String | optional | <code>"@rules_rust//ffi/cc/allocator_library"</code> |
| <a id="rust_toolchain_tools_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="rust_toolchain_tools_repository-dev_components"></a>dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | <code>False</code> |
| <a id="rust_toolchain_tools_repository-edition"></a>edition | The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its <code>edition</code> attribute. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-exec_triple"></a>exec_triple | The Rust-style target that this compiler runs on | String | required | |
| <a id="rust_toolchain_tools_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain_tools_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain_tools_repository-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when a global allocator is used with cc_common.link. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when a global allocator is used with cc_common.link. | String | optional | <code>"@rules_rust//ffi/cc/global_allocator_library"</code> |
| <a id="rust_toolchain_tools_repository-iso_date"></a>iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-opt_level"></a>opt_level | Rustc optimization levels. For more details see the documentation for <code>rust_toolchain.opt_level</code>. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="rust_toolchain_tools_repository-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |

View File

@ -2,17 +2,10 @@ load("@build_bazel_rules_android//android:rules.bzl", "android_binary", "android
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_rust//rust:defs.bzl", "rust_library")
cc_library(
name = "allocator_library",
srcs = ["allocator_library.cc"],
visibility = ["//visibility:public"],
)
rust_library(
name = "rust_lib",
srcs = ["demo.rs"],
edition = "2018",
deps = [":allocator_library"],
)
cc_library(

View File

@ -1,54 +0,0 @@
#include <stdint.h>
// This file has some exciting magic to get Rust code linking in a cc_binary.
// The Rust compiler generates some similar symbol aliases when it links, so we
// have to do it manually. We mark all our symbols as weak so that linking this
// via Rust tooling to produce a binary with a Rust main works.
//
// It is intended to be used in rust_toolchain.allocator_library.
//
// https://github.com/rust-lang/rust/blob/master/library/alloc/src/alloc.rs
// and https://github.com/rust-lang/rust/blob/master/library/std/src/alloc.rs
// are the best source of docs I've found on these functions and variables.
// https://doc.rust-lang.org/std/alloc/index.html talks about how this is
// intended to be used.
//
// Also note
// https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html for
// the sizes of the various integer types.
//
// This file strongly assumes that the default allocator is used. It will
// not work with any other allocated switched in via `#[global_allocator]`.
// New feature as of https://github.com/rust-lang/rust/pull/88098.
__attribute__((weak)) uint8_t __rust_alloc_error_handler_should_panic = 0;
extern "C" uint8_t *__rdl_alloc(uintptr_t size, uintptr_t align);
extern "C" __attribute__((weak)) uint8_t *__rust_alloc(uintptr_t size,
uintptr_t align) {
return __rdl_alloc(size, align);
}
extern "C" void __rdl_dealloc(uint8_t *ptr, uintptr_t size, uintptr_t align);
extern "C" __attribute__((weak)) void __rust_dealloc(uint8_t *ptr,
uintptr_t size,
uintptr_t align) {
__rdl_dealloc(ptr, size, align);
}
extern "C" uint8_t *__rdl_realloc(uint8_t *ptr, uintptr_t old_size,
uintptr_t align, uintptr_t new_size);
extern "C" __attribute__((weak)) uint8_t *__rust_realloc(uint8_t *ptr,
uintptr_t old_size,
uintptr_t align,
uintptr_t new_size) {
return __rdl_realloc(ptr, old_size, align, new_size);
}
extern "C" uint8_t *__rdl_alloc_zeroed(uintptr_t size, uintptr_t align);
extern "C" __attribute__((weak)) uint8_t *__rust_alloc_zeroed(uintptr_t size,
uintptr_t align) {
return __rdl_alloc_zeroed(size, align);
}
extern "C" void __rdl_oom(uintptr_t size, uintptr_t align);
extern "C" __attribute__((weak)) void __rust_alloc_error_handler(
uintptr_t size, uintptr_t align) {
__rdl_oom(size, align);
}

View File

@ -3,18 +3,11 @@ load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application")
load("@rules_cc//cc:defs.bzl", "cc_library", "objc_library")
load("@rules_rust//rust:defs.bzl", "rust_library")
cc_library(
name = "allocator_library",
srcs = ["allocator_library.cc"],
tags = ["manual"],
)
rust_library(
name = "rust_lib",
srcs = ["demo.rs"],
edition = "2018",
tags = ["manual"],
deps = [":allocator_library"],
)
# TODO: Remove this once rules_rust doesn't support bazel 5.x

View File

@ -0,0 +1,14 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "allocator_library",
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.cc"],
"//conditions:default": ["allocator_library.cc"],
}),
tags = ["manual"],
visibility = ["//visibility:public"],
)

View File

View File

@ -0,0 +1,14 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "global_allocator_library",
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.cc"],
"//conditions:default": ["global_allocator_library.cc"],
}),
tags = ["manual"],
visibility = ["//visibility:public"],
)

View File

View File

@ -25,7 +25,7 @@ def _rust_impl(ctx):
)
rust_toolchain = tag_class(attrs = {
"allocator_library": attr.string(),
"allocator_library": attr.string(default = "@rules_rust//ffi/cc/allocator_library"),
"dev_components": attr.bool(default = False),
"edition": attr.string(),
"extra_target_triples": attr.string_list(default = DEFAULT_EXTRA_TARGET_TRIPLES),

View File

@ -381,6 +381,7 @@ rust_toolchain_tools_repository = repository_rule(
attrs = {
"allocator_library": attr.string(
doc = "Target that provides allocator functions when rust_library targets are embedded in a cc_binary.",
default = "@rules_rust//ffi/cc/allocator_library",
),
"auth": attr.string_dict(
doc = (
@ -410,6 +411,7 @@ rust_toolchain_tools_repository = repository_rule(
),
"global_allocator_library": attr.string(
doc = "Target that provides allocator functions when a global allocator is used with cc_common.link.",
default = "@rules_rust//ffi/cc/global_allocator_library",
),
"iso_date": attr.string(
doc = "The date of the tool (or None, if the version is a specific version).",

View File

@ -654,6 +654,7 @@ rust_toolchain = rule(
attrs = {
"allocator_library": attr.label(
doc = "Target that provides allocator functions when rust_library targets are embedded in a cc_binary.",
default = "@rules_rust//ffi/cc/allocator_library",
),
"binary_ext": attr.string(
doc = "The extension for binaries created from rustc.",
@ -709,6 +710,7 @@ rust_toolchain = rule(
),
"global_allocator_library": attr.label(
doc = "Target that provides allocator functions for when a global allocator is present.",
default = "@rules_rust//ffi/cc/global_allocator_library",
),
"llvm_cov": attr.label(
doc = "The location of the `llvm-cov` binary. Can be a direct source or a filegroup containing one item. If None, rust code is not instrumented for coverage.",

View File

@ -7,18 +7,6 @@ load(
"rust_test",
)
cc_library(
name = "allocator_library",
srcs = ["allocator_library.cc"],
visibility = ["//visibility:public"],
)
cc_library(
name = "global_allocator_library",
srcs = ["global_allocator_library.cc"],
visibility = ["//visibility:public"],
)
cc_library(
name = "cclinkstampdep",
linkstamp = "cclinkstampdep.cc",

View File

@ -10,7 +10,6 @@ load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_regi
rules_rust_dependencies()
rust_register_toolchains(
allocator_library = "@test_cc_common_link//:allocator_library",
edition = "2018",
)

View File

@ -1,58 +0,0 @@
#include <stdint.h>
// This file has some exciting magic to get Rust code linking in a cc_binary.
// The Rust compiler generates some similar symbol aliases when it links, so we
// have to do it manually. We mark all our symbols as weak so that linking this
// via Rust tooling to produce a binary with a Rust main works.
//
// It is intended to be used in rust_toolchain.allocator_library.
//
// https://github.com/rust-lang/rust/blob/master/library/alloc/src/alloc.rs
// and https://github.com/rust-lang/rust/blob/master/library/std/src/alloc.rs
// are the best source of docs I've found on these functions and variables.
// https://doc.rust-lang.org/std/alloc/index.html talks about how this is
// intended to be used.
//
// Also note
// https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html for
// the sizes of the various integer types.
//
// This file strongly assumes that the default allocator is used. It will
// not work with any other allocated switched in via `#[global_allocator]`.
// New feature as of https://github.com/rust-lang/rust/pull/88098.
__attribute__((weak)) uint8_t __rust_alloc_error_handler_should_panic = 0;
extern "C" uint8_t *__rdl_alloc(uintptr_t size, uintptr_t align);
extern "C" __attribute__((weak)) uint8_t *__rust_alloc(uintptr_t size,
uintptr_t align) {
return __rdl_alloc(size, align);
}
extern "C" void __rdl_dealloc(uint8_t *ptr, uintptr_t size, uintptr_t align);
extern "C" __attribute__((weak)) void __rust_dealloc(uint8_t *ptr,
uintptr_t size,
uintptr_t align) {
__rdl_dealloc(ptr, size, align);
}
extern "C" uint8_t *__rdl_realloc(uint8_t *ptr, uintptr_t old_size,
uintptr_t align, uintptr_t new_size);
extern "C" __attribute__((weak)) uint8_t *__rust_realloc(uint8_t *ptr,
uintptr_t old_size,
uintptr_t align,
uintptr_t new_size) {
return __rdl_realloc(ptr, old_size, align, new_size);
}
extern "C" uint8_t *__rdl_alloc_zeroed(uintptr_t size, uintptr_t align);
extern "C" __attribute__((weak)) uint8_t *__rust_alloc_zeroed(uintptr_t size,
uintptr_t align) {
return __rdl_alloc_zeroed(size, align);
}
extern "C" void __rdl_oom(uintptr_t size, uintptr_t align);
extern "C" __attribute__((weak)) void __rust_alloc_error_handler(
uintptr_t size, uintptr_t align) {
__rdl_oom(size, align);
}
// New requirement as of Rust 1.71.0. For more details see
// https://github.com/rust-lang/rust/issues/73632.
__attribute__((weak)) uint8_t __rust_no_alloc_shim_is_unstable = 0;

View File

@ -15,9 +15,7 @@ load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_regi
rules_rust_dependencies()
rust_register_toolchains(
allocator_library = "@test_cc_common_link//:allocator_library",
edition = "2018",
global_allocator_library = "@test_cc_common_link//:global_allocator_library",
)
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

View File

@ -15,9 +15,7 @@ load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_regi
rules_rust_dependencies()
rust_register_toolchains(
allocator_library = "@test_cc_common_link//:allocator_library",
edition = "2021",
global_allocator_library = "@test_cc_common_link//:global_allocator_library",
versions = [
"nightly/2023-04-20",
"1.68.0",

View File

@ -51,7 +51,7 @@ def _collect_user_link_flags(env, tut):
def _rlib_provides_cc_info_test_impl(ctx):
env = analysistest.begin(ctx)
tut = analysistest.target_under_test(env)
_assert_cc_info_has_library_to_link(env, tut, "rlib", 3)
_assert_cc_info_has_library_to_link(env, tut, "rlib", 4)
return analysistest.end(env)
def _rlib_with_dep_only_has_stdlib_linkflags_once_test_impl(ctx):

View File

@ -33,7 +33,7 @@ def _stdlibs(tut):
for li in tut[CcInfo].linking_context.linker_inputs.to_list()
for lib in li.libraries
]
stdlibs = [lib for lib in libs if (tut.label.name not in lib.basename)]
stdlibs = [lib for lib in libs if (lib and tut.label.name not in lib.basename)]
return stdlibs
def _libstd_ordering_test_impl(ctx):