Make cxx binding generate less code

This commit is contained in:
topjohnwu
2025-08-29 01:44:06 -07:00
parent d472e9c36e
commit 653730d75e
7 changed files with 12 additions and 7 deletions

View File

@@ -7,7 +7,6 @@ LOCAL_MODULE := libbase
LOCAL_C_INCLUDES := \ LOCAL_C_INCLUDES := \
src/include \ src/include \
$(LOCAL_PATH)/include \ $(LOCAL_PATH)/include \
src/external/cxx-rs/include \
out/generated out/generated
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_EXPORT_STATIC_LIBRARIES := libcxx LOCAL_EXPORT_STATIC_LIBRARIES := libcxx

View File

@@ -0,0 +1 @@
../../../external/cxx-rs/include/cxx.h

View File

@@ -5,7 +5,7 @@
#include <functional> #include <functional>
#include <string_view> #include <string_view>
#include <bitset> #include <bitset>
#include <cxx.h> #include <rust/cxx.h>
#include "xwrap.hpp" #include "xwrap.hpp"

View File

@@ -3,7 +3,7 @@
#include <cstdint> #include <cstdint>
#include <utility> #include <utility>
#include <bitset> #include <bitset>
#include <cxx.h> #include <rust/cxx.h>
/****************** /******************
* Special Headers * Special Headers

View File

@@ -2,7 +2,7 @@
#include <functional> #include <functional>
#include <cxx.h> #include <rust/cxx.h>
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */

View File

@@ -6,7 +6,7 @@ use std::io::Write;
use std::path::Path; use std::path::Path;
use std::{fs, io, process}; use std::{fs, io, process};
use cxx_gen::Opt; use cxx_gen::{Include, IncludeKind, Opt};
trait ResultExt<T> { trait ResultExt<T> {
fn ok_or_exit(self) -> T; fn ok_or_exit(self) -> T;
@@ -38,7 +38,12 @@ fn write_if_diff<P: AsRef<Path>>(path: P, bytes: &[u8]) -> io::Result<()> {
pub fn gen_cxx_binding(name: &str) { pub fn gen_cxx_binding(name: &str) {
println!("cargo:rerun-if-changed=lib.rs"); println!("cargo:rerun-if-changed=lib.rs");
let opt = Opt::default(); let mut opt = Opt::default();
opt.cxx_impl_annotations = Some("[[gnu::always_inline]]".to_string());
opt.include.push(Include {
path: "rust/cxx.h".to_string(),
kind: IncludeKind::Bracketed,
});
let code = cxx_gen::generate_header_and_cc_with_path("lib.rs", &opt); let code = cxx_gen::generate_header_and_cc_with_path("lib.rs", &opt);
write_if_diff(format!("{name}.cpp"), code.implementation.as_slice()).ok_or_exit(); write_if_diff(format!("{name}.cpp"), code.implementation.as_slice()).ok_or_exit();
write_if_diff(format!("{name}.hpp"), code.header.as_slice()).ok_or_exit(); write_if_diff(format!("{name}.hpp"), code.header.as_slice()).ok_or_exit();

View File

@@ -4,7 +4,7 @@
#include <map> #include <map>
#include <string_view> #include <string_view>
#include <cxx.h> #include <rust/cxx.h>
#include <sepol/policydb/policydb.h> #include <sepol/policydb/policydb.h>