Generate cxx binding in build.rs

This commit is contained in:
topjohnwu
2023-05-19 15:16:54 -07:00
parent 57bd450798
commit 2bcf2e76f1
27 changed files with 169 additions and 49 deletions

View File

@@ -9,6 +9,7 @@ path = "lib.rs"
[build-dependencies]
protobuf-codegen = "3.2.0"
cxx-gen = { path = "../external/cxx-rs/gen/lib" }
[dependencies]
base = { path = "../base" }

View File

@@ -1,5 +1,10 @@
use protobuf_codegen::Customize;
use crate::gen::gen_cxx_binding;
#[path = "../base/gen.rs"]
mod gen;
fn main() {
println!("cargo:rerun-if-changed=update_metadata.proto");
protobuf_codegen::Codegen::new()
@@ -9,4 +14,6 @@ fn main() {
.customize(Customize::default().gen_mod_rs(false))
.out_dir(".")
.run_from_script();
gen_cxx_binding("boot-rs");
}

View File

@@ -9,6 +9,7 @@ mod update_metadata;
#[cxx::bridge(namespace = "rust")]
pub mod ffi {
extern "C++" {
include!("compress.hpp");
pub unsafe fn decompress(in_: *const u8, in_size: u64, fd: i32) -> bool;
}

View File

@@ -2,6 +2,8 @@
#include <sys/types.h>
#include "boot-rs.hpp"
#define HEADER_FILE "header"
#define KERNEL_FILE "kernel"
#define RAMDISK_FILE "ramdisk.cpio"

View File

@@ -4,8 +4,6 @@
#include "magiskboot.hpp"
#include "compress.hpp"
#include "boot-rs.cpp"
using namespace std;
static void print_formats() {