mail client (IMAP/SMTP)
git clone https://git.lucas.co/cce-mail.git
build.rs (2.5K)
1 //! Generates the WPE WebKit FFI bindings, but **only under the `wpe` feature**.
2 //!
3 //! Same shape as cce-browser's build.rs (the embedding pattern this crate's
4 //! `src/wpe/` follows): without the feature this is a no-op, so a
5 //! `--no-default-features` build needs no WPE headers at all.
6
7 fn main() {
8 println!("cargo:rerun-if-changed=build.rs");
9 println!("cargo:rerun-if-changed=src/wpe/wrapper.h");
10 if std::env::var("CARGO_FEATURE_WPE").is_err() {
11 return;
12 }
13
14 // Both modules are needed: wpe-webkit-2.0 is the engine, wpe-platform-2.0
15 // is the embedding layer (WPEDisplay / WPEView / WPEToplevel) that
16 // src/wpe/subclass.rs subclasses. pkg-config emits the link flags for us.
17 let mut clang_args = Vec::new();
18 for module in ["wpe-webkit-2.0", "wpe-platform-2.0"] {
19 let lib = pkg_config::Config::new()
20 .probe(module)
21 .unwrap_or_else(|e| panic!("`{module}` not found — pacman -S wpewebkit ({e})"));
22 for path in &lib.include_paths {
23 clang_args.push(format!("-I{}", path.display()));
24 }
25 }
26
27 let bindings = bindgen::Builder::default()
28 .header("src/wpe/wrapper.h")
29 .clang_args(&clang_args)
30 // The engine, the embedding layer, and just enough GObject to
31 // register subclasses and turn a main loop.
32 .allowlist_item("(wpe|WPE|webkit|WebKit)_?.*")
33 .allowlist_item("g_(object|type|signal|bytes|timeout|free|error)_.*")
34 // The main loop AND the context: `pump` drains the context directly.
35 .allowlist_item("g_main_(loop|context)_.*")
36 .allowlist_item("G(Object|Type|Value|Bytes|Error|MainLoop|ParamSpec|Closure).*")
37 // The main-context poll protocol: GPollFD is what `query` fills in.
38 .allowlist_item("G(MainContext|PollFD|Source).*")
39 .allowlist_item("g_(memory_input_stream|input_stream|file)_.*")
40 .allowlist_item("G(InputStream|MemoryInputStream|File|Cancellable|AsyncResult).*")
41 .allowlist_item("g_(type|object)_.*")
42 // GObject's generated enums are plain C enums; keep them as consts so
43 // vfunc tables and property flags stay comparable without casts.
44 .default_enum_style(bindgen::EnumVariation::ModuleConsts)
45 .derive_default(true)
46 .layout_tests(false)
47 .generate()
48 .expect("bindgen failed over the WPE headers");
49
50 let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
51 bindings
52 .write_to_file(out.join("wpe_bindings.rs"))
53 .expect("could not write wpe_bindings.rs");
54 }