From 31f28a0b8ca2cca39b19ae530e84baefcd35aa43 Mon Sep 17 00:00:00 2001 From: Li-Yu Yu Date: Sat, 12 Oct 2024 05:18:47 +0800 Subject: [PATCH] Move cras_processor out of cras/src/server/rust BUG=b:372902037 TEST=devtools/rust_generate.py TEST=cargo build && SYSTEM_CRAS_RUST_LIB=$PWD/target/debug/libcras_rust.a bazel test --//:apm --//:system_cras_rust //... TEST=bazel test --//:apm //... TEST=FEATURES='test -usersandbox' emerge-amd64-generic cras_rust adhd TEST=bazel run //cras/server/processor:processor_test Change-Id: If509ca4356f421d7c82d2e184cb33cb56d95e47d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5922501 Reviewed-by: Hung-Hsien Chen Tested-by: Li-Yu Yu Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com Commit-Queue: Li-Yu Yu --- Cargo.Bazel.lock | 115 ++++++++++++------ Cargo.lock | 15 +++ Cargo.toml | 2 + WORKSPACE.bazel | 1 + .../write_source_file_targets_generated.bzl | 2 +- cras/server/platform/dlc/BUILD.bazel | 2 +- cras/server/processor/BUILD.bazel | 76 ++++++++++++ cras/server/processor/Cargo.toml | 17 +++ .../server/rust => server/processor}/build.rs | 0 .../processor}/cras_processor_test.cc | 2 +- .../processor/processor.h} | 8 +- .../processor}/proto/cras_processor.proto | 0 .../processor/src/lib.rs} | 1 + .../processor/src}/processor_override.rs | 0 .../rust => server/processor}/src/proto.rs | 0 cras/src/server/BUILD.bazel | 1 + cras/src/server/cras_stream_apm.c | 2 +- cras/src/server/rust/BUILD.bazel | 37 +----- cras/src/server/rust/Cargo.toml | 1 + cras/src/server/rust/src/lib.rs | 5 +- cras/src/tests/BUILD.bazel | 1 + 21 files changed, 207 insertions(+), 81 deletions(-) create mode 100644 cras/server/processor/BUILD.bazel create mode 100644 cras/server/processor/Cargo.toml rename cras/{src/server/rust => server/processor}/build.rs (100%) rename cras/{src/server/rust => server/processor}/cras_processor_test.cc (97%) rename cras/{src/server/rust/include/cras_processor.h => server/processor/processor.h} (87%) rename cras/{src/server/rust => server/processor}/proto/cras_processor.proto (100%) rename cras/{src/server/rust/src/cras_processor.rs => server/processor/src/lib.rs} (99%) rename cras/{src/server/rust/src/cras_processor => server/processor/src}/processor_override.rs (100%) rename cras/{src/server/rust => server/processor}/src/proto.rs (100%) diff --git a/Cargo.Bazel.lock b/Cargo.Bazel.lock index 2af9ed15c..75638f70c 100644 --- a/Cargo.Bazel.lock +++ b/Cargo.Bazel.lock @@ -1,5 +1,5 @@ { - "checksum": "e58a8c31f302eaa217b2af114fbc2f9d2d29d39fcbbf7f9359bc7ad807a2dac1", + "checksum": "e3af85829e49125de8a0e94f1307d882246338a08bb2c2f0e7c4fedfe9a6b66f", "crates": { "addr2line 0.20.0": { "name": "addr2line", @@ -1848,18 +1848,6 @@ ] } } - }, - { - "BuildScript": { - "crate_name": "build_script_build", - "crate_root": "build.rs", - "srcs": { - "allow_empty": false, - "include": [ - "**/*.rs" - ] - } - } } ], "library_target_name": "cras", @@ -1873,10 +1861,6 @@ "id": "anyhow 1.0.75", "target": "anyhow" }, - { - "id": "cras 0.1.1", - "target": "build_script_build" - }, { "id": "hound 3.5.0", "target": "hound" @@ -1899,24 +1883,6 @@ "edition": "2021", "version": "0.1.1" }, - "build_script_attrs": { - "data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "protobuf-codegen 3.2.0", - "target": "protobuf_codegen" - }, - { - "id": "protobuf-parse 3.2.0", - "target": "protobuf_parse" - } - ], - "selects": {} - } - }, "license": null, "license_ids": [], "license_file": null @@ -2262,6 +2228,84 @@ "license_ids": [], "license_file": null }, + "cras_processor 0.1.0": { + "name": "cras_processor", + "version": "0.1.0", + "package_url": null, + "repository": null, + "targets": [ + { + "Library": { + "crate_name": "cras_processor", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": false, + "include": [ + "**/*.rs" + ] + } + } + }, + { + "BuildScript": { + "crate_name": "build_script_build", + "crate_root": "build.rs", + "srcs": { + "allow_empty": false, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "cras_processor", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "deps": { + "common": [ + { + "id": "anyhow 1.0.75", + "target": "anyhow" + }, + { + "id": "cras_processor 0.1.0", + "target": "build_script_build" + }, + { + "id": "log 0.4.20", + "target": "log" + }, + { + "id": "protobuf 3.2.0", + "target": "protobuf" + } + ], + "selects": {} + }, + "edition": "2021", + "version": "0.1.0" + }, + "build_script_attrs": { + "data_glob": [ + "**" + ], + "deps": { + "common": [ + { + "id": "protobuf-codegen 3.2.0", + "target": "protobuf_codegen" + } + ], + "selects": {} + } + }, + "license": null, + "license_ids": [], + "license_file": null + }, "cras_rust 0.1.1": { "name": "cras_rust", "version": "0.1.1", @@ -11609,6 +11653,7 @@ "cras_dlc 0.1.0": "cras/server/platform/dlc", "cras_feature_tier 0.1.0": "cras/server/feature_tier", "cras_features_backend 0.1.0": "cras/server/platform/features", + "cras_processor 0.1.0": "cras/server/processor", "cras_rust 0.1.1": "cras/src/server/rust/staticlib", "cras_s2 0.1.0": "cras/server/s2", "dsp_rust 0.1.0": "cras/src/dsp/rust", diff --git a/Cargo.lock b/Cargo.lock index ae07590f8..41ce2c444 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -301,6 +301,7 @@ dependencies = [ "cras_dlc", "cras_feature_tier", "cras_features_backend", + "cras_processor", "cras_s2", "dsp_rust", "hound", @@ -383,6 +384,20 @@ dependencies = [ "tokio", ] +[[package]] +name = "cras_processor" +version = "0.1.0" +dependencies = [ + "anyhow", + "audio_processor", + "cras_common", + "cras_dlc", + "cras_s2", + "log", + "protobuf", + "protobuf-codegen", +] + [[package]] name = "cras_rust" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index d6a91dc9c..2b7ef048f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "cras/server/feature_tier", "cras/server/platform/dlc", "cras/server/platform/features", + "cras/server/processor", "cras/server/s2", "cras/src/dsp/rust", "cras/src/server/rust", @@ -28,6 +29,7 @@ cras_common = { path = "cras/common" } cras_dlc = { path = "cras/server/platform/dlc" } cras_features_backend = { path = "cras/server/platform/features" } cras_feature_tier = { path = "cras/server/feature_tier" } +cras_processor = { path = "cras/server/processor" } cras_s2 = { path = "cras/server/s2" } dsp_rust = { path = "cras/src/dsp/rust" } diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index bc468125c..0b0a13b6b 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -222,6 +222,7 @@ crates_repository( "//cras/server/feature_tier:Cargo.toml", "//cras/server/platform/dlc:Cargo.toml", "//cras/server/platform/features:Cargo.toml", + "//cras/server/processor:Cargo.toml", "//cras/src/dsp/rust:Cargo.toml", "//cras/src/server/rust:Cargo.toml", "//cras/src/server/rust:staticlib/Cargo.toml", diff --git a/build/write_source_files/write_source_file_targets_generated.bzl b/build/write_source_files/write_source_file_targets_generated.bzl index 0056a84ad..0fb20c50b 100644 --- a/build/write_source_files/write_source_file_targets_generated.bzl +++ b/build/write_source_files/write_source_file_targets_generated.bzl @@ -8,8 +8,8 @@ WRITE_SOURCE_FILE_TARGETS = [ "@//cras/common:generate_rust_common_h", "@//cras/server/feature_tier:generate_feature_tier_h", "@//cras/server/platform/dlc:generate_dlc_h", + "@//cras/server/processor:generate_processor_h", "@//cras/server/s2:generate_s2_h", "@//cras/src/dsp/rust:generate_dsp.h", - "@//cras/src/server/rust:generate_cras_processor_h", "@//cras/src/server/rust:generate_rate_estimator_h", ] diff --git a/cras/server/platform/dlc/BUILD.bazel b/cras/server/platform/dlc/BUILD.bazel index d7958a9e3..20b57ca1e 100644 --- a/cras/server/platform/dlc/BUILD.bazel +++ b/cras/server/platform/dlc/BUILD.bazel @@ -12,7 +12,7 @@ cras_rust_library( srcs = glob(include = ["src/*.rs"]), crate_name = "cras_dlc", visibility = [ - "//cras/server/platform:__pkg__", + "//cras/server:__subpackages__", "//cras/src/server/rust:__pkg__", ], deps = all_crate_deps() + [ diff --git a/cras/server/processor/BUILD.bazel b/cras/server/processor/BUILD.bazel new file mode 100644 index 000000000..32a719379 --- /dev/null +++ b/cras/server/processor/BUILD.bazel @@ -0,0 +1,76 @@ +# Copyright 2024 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +load("@crate_index//:defs.bzl", "all_crate_deps") +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") +load("@rules_rust//cargo:defs.bzl", "cargo_build_script") +load("@rules_rust//rust:defs.bzl", "rust_test") +load("//:utils.bzl", "require_no_config") +load("//rules/cbindgen:rules.bzl", "cras_cbindgen") +load("//rules/rust:defs.bzl", "cras_rust_library") + +cras_rust_library( + name = "processor", + srcs = glob( + include = ["src/**/*.rs"], + ), + crate_name = "cras_processor", + edition = "2021", + visibility = ["//visibility:public"], + deps = all_crate_deps(normal = True) + [ + "//audio_processor", + "//cras/server/s2", + "//cras/server/platform/dlc", + "//cras/common:rust_common", + ":build_script", + ], +) + +rust_test( + name = "processor_test", + crate = ":processor", + target_compatible_with = require_no_config("//:system_cras_rust_build"), +) + +cras_cbindgen( + name = "processor_h", + srcs = ["src/lib.rs"], + out = "processor.h", + copyright_year = 2024, + extra_args = [ + "--with-include=audio_processor/c/plugin_processor.h", + "--with-include=cras/common/rust_common.h", + "--add-keyword-enum", + ], +) + +cc_library( + name = "cc", + hdrs = ["processor.h"], + visibility = ["//visibility:public"], + deps = [ + ":processor", + "//audio_processor/c:plugin_processor", + "//cras/common:rust_common_cc", + ], +) + +cc_test( + name = "cras_processor_test", + srcs = ["cras_processor_test.cc"], + deps = [ + ":cc", + "@pkg_config//gtest", + "@pkg_config//gtest_main", + ], +) + +cargo_build_script( + name = "build_script", + srcs = ["build.rs"], + data = [ + "proto/cras_processor.proto", + ], + deps = all_crate_deps(build = True), +) diff --git a/cras/server/processor/Cargo.toml b/cras/server/processor/Cargo.toml new file mode 100644 index 000000000..f7a4d6352 --- /dev/null +++ b/cras/server/processor/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "cras_processor" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = { workspace = true } +log = { workspace = true } +protobuf = { workspace = true } + +audio_processor = { workspace = true } +cras_common = { workspace = true } +cras_dlc = { workspace = true } +cras_s2 = { workspace = true } + +[build-dependencies] +protobuf-codegen = { workspace = true } diff --git a/cras/src/server/rust/build.rs b/cras/server/processor/build.rs similarity index 100% rename from cras/src/server/rust/build.rs rename to cras/server/processor/build.rs diff --git a/cras/src/server/rust/cras_processor_test.cc b/cras/server/processor/cras_processor_test.cc similarity index 97% rename from cras/src/server/rust/cras_processor_test.cc rename to cras/server/processor/cras_processor_test.cc index f4e83ba16..6bae41687 100644 --- a/cras/src/server/rust/cras_processor_test.cc +++ b/cras/server/processor/cras_processor_test.cc @@ -5,7 +5,7 @@ #include #include "audio_processor/c/plugin_processor.h" -#include "cras/src/server/rust/include/cras_processor.h" +#include "cras/server/processor/processor.h" #include "gmock/gmock.h" #include "gtest/gtest.h" diff --git a/cras/src/server/rust/include/cras_processor.h b/cras/server/processor/processor.h similarity index 87% rename from cras/src/server/rust/include/cras_processor.h rename to cras/server/processor/processor.h index a130deeba..1c8f30ef7 100644 --- a/cras/src/server/rust/include/cras_processor.h +++ b/cras/server/processor/processor.h @@ -1,4 +1,4 @@ -// Copyright 2023 The ChromiumOS Authors +// Copyright 2024 The ChromiumOS Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,8 +9,8 @@ extern "C" { #endif -#ifndef CRAS_SRC_SERVER_RUST_INCLUDE_CRAS_PROCESSOR_H_ -#define CRAS_SRC_SERVER_RUST_INCLUDE_CRAS_PROCESSOR_H_ +#ifndef CRAS_SERVER_PROCESSOR_PROCESSOR_H_ +#define CRAS_SERVER_PROCESSOR_PROCESSOR_H_ #include #include @@ -59,7 +59,7 @@ struct CrasProcessorCreateResult cras_processor_create(const struct CrasProcesso */ bool cras_processor_is_override_enabled(void); -#endif /* CRAS_SRC_SERVER_RUST_INCLUDE_CRAS_PROCESSOR_H_ */ +#endif /* CRAS_SERVER_PROCESSOR_PROCESSOR_H_ */ #ifdef __cplusplus } diff --git a/cras/src/server/rust/proto/cras_processor.proto b/cras/server/processor/proto/cras_processor.proto similarity index 100% rename from cras/src/server/rust/proto/cras_processor.proto rename to cras/server/processor/proto/cras_processor.proto diff --git a/cras/src/server/rust/src/cras_processor.rs b/cras/server/processor/src/lib.rs similarity index 99% rename from cras/src/server/rust/src/cras_processor.rs rename to cras/server/processor/src/lib.rs index cedfe77aa..0d2c55590 100644 --- a/cras/src/server/rust/src/cras_processor.rs +++ b/cras/server/processor/src/lib.rs @@ -30,6 +30,7 @@ use cras_dlc::get_dlc_state_cached; use cras_s2::BEAMFORMING_CONFIG_PATH; mod processor_override; +mod proto; #[repr(C)] #[derive(Clone, Debug)] diff --git a/cras/src/server/rust/src/cras_processor/processor_override.rs b/cras/server/processor/src/processor_override.rs similarity index 100% rename from cras/src/server/rust/src/cras_processor/processor_override.rs rename to cras/server/processor/src/processor_override.rs diff --git a/cras/src/server/rust/src/proto.rs b/cras/server/processor/src/proto.rs similarity index 100% rename from cras/src/server/rust/src/proto.rs rename to cras/server/processor/src/proto.rs diff --git a/cras/src/server/BUILD.bazel b/cras/src/server/BUILD.bazel index d01f7ee4c..2eed8d390 100644 --- a/cras/src/server/BUILD.bazel +++ b/cras/src/server/BUILD.bazel @@ -659,6 +659,7 @@ cc_library( "//cras/server:main_message", "//cras/server/platform/dlc:cc", "//cras/server/platform/features", + "//cras/server/processor:cc", "//cras/server/s2:cc", "//cras/src/common", "//cras/src/dsp", diff --git a/cras/src/server/cras_stream_apm.c b/cras/src/server/cras_stream_apm.c index c129480f6..a7e3d1a32 100644 --- a/cras/src/server/cras_stream_apm.c +++ b/cras/src/server/cras_stream_apm.c @@ -15,6 +15,7 @@ #include "cras/server/cras_thread.h" #include "cras/server/main_message.h" #include "cras/server/platform/features/features.h" +#include "cras/server/processor/processor.h" #include "cras/server/s2/s2.h" #include "cras/src/common/byte_buffer.h" #include "cras/src/common/cras_string.h" @@ -30,7 +31,6 @@ #include "cras/src/server/cras_system_state.h" #include "cras/src/server/float_buffer.h" #include "cras/src/server/iniparser_wrapper.h" -#include "cras/src/server/rust/include/cras_processor.h" #include "cras_audio_format.h" #include "third_party/utlist/utlist.h" #include "webrtc_apm/webrtc_apm.h" diff --git a/cras/src/server/rust/BUILD.bazel b/cras/src/server/rust/BUILD.bazel index 9d41757c1..73dcb224d 100644 --- a/cras/src/server/rust/BUILD.bazel +++ b/cras/src/server/rust/BUILD.bazel @@ -3,8 +3,7 @@ # found in the LICENSE file. load("@crate_index//:defs.bzl", "all_crate_deps") -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@rules_rust//cargo:defs.bzl", "cargo_build_script") +load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_rust//rust:defs.bzl", "rust_test") load("//:utils.bzl", "require_no_config") load("//rules/cbindgen:rules.bzl", "cras_cbindgen") @@ -14,12 +13,12 @@ cras_rust_library( name = "rust", srcs = glob(include = ["src/**/*.rs"]), deps = [ - ":build_script", "//audio_processor", "//cras/common:rust_common", "//cras/server/platform/dlc", "//cras/server/platform/features:backend", "//cras/server/feature_tier", + "//cras/server/processor", "//cras/server/s2", "//cras/src/dsp/rust:dsp_rust", ] + all_crate_deps(), @@ -32,15 +31,6 @@ cc_library( deps = [":rust"], ) -cargo_build_script( - name = "build_script", - srcs = ["build.rs"], - data = [ - "proto/cras_processor.proto", - ], - deps = all_crate_deps(build = True), -) - rust_test( name = "test", crate = ":rust", @@ -50,29 +40,6 @@ rust_test( target_compatible_with = require_no_config("//:system_cras_rust_build"), ) -cc_test( - name = "cras_processor_test", - srcs = ["cras_processor_test.cc"], - deps = [ - ":cc", - "//audio_processor/c:plugin_processor", - "//cras/common:rust_common_cc", - "@pkg_config//gtest", - "@pkg_config//gtest_main", - ], -) - -cras_cbindgen( - name = "cras_processor_h", - srcs = ["src/cras_processor.rs"], - out = "include/cras_processor.h", - extra_args = [ - "--with-include=audio_processor/c/plugin_processor.h", - "--with-include=cras/common/rust_common.h", - "--add-keyword-enum", - ], -) - cras_cbindgen( name = "rate_estimator_h", srcs = [ diff --git a/cras/src/server/rust/Cargo.toml b/cras/src/server/rust/Cargo.toml index 6914e82ac..6fd52ceef 100644 --- a/cras/src/server/rust/Cargo.toml +++ b/cras/src/server/rust/Cargo.toml @@ -18,6 +18,7 @@ audio_processor = { workspace = true } cras_features_backend = { workspace = true } cras_s2 = { workspace = true } cras_feature_tier = { workspace = true } +cras_processor = { workspace = true } minijail = { workspace = true, optional = true } [build-dependencies] diff --git a/cras/src/server/rust/src/lib.rs b/cras/src/server/rust/src/lib.rs index 400c0c83e..964495c90 100644 --- a/cras/src/server/rust/src/lib.rs +++ b/cras/src/server/rust/src/lib.rs @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -pub mod cras_processor; pub use cras_common::logging; pub use cras_feature_tier; mod rate_estimator; @@ -11,7 +10,7 @@ pub use cras_common::fra; pub use cras_common::pseudonymization; pub use cras_dlc::bindings as cras_dlc_bindings; pub use cras_features_backend; -pub use logging::bindings as logging_bindings; -mod proto; +pub use cras_processor; pub use cras_s2; pub use dsp_rust; +pub use logging::bindings as logging_bindings; diff --git a/cras/src/tests/BUILD.bazel b/cras/src/tests/BUILD.bazel index f2cce3da2..a007e05c8 100644 --- a/cras/src/tests/BUILD.bazel +++ b/cras/src/tests/BUILD.bazel @@ -1969,6 +1969,7 @@ cc_test( "//cras/server:main_message", "//cras/server/platform/dlc:cc", "//cras/server/platform/features", + "//cras/server/processor:cc", "//cras/server/s2:cc", "//cras/src/common:all_headers", "//cras/src/dsp:all_headers",