Skip to content

Commit 6722962

Browse files
committed
1 parent 2c02e87 commit 6722962

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

libquickjs-sys/build.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ fn main() {
5959
println!("cargo:rustc-link-lib=static={}", LIB_NAME);
6060
}
6161

62+
#[cfg(not(target_env = "msvc"))]
63+
#[derive(Debug)]
64+
struct IgnoreMacros(std::collections::HashSet<String>);
65+
66+
#[cfg(not(target_env = "msvc"))]
67+
impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
68+
fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior {
69+
if self.0.contains(name) {
70+
bindgen::callbacks::MacroParsingBehavior::Ignore
71+
} else {
72+
bindgen::callbacks::MacroParsingBehavior::Default
73+
}
74+
}
75+
}
76+
6277
#[cfg(not(target_env = "msvc"))]
6378
#[cfg(feature = "bundled")]
6479
fn main() {
@@ -121,6 +136,18 @@ fn main() {
121136
// Tell cargo to invalidate the built crate whenever the wrapper changes
122137
println!("cargo:rerun-if-changed=wrapper.h");
123138

139+
let ignored_macros = IgnoreMacros(
140+
vec![
141+
"FP_INFINITE".into(),
142+
"FP_NAN".into(),
143+
"FP_NORMAL".into(),
144+
"FP_SUBNORMAL".into(),
145+
"FP_ZERO".into(),
146+
]
147+
.into_iter()
148+
.collect(),
149+
);
150+
124151
// The bindgen::Builder is the main entry point
125152
// to bindgen, and lets you build up options for
126153
// the resulting bindings.
@@ -131,6 +158,7 @@ fn main() {
131158
// Tell cargo to invalidate the built crate whenever any of the
132159
// included header files changed.
133160
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
161+
.parse_callbacks(Box::new(ignored_macros))
134162
.clang_arg("-I".to_owned() + out_path.to_str().unwrap())
135163
// Finish the builder and generate the bindings.
136164
.generate()

libquickjs-sys/embed/quickjs/quickjs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20076,7 +20076,7 @@ typedef struct JSParseState {
2007620076
BOOL is_module; /* parsing a module */
2007720077
BOOL allow_html_comments;
2007820078
BOOL ext_json; /* true if accepting JSON superset */
20079-
#ifdef CONFIG_JSX;
20079+
#ifdef CONFIG_JSX
2008020080
BOOL allow_web_name_token; /* HTML and CSS tokens that accept '-' as part of the nmtoken */
2008120081
#endif
2008220082
} JSParseState;
@@ -20360,7 +20360,7 @@ static __exception int js_parse_string(JSParseState *s, int sep,
2036020360
/* expr start */
2036120361
--p;
2036220362
break;
20363-
} else
20363+
} else
2036420364
#endif
2036520365
if (c == sep)
2036620366
break;
@@ -20632,7 +20632,7 @@ static JSAtom parse_ident(JSParseState *s, const uint8_t **pp,
2063220632
c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p1);
2063320633
}
2063420634
#ifdef CONFIG_JSX
20635-
if (c == '-' && s->allow_web_name_token) {;} else
20635+
if (c == '-' && s->allow_web_name_token) {;} else
2063620636
#endif
2063720637
if (!lre_js_is_ident_next(c))
2063820638
break;

0 commit comments

Comments
 (0)