Kristian H. Kristensen | 7c45ef1 | 2021-04-06 21:54:57 +0000 | [diff] [blame] | 1 | extern crate wayland_scanner; |
Kristian H. Kristensen | 974c7cd | 2021-01-24 12:50:23 +0000 | [diff] [blame] | 2 | |
Kristian H. Kristensen | e8d3b4d | 2021-02-05 16:39:09 +0000 | [diff] [blame] | 3 | use std::env; |
Kristian H. Kristensen | 974c7cd | 2021-01-24 12:50:23 +0000 | [diff] [blame] | 4 | use std::path::Path; |
Kristian H. Kristensen | e8d3b4d | 2021-02-05 16:39:09 +0000 | [diff] [blame] | 5 | use std::path::PathBuf; |
Kristian H. Kristensen | b54da80 | 2021-09-09 12:35:09 +0000 | [diff] [blame] | 6 | use std::process::Command; |
Kristian H. Kristensen | 974c7cd | 2021-01-24 12:50:23 +0000 | [diff] [blame] | 7 | use wayland_scanner::*; |
| 8 | |
Kristian H. Kristensen | b54da80 | 2021-09-09 12:35:09 +0000 | [diff] [blame] | 9 | fn run_bindgen(header: &str, output: &str) { |
| 10 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); |
| 11 | |
Kristian H. Kristensen | 1cea60c | 2021-09-17 12:41:35 +0000 | [diff] [blame] | 12 | let sysroot = env::var("SYSROOT").unwrap_or("/".to_string()); |
| 13 | |
| 14 | let status = Command::new("bindgen") |
Kristian H. Kristensen | 129df19 | 2021-09-27 08:48:04 +0000 | [diff] [blame] | 15 | .args(&["-o", out_path.join(output).to_str().unwrap()]) |
| 16 | .arg("--no-doc-comments") |
| 17 | .arg("--no-layout-tests") |
| 18 | .args(&["--new-type-alias", "wl_fixed_t"]) |
| 19 | .args(&["--default-enum-style", "rust_non_exhaustive"]) |
| 20 | .args(&["--bitfield-enum", "weston_keyboard_modifier"]) |
| 21 | .args(&["--bitfield-enum", "wl_shell_surface_resize"]) |
| 22 | .arg(header) |
| 23 | .arg("--") |
| 24 | .arg(format!("--sysroot={}", sysroot)) |
| 25 | .arg("-I/usr/include/pixman-1") |
Kristian H. Kristensen | 37e86ea | 2021-10-06 21:13:25 +0000 | [diff] [blame] | 26 | .arg("-I./weston/include") |
Kristian H. Kristensen | 129df19 | 2021-09-27 08:48:04 +0000 | [diff] [blame] | 27 | .arg("-I./bindgen/block") |
| 28 | .status() |
| 29 | .unwrap(); |
Kristian H. Kristensen | 1cea60c | 2021-09-17 12:41:35 +0000 | [diff] [blame] | 30 | |
| 31 | assert!(status.success()) |
Kristian H. Kristensen | b54da80 | 2021-09-09 12:35:09 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Kristian H. Kristensen | cad53c4 | 2021-03-08 16:19:24 +0000 | [diff] [blame] | 34 | fn main() { |
| 35 | let protocols = [ |
Kristian H. Kristensen | 7c45ef1 | 2021-04-06 21:54:57 +0000 | [diff] [blame] | 36 | "wayland", |
| 37 | "linux-dmabuf-unstable-v1", |
| 38 | "croscomp", |
| 39 | "alpha-compositing-unstable-v1", |
| 40 | "aura-shell", |
| 41 | "cursor-shapes-unstable-v1", |
| 42 | "gaming-input-unstable-v2", |
| 43 | "keyboard-configuration-unstable-v1", |
| 44 | "keyboard-extension-unstable-v1", |
| 45 | "pointer-gestures-unstable-v1", |
| 46 | "remote-shell-unstable-v1", |
| 47 | "secure-output-unstable-v1", |
| 48 | "stylus-tools-unstable-v1", |
| 49 | "stylus-unstable-v2", |
| 50 | "vsync-feedback-unstable-v1", |
Kristian H. Kristensen | cad53c4 | 2021-03-08 16:19:24 +0000 | [diff] [blame] | 51 | ]; |
| 52 | |
Kristian H. Kristensen | e8d3b4d | 2021-02-05 16:39:09 +0000 | [diff] [blame] | 53 | let out_dir_str = env::var("OUT_DIR").unwrap(); |
Kristian H. Kristensen | 974c7cd | 2021-01-24 12:50:23 +0000 | [diff] [blame] | 54 | let out_dir = Path::new(&out_dir_str); |
Kristian H. Kristensen | cad53c4 | 2021-03-08 16:19:24 +0000 | [diff] [blame] | 55 | for e in &protocols { |
Kristian H. Kristensen | 7c45ef1 | 2021-04-06 21:54:57 +0000 | [diff] [blame] | 56 | let spec = Path::new("protocol").join(e).with_extension("xml"); |
| 57 | let out = out_dir.join(e).with_extension("rs"); |
| 58 | println!("cargo:rerun-if-changed={}", spec.to_str().unwrap()); |
Kristian H. Kristensen | 7c45ef1 | 2021-04-06 21:54:57 +0000 | [diff] [blame] | 59 | generate_code_with_destructor_events(spec, out, Side::Server, &[("wl_callback", "done")]); |
Kristian H. Kristensen | cad53c4 | 2021-03-08 16:19:24 +0000 | [diff] [blame] | 60 | } |
Kristian H. Kristensen | e8d3b4d | 2021-02-05 16:39:09 +0000 | [diff] [blame] | 61 | |
Kristian H. Kristensen | b54da80 | 2021-09-09 12:35:09 +0000 | [diff] [blame] | 62 | run_bindgen("/usr/include/linux/input.h", "input.rs"); |
Kristian H. Kristensen | 73599dc | 2021-10-07 20:05:00 +0000 | [diff] [blame^] | 63 | run_bindgen("./weston/croscomp_weston.h", "croscomp_weston.rs"); |
Kristian H. Kristensen | 8cc818f | 2021-02-12 22:52:36 +0000 | [diff] [blame] | 64 | |
Kristian H. Kristensen | 73599dc | 2021-10-07 20:05:00 +0000 | [diff] [blame^] | 65 | let lib_paths = ["desktop-shell", "libweston"]; |
Kristian H. Kristensen | 4cbd08f | 2021-04-06 18:15:54 +0000 | [diff] [blame] | 66 | |
Kristian H. Kristensen | 49a007d | 2021-09-02 09:18:38 +0000 | [diff] [blame] | 67 | let build_dir = env::var("MESON_BUILD_DIR").unwrap(); |
Kristian H. Kristensen | 4cbd08f | 2021-04-06 18:15:54 +0000 | [diff] [blame] | 68 | for p in &lib_paths { |
Kristian H. Kristensen | 37e86ea | 2021-10-06 21:13:25 +0000 | [diff] [blame] | 69 | println!("cargo:rustc-flags=-L{}/{}", build_dir, p); |
Kristian H. Kristensen | 4cbd08f | 2021-04-06 18:15:54 +0000 | [diff] [blame] | 70 | } |
Kristian H. Kristensen | 7c45ef1 | 2021-04-06 21:54:57 +0000 | [diff] [blame] | 71 | |
Kristian H. Kristensen | e8d3b4d | 2021-02-05 16:39:09 +0000 | [diff] [blame] | 72 | println!("cargo:rustc-link-lib=desktop-shell"); |
Kristian H. Kristensen | e8d3b4d | 2021-02-05 16:39:09 +0000 | [diff] [blame] | 73 | println!("cargo:rustc-link-lib=weston-9"); |
Kristian H. Kristensen | e8d3b4d | 2021-02-05 16:39:09 +0000 | [diff] [blame] | 74 | println!("cargo:rustc-link-lib=input"); |
Kristian H. Kristensen | 37e86ea | 2021-10-06 21:13:25 +0000 | [diff] [blame] | 75 | println!("cargo:rustc-link-lib=evdev"); |
Kristian H. Kristensen | e8d3b4d | 2021-02-05 16:39:09 +0000 | [diff] [blame] | 76 | println!("cargo:rustc-link-lib=wayland-server"); |
| 77 | println!("cargo:rustc-link-lib=pixman-1"); |
Kristian H. Kristensen | 4dd859a | 2021-01-25 17:28:59 +0000 | [diff] [blame] | 78 | } |