Skip to content

Commit 83f3ba1

Browse files
committed
Add rust binaries to link with C++ staticlib
Rather than using C++ binaries to link with Rust staticlib, we do it the other way around. This allows us to write our dbus frontend with Rust instead. Bug: 179821440 Tag: #floss Test: atest --host bluetooth_test_gd Change-Id: I63037e0aaea152a4855e0a49971c1b2f9c312ac5
1 parent d1895ce commit 83f3ba1

File tree

14 files changed

+230
-52
lines changed

14 files changed

+230
-52
lines changed

BUILD.gn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ group("all") {
3232
group("bluetooth") {
3333
deps = [
3434
"//bt/main:bluetooth",
35-
"//bt/service:bluetoothtbd",
35+
"//bt/main:bluetooth-static",
36+
#"//bt/service:bluetoothtbd",
3637
]
3738
}
3839

Cargo.toml

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,10 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
[package]
17-
name = "bt_shim_ffi"
18-
version = "0.0.1"
19-
edition = "2018"
16+
[workspace]
2017

21-
[dependencies]
22-
# BT dependencies
23-
bt_common = { path = "gd/rust/common" }
24-
bt_facade_helpers = { path = "gd/rust/facade" }
25-
bt_hal = { path = "gd/rust/hal" }
26-
bt_hci = { path = "gd/rust/hci" }
27-
bt_main = { path = "gd/rust/main" }
28-
bt_packets = { path = "gd/rust/packets" }
29-
30-
# All external dependencies. Keep all versions at build/rust/Cargo.toml
31-
bindgen = "0.51"
32-
bytes = "1.0"
33-
cxx = { version = "0.5.9", features = ["c++17"] }
34-
env_logger = "0.8"
35-
futures = "0.3"
36-
grpcio = { version = "0.7", features = ["protobuf", "protobuf-codec", "openssl"] }
37-
grpcio-sys = { version = "*", features = ["openssl"] }
38-
lazy_static = "1.4"
39-
log = "0.4"
40-
nix = "0.19"
41-
num-derive = "0.3"
42-
num-traits = "0.2"
43-
paste = "1.0"
44-
proc-macro2 = "1.0.24"
45-
protobuf = "2.0"
46-
protoc-grpcio = "2.0"
47-
protoc-rust = "2.0"
48-
quote = "1.0.8"
49-
thiserror = "1.0"
50-
syn = { version = "1.0.58", features = ['default', 'full'] }
51-
tokio = { version = "1.0", features = ['bytes', 'fs', 'io-util', 'libc', 'macros', 'memchr', 'mio', 'net', 'num_cpus', 'rt', 'rt-multi-thread', 'sync', 'time', 'tokio-macros'] }
52-
tokio-stream = "0.1"
53-
walkdir = "2.2"
54-
55-
56-
[lib]
57-
path = "gd/rust/shim/src/lib.rs"
58-
crate-type = ["staticlib"]
18+
members = [
19+
"gd/rust/shim",
20+
"gd/rust/linux/mgmt",
21+
"gd/rust/linux/adapter",
22+
]

system/gd/rust/facade/Cargo.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515

1616
[package]
17-
name = "bt_facade_helpers"
17+
name = "bluetooth_with_facades"
1818
version = "0.0.1"
1919
edition = "2018"
2020

@@ -32,6 +32,17 @@ log = "*"
3232
protobuf = "*"
3333
tokio = "*"
3434

35+
# Binary-only deps
36+
clap = "*"
37+
lazy_static = "*"
38+
nix = "*"
39+
bt_common = { path = "../common" }
40+
41+
42+
[[bin]]
43+
name = "bluetooth_with_facades"
44+
path = "src/main.rs"
45+
3546
[lib]
36-
path = "helpers/lib.rs"
47+
path = "src/lib.rs"
3748
crate-type = ["rlib"]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Copyright 2021 Google, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at:
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
[package]
17+
name = "bt_facade_helpers"
18+
version = "0.0.1"
19+
edition = "2018"
20+
21+
[dependencies]
22+
# GD bluetooth deps
23+
bt_facade_proto = { path = "../../facade_proto" }
24+
bt_packets = { path = "../../packets" }
25+
26+
# External deps
27+
bytes = "*"
28+
cxx = "*"
29+
futures = "*"
30+
grpcio = "*"
31+
log = "*"
32+
protobuf = "*"
33+
tokio = "*"
34+
35+
[lib]
36+
path = "lib.rs"
37+
crate-type = ["rlib"]
38+

system/gd/rust/hal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ edition = "2018"
2121
[dependencies]
2222
# BT dependencies
2323
bt_common = { path = "../common" }
24-
bt_facade_helpers = { path = "../facade" }
24+
bt_facade_helpers = { path = "../facade/helpers" }
2525
bt_facade_proto = { path = "../facade_proto" }
2626
bt_packets = { path = "../packets" }
2727
gddi = { path = "../gddi" }

system/gd/rust/hci/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ edition = "2018"
2323
bt_common = { path = "../common" }
2424
bt_hci_custom_types = { path = "custom_types" }
2525
bt_hal = { path = "../hal" }
26-
bt_facade_helpers = { path = "../facade" }
26+
bt_facade_helpers = { path = "../facade/helpers" }
2727
bt_facade_proto = { path = "../facade_proto" }
2828
bt_packets = { path = "../packets" }
2929
gddi = { path = "../gddi" }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright 2021 Google, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at:
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
[package]
17+
name = "bluetooth"
18+
version = "0.0.1"
19+
edition = "2018"
20+
21+
[dependencies]
22+
# BT dependencies
23+
bt_shim = { path = "../../shim" }
24+
25+
[build-dependencies]
26+
pkg-config = "0.3"
27+
28+
[[bin]]
29+
name = "bluetoothd"
30+
path = "src/main.rs"
31+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use pkg_config::Config;
2+
3+
fn main() {
4+
// The main linking point with c++ code is the libbluetooth-static.a
5+
// These includes all the symbols built via C++ but doesn't include other
6+
// links (i.e. pkg-config)
7+
println!("cargo:rustc-link-lib=static=bluetooth-static");
8+
9+
// A few dynamic links
10+
println!("cargo:rustc-link-lib=dylib=flatbuffers");
11+
println!("cargo:rustc-link-lib=dylib=protobuf");
12+
println!("cargo:rustc-link-lib=dylib=resolv");
13+
14+
// Clang requires -lc++ instead of -lstdc++
15+
println!("cargo:rustc-link-lib=c++");
16+
17+
// A few more dependencies from pkg-config. These aren't included as part of
18+
// the libbluetooth-static.a
19+
Config::new().probe("libchrome").unwrap();
20+
Config::new().probe("libmodp_b64").unwrap();
21+
Config::new().probe("tinyxml2").unwrap();
22+
23+
println!("cargo:rerun-if-changed=build.rs");
24+
println!("cargo:rerun-if-changed=libbluetooth-static.a");
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern crate bt_shim;
2+
3+
fn main() {
4+
println!("Bluetooth Adapter Daemon");
5+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright 2021 Google, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at:
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
[package]
17+
name = "btmgmt"
18+
version = "0.0.1"
19+
edition = "2018"
20+
21+
[[bin]]
22+
name = "btmgmtd"
23+
path = "src/main.rs"
24+

0 commit comments

Comments
 (0)