Commit 55df1faf authored by Yonggang Luo's avatar Yonggang Luo
Browse files

The gen procedure are lowring down

sync it
parent b8b35bdd
......@@ -35,5 +35,12 @@ The motivation for this project is:
## Developing
```
cargo install --force cargo-make
cargo make
```
\ No newline at end of file
```
Build debug version
```
cargo make build
```
Build release version
```
cargo make build --profile production
```
extern crate cbindgen;
extern crate cc;
use cc;
use std::{env, fs, fs::DirEntry, path::Path};
// include src/header directories that don't start with '_'
fn include_dir(d: &DirEntry) -> bool {
d.metadata().map(|m| m.is_dir()).unwrap_or(false)
&& d.path()
.iter()
.nth(2)
.map_or(false, |c| c.to_str().map_or(false, |x| !x.starts_with("_")))
}
fn generate_bindings(cbindgen_config_path: &Path) {
let relative_path = cbindgen_config_path
.strip_prefix("src/header")
.ok()
.and_then(|p| p.parent())
.and_then(|p| p.to_str())
.unwrap()
.replace("_", "/");
let header_path = Path::new("target/include")
.join(&relative_path)
.with_extension("h");
let mod_path = cbindgen_config_path.with_file_name("mod.rs");
let config = cbindgen::Config::from_file(cbindgen_config_path).unwrap();
cbindgen::Builder::new()
.with_config(config)
.with_src(mod_path)
.generate()
.expect("Unable to generate bindings")
.write_to_file(header_path);
}
use std::{env, fs};
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
// Generate C includes
// - based on contents of src/header/**
// - headers written to target/include
fs::read_dir(&Path::new("src/header"))
.unwrap()
.into_iter()
.filter_map(Result::ok)
.filter(|d| include_dir(d))
.map(|d| d.path().as_path().join("cbindgen.toml"))
.filter(|p| p.exists())
.for_each(|p| {
println!("cargo:rerun-if-changed={:?}", p.parent().unwrap());
println!("cargo:rerun-if-changed={:?}", p);
println!("cargo:rerun-if-changed={:?}", p.with_file_name("mod.rs"));
generate_bindings(&p);
});
let mut build = cc::Build::new();
let compiler = build.get_compiler();
if compiler.is_like_msvc() {
......
git submodule update --init
cd deps/rust
git submodule update --progress --init -- "library/backtrace"
git submodule update --progress --init -- "library/stdarch"
echo done
#!/bin/sh
set -e
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
git submodule add $url $path || true
done
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment