Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae9f652b authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Floss: Add protobuf build to btmanagerd

Prepares build system to support protobuf with powerd D-Bus integration.

Bug: 224606285
Tag: #floss
Test: Manual - build.py

Change-Id: I9b701a84d11dde3ed9414711a371707106f28b57
parent dc2a40bb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -246,6 +246,7 @@ class HostBuild():
        self.env['CARGO_HOME'] = os.path.join(self.output_dir, 'cargo_home')
        self.env['RUSTFLAGS'] = self._generate_rustflags()
        self.env['CXX_ROOT_PATH'] = os.path.join(self.platform_dir, 'bt')
        self.env['CROS_SYSTEM_API_ROOT'] = os.path.join(self.platform_dir, 'system_api')

    def run_command(self, target, args, cwd=None, env=None):
        """ Run command and stream the output.
@@ -606,6 +607,7 @@ class Bootstrap():
        # Symlink things
        symlinks = [
            (os.path.join(self.git_dir, 'platform2', 'common-mk'), os.path.join(self.staging_dir, 'common-mk')),
            (os.path.join(self.git_dir, 'platform2', 'system_api'), os.path.join(self.staging_dir, 'system_api')),
            (os.path.join(self.git_dir, 'platform2', '.gn'), os.path.join(self.staging_dir, '.gn')),
            (os.path.join(self.bt_dir), os.path.join(self.staging_dir, 'bt')),
            (os.path.join(self.git_dir, 'rust_crates'), os.path.join(self.external_dir, 'rust')),
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ futures = "0.3.13"
inotify = "*"
log = "0.4.14"
nix = "*"
protobuf = "2.0"
regex = "1.5"
serde_json = "1.0"
syslog = "4.0"
@@ -28,6 +29,7 @@ tokio = { version = "1.0", features = ["fs", "macros", "rt-multi-thread", "sync"

[build-dependencies]
pkg-config = "0.3.19"
protoc-rust = "*"

[[bin]]
name = "btmanagerd"
+46 −0
Original line number Diff line number Diff line
extern crate protoc_rust;

use pkg_config::Config;
use std::env;
use std::fs;
use std::io::Write;
use std::path::{Path, PathBuf};

fn paths_to_strs<P: AsRef<Path>>(paths: &[P]) -> Vec<&str> {
    paths.iter().map(|p| p.as_ref().as_os_str().to_str().unwrap()).collect()
}

// Generate mod.rs files for given input files.
fn gen_mod_rs<P: AsRef<Path>>(out_dir: PathBuf, inputs: &[P]) {
    // Will panic if file doesn't exist or it can't create it
    let mut f = fs::File::create(out_dir.join("mod.rs")).unwrap();

    f.write_all(b"// Generated by build.rs\n\n").unwrap();

    for i in 0..inputs.len() {
        let stem = inputs[i].as_ref().file_stem().unwrap();
        f.write_all(format!("pub mod {}; \n", stem.to_str().unwrap()).as_bytes()).unwrap();
    }
}

fn main() {
    let target_dir = std::env::var_os("CARGO_TARGET_DIR").unwrap();
@@ -9,4 +32,27 @@ fn main() {
    // libdir and fixes the build issues.
    Config::new().probe("dbus-1").unwrap();
    println!("cargo:rerun-if-changed=build.rs");

    let system_api_root = PathBuf::from(std::env::var_os("CROS_SYSTEM_API_ROOT").unwrap());

    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    let proto_out_dir = out_dir.join("proto_out");
    let proto_input_files = [system_api_root.join("dbus/power_manager/suspend.proto")];
    let proto_include_dirs = [system_api_root.clone()];

    // Make sure to create the output directories before using it
    match fs::create_dir(proto_out_dir.as_os_str().to_str().unwrap()) {
        Err(e) => println!("Proto dir failed to be created: {}", e),
        _ => (),
    };

    protoc_rust::Codegen::new()
        .out_dir(proto_out_dir.as_os_str().to_str().unwrap())
        .inputs(&paths_to_strs(&proto_input_files))
        .includes(&paths_to_strs(&proto_include_dirs))
        .customize(Default::default())
        .run()
        .expect("Failed to run protoc");

    gen_mod_rs(proto_out_dir, &proto_input_files);
}
+4 −0
Original line number Diff line number Diff line
pub mod iface_bluetooth_manager;

// protoc-rust generates all modules and exports them in mod.rs
// We have to include them all here to make them available for crate export.
include!(concat!(env!("OUT_DIR"), "/proto_out/mod.rs"));