Skip to content

Commit 9e12879

Browse files
authored
refactor: c header fixes for cyclical dep & example (#84)
1 parent 480779a commit 9e12879

File tree

11 files changed

+1000
-1055
lines changed

11 files changed

+1000
-1055
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"files.associations": {
3+
".fantomasignore": "ignore",
34
"__locale": "c",
45
"__config": "c",
5-
"unistd.h": "c"
6+
"unistd.h": "c",
7+
"typeinfo": "c",
8+
"dojo.h": "c"
69
},
710
"rust-analyzer.linkedProjects": [
811
"./Cargo.toml"

Cargo.lock

Lines changed: 12 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ instant = { version = "0.1.13", features = ["wasm-bindgen"] }
4949
gloo-timers = { version = "0.3.0", features = ["futures"] }
5050

5151
[build-dependencies]
52-
cbindgen = "0.26.0"
52+
# this addresses issue with cyclical dependencies when generating C header
53+
# see. https://github.com/mozilla/cbindgen/issues/43
54+
cbindgen = { git = "https://github.com/masnagam/cbindgen", branch = "fix-issue-43" }

build.rs

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
use std::collections::HashMap;
21
use std::env;
32

43
fn main() {
54
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
65

76
cbindgen::Builder::new()
87
.with_config({
9-
let mut config = cbindgen::Config::default();
10-
11-
config.language = cbindgen::Language::C;
12-
config.braces = cbindgen::Braces::SameLine;
13-
config.cpp_compat = true;
14-
config.style = cbindgen::Style::Both;
15-
config.layout = cbindgen::LayoutConfig { ..Default::default() };
16-
config.enumeration = cbindgen::EnumConfig {
17-
derive_helper_methods: true,
18-
// prefix_with_name: true,
19-
..Default::default()
20-
};
21-
config.export = cbindgen::ExportConfig {
22-
mangle: cbindgen::MangleConfig { remove_underscores: true, ..Default::default() },
8+
let mut config = cbindgen::Config {
9+
language: cbindgen::Language::C,
10+
braces: cbindgen::Braces::SameLine,
11+
cpp_compat: true,
12+
style: cbindgen::Style::Both,
13+
layout: cbindgen::LayoutConfig { ..Default::default() },
14+
enumeration: cbindgen::EnumConfig {
15+
derive_helper_methods: true,
16+
// prefix_with_name: true,
17+
..Default::default()
18+
},
19+
export: cbindgen::ExportConfig {
20+
mangle: cbindgen::MangleConfig {
21+
remove_underscores: true,
22+
..Default::default()
23+
},
24+
..Default::default()
25+
},
26+
namespace: Some("dojo_bindings".to_string()),
2327
..Default::default()
2428
};
2529

26-
config.defines = HashMap::new();
27-
// config.defines.insert("target_arch = wasm32".to_string(),
28-
// "TARGET_WASM32".to_string());
2930
config.defines.insert(
3031
"target_pointer_width = 32".to_string(),
3132
"TARGET_POINTER_WIDTH_32".to_string(),
@@ -40,27 +41,27 @@ fn main() {
4041

4142
cbindgen::Builder::new()
4243
.with_config({
43-
let mut config = cbindgen::Config::default();
44-
45-
config.language = cbindgen::Language::Cxx;
46-
config.braces = cbindgen::Braces::SameLine;
47-
config.style = cbindgen::Style::Both;
48-
config.layout = cbindgen::LayoutConfig { ..Default::default() };
49-
config.enumeration = cbindgen::EnumConfig {
50-
derive_helper_methods: true,
51-
// prefix_with_name: true,
52-
..Default::default()
53-
};
54-
config.export = cbindgen::ExportConfig {
55-
mangle: cbindgen::MangleConfig { remove_underscores: true, ..Default::default() },
44+
let mut config = cbindgen::Config {
45+
language: cbindgen::Language::Cxx,
46+
braces: cbindgen::Braces::SameLine,
47+
style: cbindgen::Style::Both,
48+
layout: cbindgen::LayoutConfig { ..Default::default() },
49+
enumeration: cbindgen::EnumConfig {
50+
derive_helper_methods: true,
51+
// prefix_with_name: true,
52+
..Default::default()
53+
},
54+
export: cbindgen::ExportConfig {
55+
mangle: cbindgen::MangleConfig {
56+
remove_underscores: true,
57+
..Default::default()
58+
},
59+
..Default::default()
60+
},
61+
namespace: Some("dojo_bindings".to_string()),
5662
..Default::default()
5763
};
5864

59-
// config.structure.derive_constructor = true;
60-
// config.structure.derive_eq = true;
61-
config.namespace = Some("dojo_bindings".to_string());
62-
63-
config.defines = HashMap::new();
6465
config.defines.insert(
6566
"target_pointer_width = 32".to_string(),
6667
"TARGET_POINTER_WIDTH_32".to_string(),
@@ -75,27 +76,27 @@ fn main() {
7576

7677
cbindgen::Builder::new()
7778
.with_config({
78-
let mut config = cbindgen::Config::default();
79-
80-
config.language = cbindgen::Language::Cython;
81-
config.braces = cbindgen::Braces::SameLine;
82-
config.style = cbindgen::Style::Both;
83-
config.layout = cbindgen::LayoutConfig { ..Default::default() };
84-
config.enumeration = cbindgen::EnumConfig {
85-
derive_helper_methods: true,
86-
// prefix_with_name: true,
79+
let mut config = cbindgen::Config {
80+
language: cbindgen::Language::Cython,
81+
braces: cbindgen::Braces::SameLine,
82+
style: cbindgen::Style::Both,
83+
layout: cbindgen::LayoutConfig { ..Default::default() },
84+
enumeration: cbindgen::EnumConfig {
85+
derive_helper_methods: true,
86+
// prefix_with_name: true,
87+
..Default::default()
88+
},
89+
export: cbindgen::ExportConfig {
90+
mangle: cbindgen::MangleConfig {
91+
remove_underscores: true,
92+
..Default::default()
93+
},
94+
..Default::default()
95+
},
96+
namespace: Some("dojo_bindings".to_string()),
8797
..Default::default()
8898
};
89-
config.export = cbindgen::ExportConfig {
90-
mangle: cbindgen::MangleConfig { remove_underscores: true, ..Default::default() },
91-
..Default::default()
92-
};
93-
94-
// config.structure.derive_constructor = true;
95-
// config.structure.derive_eq = true;
96-
config.namespace = Some("dojo_bindings".to_string());
9799

98-
config.defines = HashMap::new();
99100
config.defines.insert(
100101
"target_pointer_width = 32".to_string(),
101102
"TARGET_POINTER_WIDTH_32".to_string(),

0 commit comments

Comments
 (0)