Update cbindgen, generate a single C/C++ header

This commit is contained in:
Oliver Hamlet
2019-06-30 11:25:24 +01:00
parent 954757a141
commit 93b16a4c2a
5 changed files with 10 additions and 13 deletions
+2 -2
View File
@@ -35,13 +35,13 @@ To generate a C++ header file as part of the build, instead run:
cargo build --release --package loot-condition-interpreter-ffi --all-features cargo build --release --package loot-condition-interpreter-ffi --all-features
``` ```
This will create a file at `ffi/include/loot_condition_interpreter.hpp`. This will create a file at `ffi/include/loot_condition_interpreter.h`.
However, this involves building [cbindgen](https://github.com/eqrion/cbindgen) However, this involves building [cbindgen](https://github.com/eqrion/cbindgen)
as a dependency, which is relatively slow. If you have cbindgen installed as a dependency, which is relatively slow. If you have cbindgen installed
separately, it's faster to generate the headers using its CLI: separately, it's faster to generate the headers using its CLI:
``` ```
cbindgen ffi/ -l c++ -o ffi/include/loot_condition_interpreter.hpp cbindgen ffi/ -o ffi/include/loot_condition_interpreter.h
``` ```
## Tests & Benchmarks ## Tests & Benchmarks
+1 -1
View File
@@ -19,4 +19,4 @@ default = []
ffi-headers = ["cbindgen"] ffi-headers = ["cbindgen"]
[build-dependencies] [build-dependencies]
cbindgen = { version = "0.6", optional = true } cbindgen = { version = "0.9", optional = true }
+4 -9
View File
@@ -5,8 +5,7 @@ mod ffi_headers {
use std::env; use std::env;
use std::fs; use std::fs;
use self::cbindgen::Builder; use self::cbindgen::generate;
use self::cbindgen::Language;
pub fn generate_headers() { pub fn generate_headers() {
let crate_dir = env::var("CARGO_MANIFEST_DIR") let crate_dir = env::var("CARGO_MANIFEST_DIR")
@@ -14,13 +13,9 @@ mod ffi_headers {
fs::create_dir_all("include").expect("could not create include directory"); fs::create_dir_all("include").expect("could not create include directory");
Builder::new() generate(&crate_dir)
.with_crate(&crate_dir) .expect("could not generate C/C++ header file")
.with_language(Language::Cxx) .write_to_file("include/loot_condition_interpreter.h");
.with_std_types(false)
.generate()
.expect("could not generate C++ header file")
.write_to_file("include/loot_condition_interpreter.hpp");
} }
} }
+2
View File
@@ -0,0 +1,2 @@
language = "C"
cpp_compat = true
+1 -1
View File
@@ -8,7 +8,7 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include "loot_condition_interpreter.hpp" #include "loot_condition_interpreter.h"
void test_game_id_values() { void test_game_id_values() {
printf("testing LCI_GAME_* values...\n"); printf("testing LCI_GAME_* values...\n");