0

Make rust toolchain non-optional in chromium and move flags out of build

The //build dir should contain things that apply to all projects using
the directly. Moving the gn args for specific chromium projects out of
//build/config/rust.gni into the Chromium tree next to the features they
are flags for.

Removed the flags that now default to on. They were gated on enable_rust
but enable_rust is always true in Chromium, so in Chromium code we can
just assume it's true. Thus the features are always enabled. Removed
buildflags etc for these removed GN args.

Gating Rust in //base on IS_NACL rather than rust-specific toolchain
flags, as Rust is always available in Chromium in all of our build
configurations except NaCl (and it will be going away in under a year
now).

Change-Id: I4da36c740af7c01e7c70989b84548e6403ca4a0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6000397
Commit-Queue: danakj <danakj@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org>
Auto-Submit: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1379977}
This commit is contained in:
danakj
2024-11-07 22:14:14 +00:00
committed by Chromium LUCI CQ
parent 55d177552f
commit 9ddc162463
41 changed files with 189 additions and 232 deletions
BUILD.gn
base
build/config
chrome
content/browser/interest_group
infra/config
generated
builders
ci
android-rust-arm32-rel
android-rust-arm64-dbg
android-rust-arm64-rel
linux-rust-x64-dbg
linux-rust-x64-rel
mac-rust-x64-dbg
win-rust-x64-dbg
win-rust-x64-rel
try
android-rust-arm32-rel
android-rust-arm64-dbg
android-rust-arm64-rel
linux-rust-x64-dbg
linux-rust-x64-rel
mac-rust-x64-dbg
win-rust-x64-dbg
win-rust-x64-rel
gn_args
subprojects
mojo/public
rust
tools
bindings
services/data_decoder/public/cpp
skia
third_party
blink
common
public
renderer
platform
image-decoders
breakpad

@ -28,11 +28,13 @@ import("//extensions/buildflags/buildflags.gni")
import("//gpu/vulkan/features.gni")
import("//media/gpu/args.gni")
import("//media/media_options.gni")
import("//mojo/public/rust/rust.gni")
import("//pdf/features.gni")
import("//ppapi/buildflags/buildflags.gni")
import("//printing/buildflags/buildflags.gni")
import("//remoting/remoting_enable.gni")
import("//services/on_device_model/on_device_model.gni")
import("//skia/skia.gni")
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/ipc_fuzzer/ipc_fuzzer.gni")
import("//ui/base/ui_features.gni")
@ -886,12 +888,11 @@ group("all_rust") {
deps = [
":rust_build_tests",
"third_party/cloud_authenticator/processor",
"//base:base_unittests", # There is rust stuff in here.
"//testing/rust_gtest_interop:rust_gtest_interop_unittests",
"//third_party/cloud_authenticator/processor",
]
# There is rust stuff behind flags in here.
deps += [ "//base:base_unittests" ]
if (enable_rust_mojo) {
deps += [
"//mojo/public/rust:mojo_rust",
@ -899,9 +900,6 @@ group("all_rust") {
"//mojo/public/rust:mojo_rust_unittests",
]
}
if (enable_rust_gtest_interop) {
deps += [ "//testing/rust_gtest_interop:rust_gtest_interop_unittests" ]
}
if (enable_rust_png) {
deps += [ "//skia" ]
}

@ -105,30 +105,6 @@ if (is_fuchsia) {
import("//third_party/fuchsia-gn-sdk/src/fidl_library.gni")
}
# The Rust implementation of base::JSONReader. NaCl depends on base and doesn't
# have a Rust toolchain, so we need a fallback to C++ for it until it removes
# its dependency on //base.
#
# TODO(crbug.com/40811643): Drop toolchain_has_rust and move the C++ parser into
# components/nacl to just run in-process there. Don't compile base::JSONReader
# on NaCL at all.
build_rust_json_reader = toolchain_has_rust && enable_rust_json
# Rust to C++ type conversions. Also can not be enabled while NaCl depends on
# //base.
build_rust_base_conversions = toolchain_has_rust && enable_rust_base_conversions
assert(build_rust_base_conversions || !build_rust_json_reader,
"Cannot enable Rust JSON decoder without also base conversions")
buildflag_header("rust_buildflags") {
header = "rust_buildflags.h"
flags = [
"BUILD_RUST_JSON_READER=$build_rust_json_reader",
"BUILD_RUST_BASE_CONVERSIONS=$build_rust_base_conversions",
]
}
if (is_win) {
# This is in a separate config so the flags can be applied to dependents.
# ldflags in GN aren't automatically inherited.
@ -1046,7 +1022,10 @@ component("base") {
deps += [ "//third_party/zlib" ]
# NaCl does not support Rust.
deps += [ ":rust_logger" ]
deps += [
":rust_logger",
"//third_party/rust/serde_json_lenient/v0_2/wrapper",
]
}
# `raw_ptr` cannot be made a component due to CRT symbol issues.
@ -1054,10 +1033,6 @@ component("base") {
# to provide the appropriate `#define` here.
defines += [ "IS_RAW_PTR_IMPL" ]
if (build_rust_json_reader) {
deps += [ "//third_party/rust/serde_json_lenient/v0_2/wrapper" ]
}
# native_unwinder_android is intended for use solely via a dynamic feature
# module, to avoid increasing Chrome's executable size.
assert_no_deps = [ ":native_unwinder_android" ]
@ -1076,7 +1051,6 @@ component("base") {
":power_monitor_buildflags",
":profiler_buildflags",
":protected_memory_buildflags",
":rust_buildflags",
":sanitizer_buildflags",
":synchronization_buildflags",
":tracing_buildflags",
@ -1089,7 +1063,7 @@ component("base") {
"//third_party/abseil-cpp:absl",
]
if (build_rust_base_conversions) {
if (!is_nacl) {
sources += [
"containers/span_rust.h",
"strings/string_view_rust.h",
@ -3580,7 +3554,7 @@ test("base_unittests") {
sources += [ "location_unittest.cc" ]
}
if (build_rust_base_conversions) {
if (!is_nacl) {
sources += [
"containers/span_rust_unittest.cc",
"strings/string_piece_rust_unittest.cc",
@ -3633,6 +3607,10 @@ test("base_unittests") {
deps += [ "allocator/partition_allocator/src/partition_alloc:unittests" ]
}
if (!is_nacl) {
deps += [ "//build/rust:cxx_cppdeps" ]
}
data_deps = [
"//base/test:immediate_crash_test_helper",
"//base/test:test_child_process",
@ -3653,10 +3631,6 @@ test("base_unittests") {
"//base/allocator/partition_allocator/src/partition_alloc:memory_tagging",
]
if (build_rust_base_conversions) {
deps += [ "//build/rust:cxx_cppdeps" ]
}
if (is_apple) {
public_deps = [
":base_unittests_bundle_data",

@ -8,11 +8,11 @@
#include <stdint.h>
#include "base/containers/span.h"
#include "base/rust_buildflags.h"
#include "build/build_config.h"
#include "third_party/rust/cxx/v1/cxx.h"
#if !BUILDFLAG(BUILD_RUST_BASE_CONVERSIONS)
#error "span_rust.h included without BUILD_RUST_BASE_CONVERSIONS"
#if BUILDFLAG(IS_NACL)
#error "span_rust.h included under IS_NACL"
#endif
namespace base {

@ -8,20 +8,22 @@
#include <utility>
#include "base/features.h"
#include "base/json/json_parser.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/rust_buildflags.h"
#include "build/build_config.h"
#if BUILDFLAG(BUILD_RUST_JSON_READER)
#if !BUILDFLAG(IS_NACL)
#include "base/strings/string_view_rust.h"
#include "third_party/rust/serde_json_lenient/v0_2/wrapper/functions.h"
#include "third_party/rust/serde_json_lenient/v0_2/wrapper/lib.rs.h"
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
#include "base/json/json_parser.h"
#endif
namespace base {
#if BUILDFLAG(BUILD_RUST_JSON_READER)
// TODO(crbug.com/40811643): Move the C++ parser into components/nacl to just
// run in-process there. Don't compile base::JSONReader on NaCL at all.
#if !BUILDFLAG(IS_NACL)
namespace {
using serde_json_lenient::ContextPointer;
@ -132,13 +134,16 @@ JSONReader::Result DecodeJSONInRust(std::string_view json,
} // anonymous namespace
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
#endif // !BUILDFLAG(IS_NACL)
// static
std::optional<Value> JSONReader::Read(std::string_view json,
int options,
size_t max_depth) {
#if BUILDFLAG(BUILD_RUST_JSON_READER)
#if BUILDFLAG(IS_NACL)
internal::JSONParser parser(options, max_depth);
return parser.Parse(json);
#else // BUILDFLAG(IS_NACL)
SCOPED_UMA_HISTOGRAM_TIMER_MICROS(kSecurityJsonParsingTime);
if (UsingRust()) {
JSONReader::Result result = DecodeJSONInRust(json, options, max_depth);
@ -150,10 +155,7 @@ std::optional<Value> JSONReader::Read(std::string_view json,
internal::JSONParser parser(options, max_depth);
return parser.Parse(json);
}
#else // BUILDFLAG(BUILD_RUST_JSON_READER)
internal::JSONParser parser(options, max_depth);
return parser.Parse(json);
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
#endif // BUILDFLAG(IS_NACL)
}
// static
@ -171,7 +173,19 @@ std::optional<Value::Dict> JSONReader::ReadDict(std::string_view json,
JSONReader::Result JSONReader::ReadAndReturnValueWithError(
std::string_view json,
int options) {
#if BUILDFLAG(BUILD_RUST_JSON_READER)
#if BUILDFLAG(IS_NACL)
internal::JSONParser parser(options);
auto value = parser.Parse(json);
if (!value) {
Error error;
error.message = parser.GetErrorMessage();
error.line = parser.error_line();
error.column = parser.error_column();
return base::unexpected(std::move(error));
}
return std::move(*value);
#else // BUILDFLAG(IS_NACL)
SCOPED_UMA_HISTOGRAM_TIMER_MICROS(kSecurityJsonParsingTime);
if (UsingRust()) {
return DecodeJSONInRust(json, options, internal::kAbsoluteMaxDepth);
@ -188,19 +202,7 @@ JSONReader::Result JSONReader::ReadAndReturnValueWithError(
return std::move(*value);
}
#else // BUILDFLAG(BUILD_RUST_JSON_READER)
internal::JSONParser parser(options);
auto value = parser.Parse(json);
if (!value) {
Error error;
error.message = parser.GetErrorMessage();
error.line = parser.error_line();
error.column = parser.error_column();
return base::unexpected(std::move(error));
}
return std::move(*value);
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
#endif // BUILDFLAG(IS_NACL)
}
// static
@ -211,11 +213,11 @@ bool JSONReader::UsingRust() {
if (!base::FeatureList::GetInstance()) {
return false;
}
#if BUILDFLAG(BUILD_RUST_JSON_READER)
return base::FeatureList::IsEnabled(base::features::kUseRustJsonParser);
#else // BUILDFLAG(BUILD_RUST_JSON_READER)
#if BUILDFLAG(IS_NACL)
return false;
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
#else
return base::FeatureList::IsEnabled(base::features::kUseRustJsonParser);
#endif
}
} // namespace base

@ -20,7 +20,6 @@
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/rust_buildflags.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_expected_support.h"
@ -74,15 +73,11 @@ TEST_P(JSONReaderTest, InvalidString) {
}
TEST_P(JSONReaderTest, SimpleBool) {
#if BUILDFLAG(BUILD_RUST_JSON_READER)
base::HistogramTester histograms;
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
std::optional<Value> root = JSONReader::Read("true ");
ASSERT_TRUE(root);
EXPECT_TRUE(root->is_bool());
#if BUILDFLAG(BUILD_RUST_JSON_READER)
histograms.ExpectTotalCount("Security.JSONParser.ParsingTime", 1);
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
}
TEST_P(JSONReaderTest, EmbeddedComments) {
@ -1195,11 +1190,7 @@ TEST_P(JSONReaderTest, UsingRust) {
INSTANTIATE_TEST_SUITE_P(All,
JSONReaderTest,
#if BUILDFLAG(BUILD_RUST_JSON_READER)
testing::Bool(),
#else // BUILDFLAG(BUILD_RUST_JSON_READER)
testing::Values(false),
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
[](const testing::TestParamInfo<bool>& info) {
return info.param ? "Rust" : "Cpp";
});

@ -9,11 +9,11 @@
#include <string_view>
#include "base/rust_buildflags.h"
#include "build/build_config.h"
#include "third_party/rust/cxx/v1/cxx.h"
#if !BUILDFLAG(BUILD_RUST_BASE_CONVERSIONS)
#error "string_view_rust.h included without BUILD_RUST_BASE_CONVERSIONS"
#if BUILDFLAG(IS_NACL)
#error "string_view_rust.h included under IS_NACL"
#endif
namespace base {

@ -36,6 +36,8 @@ declare_args() {
# The CXX tool is in //third_party/rust which is not shared with downstream
# projects yet. So they need to copy the required dependencies and GN files
# into their project to enable CXX there.
#
# We do not support disabling this flag in Chromium code.
enable_rust_cxx = build_with_chromium
# The chromium prelude crate provides the `chromium::import!` macro which
@ -48,14 +50,10 @@ declare_args() {
# specify a globally unique `crate_name` in their rust library GN rules
# instead. Note that using a `crate_name` is strongly discouraged inside
# Chromium, and is also discouraged for downstream projects when possible.
#
# We do not support disabling this flag in Chromium code.
enable_chromium_prelude = build_with_chromium
# As we incrementally enable Rust on mainstream builders, we want to enable
# the toolchain (by switching 'enable_rust' to true) while still disabling
# almost all Rust features). Yet we still want to have some builders with
# all Rust features enabled.
enable_all_rust_features = false
# Chromium provides a Rust toolchain in //third_party/rust-toolchain.
#
# To use a custom toolchain instead, specify an absolute path to the root of
@ -106,34 +104,6 @@ declare_args() {
force_rustc_color_output = false
}
# Use a separate declare_args so these variables' defaults can depend on the
# ones above.
declare_args() {
# Individual Rust components.
# Conversions between Rust types and C++ types.
enable_rust_base_conversions = enable_rust
# The base::JSONReader implementation. Requires base conversions.
enable_rust_json = enable_rust
# Support for chrome://crash-rust to check crash dump collection works.
enable_rust_crash = enable_rust
# Support for Rust mojo bindings.
enable_rust_mojo = enable_rust && enable_all_rust_features
# Rust gtest interop.
enable_rust_gtest_interop = enable_rust
# WIP attempt to replace `libpng` with Rust `png` crate.
#
# TODO(https://crbug.com/360375227): Remove the `enable_all_rust_features`
# condition below (only true on Rust bots) once/if ready to start A/B
# experiments.
enable_rust_png = enable_rust && enable_all_rust_features
}
# Use the Rust toolchain built in-tree. When false, we use the prebuilt Rust
# stdlibs that come with the specified custom toolchain.
use_chromium_rust_toolchain = rust_sysroot_absolute == ""

@ -278,7 +278,6 @@ IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, MAYBE_CheckCrashRenderers) {
#endif
}
#if BUILDFLAG(ENABLE_RUST_CRASH)
IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, CrashRenderersInRust) {
base::HistogramTester histogram_tester;
@ -292,7 +291,6 @@ IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, CrashRenderersInRust) {
histogram_tester.ExpectBucketCount(
"Stability.Counts2", metrics::StabilityEventType::kRendererCrash, 1);
}
#endif // BUILDFLAG(ENABLE_RUST_CRASH)
// OOM code only works on Windows.
#if BUILDFLAG(IS_WIN) && !defined(ADDRESS_SANITIZER)

@ -259,12 +259,10 @@ base::span<const base::cstring_view> ChromeDebugURLs() {
blink::kChromeUIBrowserCrashURL,
blink::kChromeUIBrowserDcheckURL,
blink::kChromeUICrashURL,
#if BUILDFLAG(ENABLE_RUST_CRASH)
blink::kChromeUICrashRustURL,
#if defined(ADDRESS_SANITIZER)
blink::kChromeUICrashRustOverflowURL,
#endif
#endif // BUILDFLAG(ENABLE_RUST_CRASH)
blink::kChromeUIDumpURL,
blink::kChromeUIKillURL,
blink::kChromeUIHangURL,

@ -26,7 +26,6 @@
#include "base/memory/raw_ref.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/rust_buildflags.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"

@ -2,7 +2,9 @@
"gn_args": {
"dcheck_always_on": true,
"debuggable_apks": false,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"ffmpeg_branding": "Chrome",
"is_component_build": false,
"is_debug": false,

@ -1,7 +1,9 @@
{
"gn_args": {
"debuggable_apks": false,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"ffmpeg_branding": "Chrome",
"is_component_build": true,
"is_debug": true,

@ -2,7 +2,9 @@
"gn_args": {
"dcheck_always_on": true,
"debuggable_apks": false,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"ffmpeg_branding": "Chrome",
"is_component_build": false,
"is_debug": false,

@ -1,6 +1,8 @@
{
"gn_args": {
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": true,
"is_debug": true,
"symbol_level": 1,

@ -1,7 +1,9 @@
{
"gn_args": {
"dcheck_always_on": true,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": false,
"is_debug": false,
"symbol_level": 1,

@ -1,6 +1,8 @@
{
"gn_args": {
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": true,
"is_debug": true,
"symbol_level": 1,

@ -1,6 +1,8 @@
{
"gn_args": {
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": true,
"is_debug": true,
"symbol_level": 1,

@ -1,7 +1,9 @@
{
"gn_args": {
"dcheck_always_on": true,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": false,
"is_debug": false,
"symbol_level": 1,

@ -2,7 +2,9 @@
"gn_args": {
"dcheck_always_on": true,
"debuggable_apks": false,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"ffmpeg_branding": "Chrome",
"is_component_build": false,
"is_debug": false,

@ -1,7 +1,9 @@
{
"gn_args": {
"debuggable_apks": false,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"ffmpeg_branding": "Chrome",
"is_component_build": true,
"is_debug": true,

@ -2,7 +2,9 @@
"gn_args": {
"dcheck_always_on": true,
"debuggable_apks": false,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"ffmpeg_branding": "Chrome",
"is_component_build": false,
"is_debug": false,

@ -1,6 +1,8 @@
{
"gn_args": {
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": true,
"is_debug": true,
"symbol_level": 1,

@ -1,7 +1,9 @@
{
"gn_args": {
"dcheck_always_on": true,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": false,
"is_debug": false,
"symbol_level": 1,

@ -1,6 +1,8 @@
{
"gn_args": {
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": true,
"is_debug": true,
"symbol_level": 1,

@ -1,6 +1,8 @@
{
"gn_args": {
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": true,
"is_debug": true,
"symbol_level": 1,

@ -1,7 +1,9 @@
{
"gn_args": {
"dcheck_always_on": true,
"enable_all_rust_features": true,
"enable_rust_mojo": true,
"enable_rust_mojom_bindings": true,
"enable_rust_png": true,
"is_component_build": false,
"is_debug": false,
"symbol_level": 1,

@ -536,9 +536,23 @@ gn_args.config(
)
gn_args.config(
name = "enable_all_rust_features",
name = "enable_rust_mojo",
args = {
"enable_all_rust_features": True,
"enable_rust_mojo": True,
},
)
gn_args.config(
name = "enable_rust_mojom_bindings",
args = {
"enable_rust_mojom_bindings": True,
},
)
gn_args.config(
name = "enable_rust_png",
args = {
"enable_rust_png": True,
},
)

@ -38,6 +38,15 @@ consoles.console_view(
name = "chromium.rust",
)
def rust_fyi_configs(*args):
# Enables off-by-default GN configs to build extra experimental Rust
# components.
return list(args) + [
"enable_rust_mojo",
"enable_rust_mojom_bindings",
"enable_rust_png",
]
ci.builder(
name = "android-rust-arm32-rel",
builder_spec = builder_config.builder_spec(
@ -58,14 +67,13 @@ ci.builder(
android_config = builder_config.android_config(config = "base_config"),
),
gn_args = gn_args.config(
configs = [
configs = rust_fyi_configs(
"release_try_builder",
"minimal_symbols",
"remoteexec",
"enable_all_rust_features",
"android_builder",
"arm",
],
),
),
targets = targets.bundle(
targets = [
@ -108,13 +116,12 @@ ci.builder(
android_config = builder_config.android_config(config = "base_config"),
),
gn_args = gn_args.config(
configs = [
configs = rust_fyi_configs(
"debug_builder",
"remoteexec",
"enable_all_rust_features",
"android_builder",
"arm64",
],
),
),
targets = targets.bundle(
targets = [
@ -157,14 +164,13 @@ ci.builder(
android_config = builder_config.android_config(config = "base_config"),
),
gn_args = gn_args.config(
configs = [
configs = rust_fyi_configs(
"release_try_builder",
"minimal_symbols",
"remoteexec",
"enable_all_rust_features",
"android_builder",
"arm64",
],
),
),
targets = targets.bundle(
targets = [
@ -202,13 +208,12 @@ ci.builder(
),
),
gn_args = gn_args.config(
configs = [
configs = rust_fyi_configs(
"debug_builder",
"remoteexec",
"enable_all_rust_features",
"linux",
"x64",
],
),
),
targets = targets.bundle(
targets = [
@ -248,14 +253,13 @@ ci.builder(
),
),
gn_args = gn_args.config(
configs = [
configs = rust_fyi_configs(
"release_try_builder",
"minimal_symbols",
"remoteexec",
"enable_all_rust_features",
"linux",
"x64",
],
),
),
targets = targets.bundle(
targets = [
@ -293,13 +297,12 @@ ci.builder(
),
),
gn_args = gn_args.config(
configs = [
configs = rust_fyi_configs(
"debug_builder",
"remoteexec",
"enable_all_rust_features",
"mac",
"x64",
],
),
),
targets = targets.bundle(
targets = [
@ -339,13 +342,12 @@ ci.builder(
),
),
gn_args = gn_args.config(
configs = [
configs = rust_fyi_configs(
"debug_builder",
"remoteexec",
"enable_all_rust_features",
"win",
"x64",
],
),
),
targets = targets.bundle(
targets = [
@ -385,14 +387,13 @@ ci.builder(
),
),
gn_args = gn_args.config(
configs = [
configs = rust_fyi_configs(
"release_try_builder",
"minimal_symbols",
"remoteexec",
"enable_all_rust_features",
"win",
"x64",
],
),
),
targets = targets.bundle(
targets = [

@ -0,0 +1,8 @@
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
declare_args() {
# Support for the experimental Rust mojo implementation.
enable_rust_mojo = false
}

@ -19,7 +19,6 @@ import("//build/config/chrome_build.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni")
import("//build/config/nacl/config.gni")
import("//build/config/rust.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/rust/rust_static_library.gni")
import("//build/toolchain/kythe.gni")
@ -51,7 +50,12 @@ declare_args() {
# Output Rust mojom bindings when `generate_rust` is `true` for a target. The
# option has no effect if this flag is disabled.
enable_rust_mojom_bindings = enable_all_rust_features
#
# This is currently behind a build flag since it's not being actively worked
# on, but to maintain some coverage of the code on the Rust FYI bots. When we
# want to actively develop support for Mojo use with Rust again, we should do
# it without any build flags.
enable_rust_mojom_bindings = false
# Enables Closure compilation of generated JS lite bindings. In environments
# where compilation is supported, any mojom target "foo" will also have a

@ -14,7 +14,6 @@
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/rust_buildflags.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
@ -145,8 +144,6 @@ void BindInProcessService(
}
#endif
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(BUILD_RUST_JSON_READER)
void ParsingComplete(scoped_refptr<DataDecoder::CancellationFlag> is_cancelled,
DataDecoder::ValueParseCallback callback,
base::JSONReader::Result value_with_error) {
@ -161,8 +158,6 @@ void ParsingComplete(scoped_refptr<DataDecoder::CancellationFlag> is_cancelled,
}
}
#endif
} // namespace
DataDecoder::DataDecoder() : DataDecoder(kServiceProcessIdleTimeoutDefault) {}
@ -210,7 +205,6 @@ void DataDecoder::ParseJson(const std::string& json,
base::ElapsedTimer(), std::move(callback));
if (base::JSONReader::UsingRust()) {
#if BUILDFLAG(BUILD_RUST_JSON_READER)
if (base::features::kUseRustJsonParserInCurrentSequence.Get()) {
base::JSONReader::Result result =
base::JSONReader::ReadAndReturnValueWithError(json,
@ -230,10 +224,6 @@ void DataDecoder::ParseJson(const std::string& json,
base::BindOnce(&ParsingComplete, cancel_requests_,
std::move(callback)));
}
#else // BUILDFLAG(BUILD_RUST_JSON_READER)
CHECK(false)
<< "UseJsonParserFeature enabled, but not supported in this build.";
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
return;
}

@ -9,7 +9,6 @@
#include "base/features.h"
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/rust_buildflags.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
@ -207,8 +206,6 @@ TEST_F(DataDecoderTest, SeparateDecoderInstancesMakeSeparateConnectionsForPix) {
EXPECT_EQ(2u, service().receivers().size());
}
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(BUILD_RUST_JSON_READER)
class DataDecoderMultiThreadTest : public testing::Test {
protected:
void TestJSONDecode() {
@ -270,6 +267,4 @@ TEST_F(DataDecoderMultiThreadTest, JSONDecodeRustCurrentSequence) {
TestJSONDecode();
}
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(BUILD_RUST_JSON_READER)
} // namespace data_decoder

@ -7,7 +7,6 @@
#include <utility>
#include "base/features.h"
#include "base/rust_buildflags.h"
#include "base/task/sequenced_task_runner.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
@ -29,10 +28,8 @@ InProcessDataDecoder::CreateCustomImageDecoder() {
}
void InProcessDataDecoder::SimulateJsonParserCrash(bool drop) {
#if BUILDFLAG(BUILD_RUST_JSON_READER)
CHECK(!base::FeatureList::IsEnabled(base::features::kUseRustJsonParser))
<< "Rust JSON parser is in-process and cannot crash.";
#endif // BUILDFLAG(BUILD_RUST_JSON_READER)
drop_json_parsers_ = drop;
}

@ -10,6 +10,7 @@ import("//build/config/rust.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/rust/rust_static_library.gni")
import("//gpu/vulkan/features.gni")
import("//skia/skia.gni")
import("//testing/test.gni")
import("//third_party/skia/gn/shared_sources.gni")
import("//third_party/skia/modules/skcms/skcms.gni")

11
skia/skia.gni Normal file

@ -0,0 +1,11 @@
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
declare_args() {
# WIP attempt to replace `libpng` with Rust `png` crate.
#
# TODO(https://crbug.com/360375227): Default to true when ready to start A/B
# experiments.
enable_rust_png = false
}

@ -341,6 +341,7 @@ source_set("common") {
"//services/metrics/public/cpp:ukm_builders",
"//services/metrics/public/mojom:mojom",
"//services/network/public/cpp:cpp",
"//third_party/blink/common/rust_crash",
"//third_party/blink/public/common:buildflags",
"//third_party/re2",
"//ui/base:base",
@ -353,10 +354,6 @@ source_set("common") {
"//ui/latency/mojom:shared_mojom_traits",
]
if (enable_rust_crash) {
deps += [ "//third_party/blink/common/rust_crash" ]
}
# If use_blink is used then it needs to depend on //media
if (use_blink) {
deps += [ "//media" ]

@ -11,6 +11,7 @@
#include "base/threading/platform_thread.h"
#include "build/build_config.h"
#include "third_party/blink/common/crash_helpers.h"
#include "third_party/blink/common/rust_crash/src/lib.rs.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_WIN)
@ -22,9 +23,6 @@
#include <zircon/syscalls.h>
#endif
#if BUILDFLAG(ENABLE_RUST_CRASH)
#include "third_party/blink/common/rust_crash/src/lib.rs.h"
#endif
namespace blink {
@ -41,28 +39,18 @@ bool IsRendererDebugURL(const GURL& url) {
if (url == kChromeUICheckCrashURL || url == kChromeUIBadCastCrashURL ||
url == kChromeUICrashURL || url == kChromeUIDumpURL ||
url == kChromeUIKillURL || url == kChromeUIHangURL ||
url == kChromeUIShorthangURL || url == kChromeUIMemoryExhaustURL) {
url == kChromeUIShorthangURL || url == kChromeUIMemoryExhaustURL ||
url == kChromeUICrashRustURL) {
return true;
}
#if BUILDFLAG(ENABLE_RUST_CRASH)
if (url == kChromeUICrashRustURL) {
return true;
}
#endif
#if defined(ADDRESS_SANITIZER)
if (url == kChromeUICrashHeapOverflowURL ||
url == kChromeUICrashHeapUnderflowURL ||
url == kChromeUICrashUseAfterFreeURL) {
url == kChromeUICrashUseAfterFreeURL ||
url == kChromeUICrashRustOverflowURL) {
return true;
}
#if BUILDFLAG(ENABLE_RUST_CRASH)
if (url == kChromeUICrashRustOverflowURL) {
return true;
}
#endif // BUILDFLAG(ENABLE_RUST_CRASH)
#endif // defined(ADDRESS_SANITIZER)
#if BUILDFLAG(IS_WIN)
@ -125,13 +113,11 @@ NOINLINE void MaybeTriggerAsanError(const GURL& url) {
<< " because user navigated to " << url.spec();
base::debug::AsanCorruptHeap();
#endif // BUILDFLAG(IS_WIN)
#if BUILDFLAG(ENABLE_RUST_CRASH)
} else if (url == kChromeUICrashRustOverflowURL) {
// Ensure that ASAN works even in Rust code.
LOG(ERROR) << "Intentionally causing ASAN heap overflow in Rust"
<< " because user navigated to " << url.spec();
crash_in_rust_with_overflow();
#endif
}
}
#endif // ADDRESS_SANITIZER
@ -148,12 +134,10 @@ void HandleChromeDebugURL(const GURL& url) {
LOG(ERROR) << "Intentionally crashing (with null pointer dereference)"
<< " because user navigated to " << url.spec();
internal::CrashIntentionally();
#if BUILDFLAG(ENABLE_RUST_CRASH)
} else if (url == kChromeUICrashRustURL) {
// Cause a typical crash in Rust code, so we can test that call stack
// collection and symbol mangling work across the language boundary.
crash_in_rust();
#endif
} else if (url == kChromeUIDumpURL) {
// This URL will only correctly create a crash dump file if content is
// hosted in a process that has correctly called

@ -87,7 +87,6 @@ buildflag_header("buildflags") {
flags = [
"RTC_USE_H264=$rtc_use_h264",
"RTC_USE_H265=$rtc_use_h265",
"ENABLE_RUST_CRASH=$enable_rust_crash",
]
}

@ -8,7 +8,6 @@
#include "base/check_op.h"
#include "base/dcheck_is_on.h"
#include "build/build_config.h"
#include "third_party/blink/public/common/buildflags.h"
#include "third_party/blink/public/common/common_export.h"
class GURL;
@ -52,9 +51,7 @@ inline constexpr char kChromeUIProcessInternalsURL[] =
#if BUILDFLAG(IS_ANDROID)
inline constexpr char kChromeUIGpuJavaCrashURL[] = "chrome://gpu-java-crash/";
#endif
#if BUILDFLAG(ENABLE_RUST_CRASH)
inline constexpr char kChromeUICrashRustURL[] = "chrome://crash/rust";
#endif
#if BUILDFLAG(IS_WIN)
inline constexpr char kChromeUIBrowserHeapCorruptionURL[] =
"chrome://inducebrowserheapcorruption/";
@ -76,10 +73,8 @@ inline constexpr char kChromeUICrashCorruptHeapBlockURL[] =
inline constexpr char kChromeUICrashCorruptHeapURL[] =
"chrome://crash/corrupt-heap";
#endif // BUILDFLAG(IS_WIN)
#if BUILDFLAG(ENABLE_RUST_CRASH)
inline constexpr char kChromeUICrashRustOverflowURL[] =
"chrome://crash/rust-overflow";
#endif // BUILDFLAG(ENABLE_RUST_CRASH)
#endif // ADDRESS_SANITIZER
#if DCHECK_IS_ON()

@ -2,11 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/rust.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//media/media_options.gni")
import("//skia/skia.gni")
import("//testing/test.gni")
import("//third_party/blink/renderer/platform/platform.gni")
component("image_decoders") {
visibility = [
"//third_party/blink/renderer/core/*",

@ -494,12 +494,11 @@ if (is_mac) {
# For breakpad/src/common/stabs_reader.h.
defines = [ "HAVE_MACH_O_NLIST_H" ]
if (enable_rust_crash) {
deps = [ "//third_party/rust/rustc_demangle_capi/v0_1:lib" ]
defines += [ "HAVE_RUSTC_DEMANGLE" ]
include_dirs += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include" ]
sources += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include/rustc_demangle.h" ]
}
# Rust demangle support.
deps = [ "//third_party/rust/rustc_demangle_capi/v0_1:lib" ]
defines += [ "HAVE_RUSTC_DEMANGLE" ]
include_dirs += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include" ]
sources += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include/rustc_demangle.h" ]
}
test("breakpad_unittests") {
sources = [ "breakpad/src/common/module_unittest.cc" ]
@ -743,12 +742,11 @@ if (is_linux || is_chromeos || is_android) {
include_dirs = [ "breakpad/src" ]
if (enable_rust_crash) {
deps = [ "//third_party/rust/rustc_demangle_capi/v0_1:lib" ]
defines += [ "HAVE_RUSTC_DEMANGLE" ]
include_dirs += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include" ]
sources += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include/rustc_demangle.h" ]
}
# Rust demangle support.
deps = [ "//third_party/rust/rustc_demangle_capi/v0_1:lib" ]
defines += [ "HAVE_RUSTC_DEMANGLE" ]
include_dirs += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include" ]
sources += [ "//third_party/rust/chromium_crates_io/vendor/rustc-demangle-capi-0.1.0/include/rustc_demangle.h" ]
libs = [ "z" ]
}