Skip to content

Commit

Permalink
Add cras_rust_library to automatically select bazel or system cras_rust
Browse files Browse the repository at this point in the history
The new pattern is:
1.  Rust crates use cras_rust_library
2.  If the rust package happens to have C headers, create
    a cc_library to wrap the cras_rust_library and add hdrs
    to it.

This is done so that:
1.  If a cc_library only depends on a small crate, it doesn't have
    to depend the full //cras/src/server/rust.
2.  Allows moving the headers for Rust crates to be alongside
    their sources.

Also move @pkg_config//dbus-1 to a better location.

BUG=b:314126577
TEST=CQ

Change-Id: Id398d12cf4af7b8685f29511327fc060f19849d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5216247
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com <chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com>
Commit-Queue: Li-Yu Yu <aaronyu@google.com>
  • Loading branch information
afq984 authored and Chromeos LUCI committed Jan 19, 2024
1 parent 2a4a333 commit aee3a37
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 106 deletions.
1 change: 1 addition & 0 deletions cras/server/platform/dlc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rust_library(
visibility = ["//cras/src/server/rust:__pkg__"],
deps = all_crate_deps() + [
"//cras/server/s2",
"@pkg_config//dbus-1",
],
# TODO: Enable "dlc" feature based on //:dlc_build
)
2 changes: 1 addition & 1 deletion cras/server/platform/features/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cc_library(
deps = [
"//cras/common:check",
"//cras/server:main_message",
"//cras/src/server/rust",
"//cras/src/server/rust:cc",
],
)

Expand Down
2 changes: 1 addition & 1 deletion cras/src/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ cc_library(
"//cras/src/tests:__pkg__",
],
deps = [
"//cras/src/server/rust",
"//cras/src/server/rust:cc",
],
)

Expand Down
6 changes: 3 additions & 3 deletions cras/src/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ cc_library(
":ewma_power",
"//cras/server/platform/features",
"//cras/src/common",
"//cras/src/server/rust",
"//cras/src/server/rust:cc",
] + select({
"//:ml_build": ["//cras/src/dsp:am"],
"//conditions:default": [],
Expand Down Expand Up @@ -503,7 +503,7 @@ cc_library(
"//cras/src/dsp",
"//cras/src/plc",
"//cras/src/server/config",
"//cras/src/server/rust",
"//cras/src/server/rust:cc",
"@pkg_config//alsa",
"@pkg_config//dbus-1",
"@pkg_config//libudev",
Expand Down Expand Up @@ -550,7 +550,7 @@ cc_library(
"//cras/server/platform/features",
"//cras/src/common",
"//cras/src/dsp",
"//cras/src/server/rust",
"//cras/src/server/rust:cc",
] + select({
"//:apm_build": ["@webrtc_apm//webrtc_apm"],
"//conditions:default": [],
Expand Down
39 changes: 15 additions & 24 deletions cras/src/server/rust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,14 @@
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_library", "rust_test")
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")

cc_library(
cras_rust_library(
name = "rust",
hdrs = glob(include = ["include/*.h"]),
visibility = ["//visibility:public"],
deps = select({
"//:system_cras_rust_build": [
"//cras/src/server/rust/system_cras_rust",
],
"//conditions:default": [
":lib",
],
}) + [
"@pkg_config//dbus-1",
],
)

rust_library(
name = "lib",
srcs = glob(include = ["src/**/*.rs"]),
target_compatible_with = require_no_config("//:system_cras_rust_build"),
deps = [
":build_script",
"//audio_processor",
Expand All @@ -39,6 +23,13 @@ rust_library(
] + all_crate_deps(),
)

cc_library(
name = "cc",
hdrs = glob(include = ["include/*.h"]),
visibility = ["//visibility:public"],
deps = [":rust"],
)

cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
Expand All @@ -50,7 +41,7 @@ cargo_build_script(

rust_test(
name = "test",
crate = ":lib",
crate = ":rust",
tags = [
"tsan-broken",
],
Expand All @@ -61,7 +52,7 @@ cc_test(
name = "cras_processor_test",
srcs = ["cras_processor_test.cc"],
deps = [
":rust",
":cc",
"//audio_processor/c:plugin_processor",
"@pkg_config//gtest",
"@pkg_config//gtest_main",
Expand All @@ -72,7 +63,7 @@ cc_test(
name = "pseudonymization_test",
srcs = ["pseudonymization_test.cc"],
deps = [
":rust",
":cc",
"@pkg_config//gtest",
"@pkg_config//gtest_main",
],
Expand All @@ -82,7 +73,7 @@ cc_test(
name = "pseudonymization_none_test",
srcs = ["pseudonymization_none_test.cc"],
deps = [
":rust",
":cc",
"@pkg_config//gtest",
"@pkg_config//gtest_main",
],
Expand All @@ -92,7 +83,7 @@ cc_test(
name = "cras_fra_test",
srcs = ["cras_fra_test.cc"],
deps = [
":rust",
":cc",
"@pkg_config//gtest",
"@pkg_config//gtest_main",
],
Expand Down
4 changes: 4 additions & 0 deletions cras/src/server/rust/system_cras_rust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

load("@rules_cc//cc:defs.bzl", "cc_import")
load("@rules_python//python:defs.bzl", "py_binary")

"""This package holds the magic to find libcras_rust.a as the way
the compiler does and list it explicitly in the dependency.
Expand All @@ -26,6 +29,7 @@ cc_import(
target_compatible_with = require_config("//:system_cras_rust_build"),
visibility = ["//cras/src/server/rust:__pkg__"],
deps = [
"@pkg_config//dbus-1",
"@pkg_config//openssl",
"@pkg_config//speexdsp",
] + select({
Expand Down
Loading

0 comments on commit aee3a37

Please sign in to comment.