Skip to content

Commit

Permalink
Fix Linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
l0calh05t committed Nov 20, 2020
1 parent 2c02e87 commit 6722962
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 28 additions & 0 deletions libquickjs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ fn main() {
println!("cargo:rustc-link-lib=static={}", LIB_NAME);
}

#[cfg(not(target_env = "msvc"))]
#[derive(Debug)]
struct IgnoreMacros(std::collections::HashSet<String>);

#[cfg(not(target_env = "msvc"))]
impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior {
if self.0.contains(name) {
bindgen::callbacks::MacroParsingBehavior::Ignore
} else {
bindgen::callbacks::MacroParsingBehavior::Default
}
}
}

#[cfg(not(target_env = "msvc"))]
#[cfg(feature = "bundled")]
fn main() {
Expand Down Expand Up @@ -121,6 +136,18 @@ fn main() {
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed=wrapper.h");

let ignored_macros = IgnoreMacros(
vec![
"FP_INFINITE".into(),
"FP_NAN".into(),
"FP_NORMAL".into(),
"FP_SUBNORMAL".into(),
"FP_ZERO".into(),
]
.into_iter()
.collect(),
);

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
Expand All @@ -131,6 +158,7 @@ fn main() {
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.parse_callbacks(Box::new(ignored_macros))
.clang_arg("-I".to_owned() + out_path.to_str().unwrap())
// Finish the builder and generate the bindings.
.generate()
Expand Down
6 changes: 3 additions & 3 deletions libquickjs-sys/embed/quickjs/quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -20076,7 +20076,7 @@ typedef struct JSParseState {
BOOL is_module; /* parsing a module */
BOOL allow_html_comments;
BOOL ext_json; /* true if accepting JSON superset */
#ifdef CONFIG_JSX;
#ifdef CONFIG_JSX
BOOL allow_web_name_token; /* HTML and CSS tokens that accept '-' as part of the nmtoken */
#endif
} JSParseState;
Expand Down Expand Up @@ -20360,7 +20360,7 @@ static __exception int js_parse_string(JSParseState *s, int sep,
/* expr start */
--p;
break;
} else
} else
#endif
if (c == sep)
break;
Expand Down Expand Up @@ -20632,7 +20632,7 @@ static JSAtom parse_ident(JSParseState *s, const uint8_t **pp,
c = unicode_from_utf8(p, UTF8_CHAR_LEN_MAX, &p1);
}
#ifdef CONFIG_JSX
if (c == '-' && s->allow_web_name_token) {;} else
if (c == '-' && s->allow_web_name_token) {;} else
#endif
if (!lre_js_is_ident_next(c))
break;
Expand Down

0 comments on commit 6722962

Please sign in to comment.