author | unC0Rr |
Tue, 10 Sep 2024 13:56:51 +0200 | |
branch | transitional_engine |
changeset 16032 | 31cc1e450273 |
parent 15893 | 5b3beb90e1a6 |
permissions | -rw-r--r-- |
15893
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
1 |
extern crate cbindgen; |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
2 |
|
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
3 |
use cbindgen::Config; |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
4 |
use std::env; |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
5 |
use std::path::PathBuf; |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
6 |
|
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
7 |
fn main() { |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
8 |
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
9 |
|
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
10 |
let package_name = env::var("CARGO_PKG_NAME").unwrap(); |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
11 |
let output_file = target_dir() |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
12 |
.join(format!("{}.hpp", package_name)) |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
13 |
.display() |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
14 |
.to_string(); |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
15 |
|
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
16 |
let config = Config { |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
17 |
namespace: Some(String::from("hwengine")), |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
18 |
..Default::default() |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
19 |
}; |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
20 |
|
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
21 |
cbindgen::generate_with_config(&crate_dir, config) |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
22 |
.unwrap() |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
23 |
.write_to_file(&output_file); |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
24 |
} |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
25 |
|
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
26 |
fn target_dir() -> PathBuf { |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
27 |
if let Ok(target) = env::var("CARGO_TARGET_DIR") { |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
28 |
PathBuf::from(target) |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
29 |
} else { |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
30 |
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("target") |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
31 |
} |
5b3beb90e1a6
Implement generation of c header from rust interface, adapt qmlfrontend
unC0Rr
parents:
diff
changeset
|
32 |
} |