From 04d000ee2626ee5f5d63981756664db78dafd543 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 30 Apr 2024 05:02:57 +0700 Subject: [PATCH 1/2] nicer fmt by cfg! expr --- sdl2-sys/build.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/sdl2-sys/build.rs b/sdl2-sys/build.rs index 59b3852062..c57e585869 100644 --- a/sdl2-sys/build.rs +++ b/sdl2-sys/build.rs @@ -555,15 +555,11 @@ fn main() { #[cfg(feature = "bindgen")] { - let include_paths: Vec; - #[cfg(feature = "bundled")] - { - include_paths = vec![sdl2_includes]; - } - #[cfg(not(feature = "bundled"))] - { - include_paths = compute_include_paths(sdl2_includes) - } + let include_paths: Vec = if cfg!(feature = "bundled") { + vec![sdl2_includes] + } else { + compute_include_paths(sdl2_includes) + }; generate_bindings(target.as_str(), host.as_str(), include_paths.as_slice()); println!("cargo:include={}", include_paths.join(":")); } From 183fcf0828a421636d5e27083cf234fceaf270e8 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 30 Apr 2024 05:03:28 +0700 Subject: [PATCH 2/2] don't repeat yourself --- sdl2-sys/build.rs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/sdl2-sys/build.rs b/sdl2-sys/build.rs index c57e585869..857a23c312 100644 --- a/sdl2-sys/build.rs +++ b/sdl2-sys/build.rs @@ -659,26 +659,14 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) { .raw_line("use crate::*;") .ctypes_prefix("libc"); - let mut ttf_bindings = bindgen::Builder::default() - .use_core() - .raw_line("use crate::*;") - .ctypes_prefix("libc"); + let mut ttf_bindings = image_bindings.clone(); - let mut mixer_bindings = bindgen::Builder::default() - .use_core() - .raw_line("use crate::*;") - .ctypes_prefix("libc"); + let mut mixer_bindings = image_bindings.clone(); let mut gfx_framerate_bindings = bindgen::Builder::default().use_core().ctypes_prefix("libc"); - let mut gfx_primitives_bindings = bindgen::Builder::default() - .use_core() - .raw_line("use crate::*;") - .ctypes_prefix("libc"); - let mut gfx_imagefilter_bindings = bindgen::Builder::default().use_core().ctypes_prefix("libc"); - let mut gfx_rotozoom_bindings = bindgen::Builder::default() - .use_core() - .raw_line("use crate::*;") - .ctypes_prefix("libc"); + let mut gfx_primitives_bindings = image_bindings.clone(); + let mut gfx_imagefilter_bindings = gfx_framerate_bindings.clone(); + let mut gfx_rotozoom_bindings = gfx_primitives_bindings.clone(); // Set correct target triple for bindgen when cross-compiling if target != host {