Merge "aconfig: add create_flag_info cc api" into main am: 83066f6dc0
am: 87ce19046a
Original change: https://android-review.googlesource.com/c/platform/build/+/3024987 Change-Id: Ife0d3338984d453710e8c144ec6728ed35269d13 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
7faba1cdc4
6 changed files with 121 additions and 0 deletions
|
@ -12,6 +12,7 @@ rust_defaults {
|
|||
"libtempfile",
|
||||
"libprotobuf",
|
||||
"libclap",
|
||||
"libcxx",
|
||||
"libaconfig_storage_protos",
|
||||
],
|
||||
}
|
||||
|
@ -69,3 +70,46 @@ cc_library_static {
|
|||
],
|
||||
host_supported: true,
|
||||
}
|
||||
|
||||
// cxx source codegen from rust api
|
||||
genrule {
|
||||
name: "libcxx_aconfig_storage_file_bridge_code",
|
||||
tools: ["cxxbridge"],
|
||||
cmd: "$(location cxxbridge) $(in) > $(out)",
|
||||
srcs: ["src/lib.rs"],
|
||||
out: ["aconfig_storage/lib.rs.cc"],
|
||||
}
|
||||
|
||||
// cxx header codegen from rust api
|
||||
genrule {
|
||||
name: "libcxx_aconfig_storage_file_bridge_header",
|
||||
tools: ["cxxbridge"],
|
||||
cmd: "$(location cxxbridge) $(in) --header > $(out)",
|
||||
srcs: ["src/lib.rs"],
|
||||
out: ["aconfig_storage/lib.rs.h"],
|
||||
}
|
||||
|
||||
// a static cc lib based on generated code
|
||||
rust_ffi_static {
|
||||
name: "libaconfig_storage_file_cxx_bridge",
|
||||
crate_name: "aconfig_storage_file_cxx_bridge",
|
||||
host_supported: true,
|
||||
srcs: ["src/lib.rs"],
|
||||
defaults: ["aconfig_storage_file.defaults"],
|
||||
}
|
||||
|
||||
// flag storage file cc interface
|
||||
cc_library_static {
|
||||
name: "libaconfig_storage_file_cc",
|
||||
srcs: ["aconfig_storage_file.cpp"],
|
||||
generated_headers: [
|
||||
"cxx-bridge-header",
|
||||
"libcxx_aconfig_storage_file_bridge_header",
|
||||
],
|
||||
generated_sources: ["libcxx_aconfig_storage_file_bridge_code"],
|
||||
whole_static_libs: ["libaconfig_storage_file_cxx_bridge"],
|
||||
export_include_dirs: ["include"],
|
||||
static_libs: [
|
||||
"libbase",
|
||||
],
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ anyhow = "1.0.69"
|
|||
protobuf = "3.2.0"
|
||||
tempfile = "3.9.0"
|
||||
thiserror = "1.0.56"
|
||||
cxx = "1.0"
|
||||
clap = { version = "4.1.8", features = ["derive"] }
|
||||
|
||||
[[bin]]
|
||||
|
|
20
tools/aconfig/aconfig_storage_file/aconfig_storage_file.cpp
Normal file
20
tools/aconfig/aconfig_storage_file/aconfig_storage_file.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "rust/cxx.h"
|
||||
#include "aconfig_storage/lib.rs.h"
|
||||
#include "aconfig_storage/aconfig_storage_file.hpp"
|
||||
|
||||
namespace aconfig_storage {
|
||||
android::base::Result<void> create_flag_info(
|
||||
std::string const& package_map,
|
||||
std::string const& flag_map,
|
||||
std::string const& flag_info_out) {
|
||||
auto creation_cxx = create_flag_info_cxx(
|
||||
rust::Str(package_map.c_str()),
|
||||
rust::Str(flag_map.c_str()),
|
||||
rust::Str(flag_info_out.c_str()));
|
||||
if (creation_cxx.success) {
|
||||
return {};
|
||||
} else {
|
||||
return android::base::Error() << creation_cxx.error_message;
|
||||
}
|
||||
}
|
||||
} // namespace aconfig_storage
|
|
@ -14,4 +14,7 @@ fn main() {
|
|||
.inputs(proto_files)
|
||||
.cargo_out_dir("aconfig_storage_protos")
|
||||
.run_from_script();
|
||||
|
||||
let _ = cxx_build::bridge("src/lib.rs");
|
||||
println!("cargo:rerun-if-changed=src/lib.rs");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <android-base/result.h>
|
||||
|
||||
namespace aconfig_storage {
|
||||
/// Create flag info file based on package and flag map
|
||||
/// \input package_map: package map file
|
||||
/// \input flag_map: flag map file
|
||||
/// \input flag_info_out: flag info file to be created
|
||||
android::base::Result<void> create_flag_info(
|
||||
std::string const& package_map,
|
||||
std::string const& flag_map,
|
||||
std::string const& flag_info_out);
|
||||
} // namespace aconfig_storage
|
|
@ -332,6 +332,43 @@ pub fn create_flag_info(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// *************************************** //
|
||||
// CC INTERLOP
|
||||
// *************************************** //
|
||||
#[cxx::bridge]
|
||||
mod ffi {
|
||||
pub struct FlagInfoCreationCXX {
|
||||
pub success: bool,
|
||||
pub error_message: String,
|
||||
}
|
||||
|
||||
extern "Rust" {
|
||||
pub fn create_flag_info_cxx(
|
||||
package_map: &str,
|
||||
flag_map: &str,
|
||||
flag_info_out: &str,
|
||||
) -> FlagInfoCreationCXX;
|
||||
}
|
||||
}
|
||||
|
||||
/// Create flag info file cc interlop
|
||||
pub fn create_flag_info_cxx(
|
||||
package_map: &str,
|
||||
flag_map: &str,
|
||||
flag_info_out: &str,
|
||||
) -> ffi::FlagInfoCreationCXX {
|
||||
match create_flag_info(package_map, flag_map, flag_info_out) {
|
||||
Ok(()) => ffi::FlagInfoCreationCXX {
|
||||
success: true,
|
||||
error_message: String::from(""),
|
||||
},
|
||||
Err(errmsg) => ffi::FlagInfoCreationCXX {
|
||||
success: false,
|
||||
error_message: format!("{:?}", errmsg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue