mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Merge pull request #968 from BVE-Reborn/include-from-sys-pr
Print Out SDL2 Include Directory in sdl2-sys Build Script
This commit is contained in:
@@ -371,6 +371,19 @@ If you don't have pkg-config or disabled the feature, it will try to get the hea
|
||||
If somehow you have your own headers that you want to use (use a beta version, an older version, ...),
|
||||
you can set the environment variable "SDL2_INCLUDE_PATH" and those headers will be used by bindgen instead.
|
||||
|
||||
# Using sdl2-sys to provide SDL2 headers/library
|
||||
|
||||
If you are creating a `*-sys` crate for a library which requires SDL2, you can use `sdl2-sys` to provide both the compiled library
|
||||
and the headers for SDL2.
|
||||
|
||||
Follow the following process to get the header directory. In the `Cargo.toml` for your crate, add `sdl2-sys` as a dependency (not a build-dependency).
|
||||
Cargo will then provide your build script with an environment variable `DEP_SDL2_INCLUDE` which is populated with the include directory for SDL2.
|
||||
If there is more than one directory, they are combined with `:` as a separator. Pass these directories to whatever is building your C/C++.
|
||||
|
||||
Once everything is linked together, there will be a single copy of SDL2 (the one provided by `sdl2-sys`) for all C, C++, and Rust code.
|
||||
|
||||
For more discussion see the corresponding [issue][dep-sdl2-include-issue]
|
||||
|
||||
# OpenGL
|
||||
|
||||
If you want to use OpenGL, you also need the
|
||||
@@ -589,5 +602,6 @@ Any Pull Request is welcome, however small your contribution may be ! There are,
|
||||
[homebrew]: http://brew.sh/
|
||||
[crates]: http://crates.io/
|
||||
[examples]: https://github.com/jdeseno/rs-sdl2-examples
|
||||
[dep-sdl2-include-issue]: https://github.com/Rust-SDL2/rust-sdl2/pull/968
|
||||
[gl-rs]: https://github.com/bjz/gl-rs
|
||||
[pdev-issue]: https://github.com/PistonDevelopers/rust-empty/issues/175
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
In this file will be listed the changes, especially the breaking ones that one should be careful of
|
||||
when upgrading from a version of rust-sdl2 to another.
|
||||
|
||||
### unreleased
|
||||
|
||||
[PR #968](https://github.com/Rust-SDL2/rust-sdl2/pull/968)
|
||||
Pass SDL2 include directories to `sdl2-sys`'s dependant crates through `DEP_SDL2_INCLUDE`.
|
||||
|
||||
### v0.33
|
||||
|
||||
[PR #956](https://github.com/Rust-SDL2/rust-sdl2/pull/956) + [PR #960](https://github.com/Rust-SDL2/rust-sdl2/pull/960) + [PR #951](https://github.com/Rust-SDL2/rust-sdl2/pull/951):
|
||||
|
||||
+25
-12
@@ -36,6 +36,13 @@ macro_rules! add_msvc_includes_to_bindings {
|
||||
};
|
||||
}
|
||||
|
||||
fn get_bundled_header_path() -> PathBuf {
|
||||
let mut include_path: PathBuf = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
include_path.push(format!("SDL2-{}", SDL2_HEADERS_BUNDLED_VERSION));
|
||||
include_path.push("include");
|
||||
include_path
|
||||
}
|
||||
|
||||
#[cfg(feature = "bundled")]
|
||||
fn run_command(cmd: &str, args: &[&str]) {
|
||||
use std::process::Command;
|
||||
@@ -468,8 +475,12 @@ fn main() {
|
||||
|
||||
#[cfg(feature = "bindgen")] {
|
||||
let include_paths = vec!(String::from(sdl2_downloaded_include_path.to_str().unwrap()));
|
||||
println!("cargo:include={}", include_paths.join(":"));
|
||||
generate_bindings(target.as_str(), host.as_str(), include_paths.as_slice())
|
||||
}
|
||||
#[cfg(not(feature = "bindgen"))] {
|
||||
println!("cargo:include={}", sdl2_downloaded_include_path.display());
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(all(not(feature = "bundled"), feature = "bindgen"))] {
|
||||
@@ -479,6 +490,7 @@ fn main() {
|
||||
|
||||
#[cfg(not(feature = "bindgen"))] {
|
||||
copy_pregenerated_bindings();
|
||||
println!("cargo:include={}", get_bundled_header_path().display());
|
||||
}
|
||||
|
||||
link_sdl2(target_os);
|
||||
@@ -526,7 +538,7 @@ fn copy_pregenerated_bindings() {
|
||||
#[cfg(feature = "bindgen")]
|
||||
// headers_path is a list of directories where the SDL2 headers are expected
|
||||
// to be found by bindgen (should point to the include/ directories)
|
||||
fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str, headers_paths: &[S]) {
|
||||
fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
|
||||
let target_os = get_os_from_triple(target).unwrap();
|
||||
let mut bindings = bindgen::Builder::default()
|
||||
// enable no_std-friendly output by only using core definitions
|
||||
@@ -600,9 +612,9 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
|
||||
|
||||
if headers_paths.len() == 0 {
|
||||
// if no paths are being provided, fall back to the headers included in this repo
|
||||
let mut include_path: PathBuf = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
include_path.push(format!("SDL2-{}", SDL2_HEADERS_BUNDLED_VERSION));
|
||||
include_path.push("include");
|
||||
let include_path = get_bundled_header_path();
|
||||
println!("cargo:include={}", include_path.display());
|
||||
|
||||
bindings = bindings.clang_arg(format!("-I{}", include_path.display()));
|
||||
if cfg!(feature = "image") {
|
||||
image_bindings = image_bindings.clang_arg(format!("-I{}", include_path.display()));
|
||||
@@ -621,22 +633,23 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
|
||||
}
|
||||
} else {
|
||||
// if paths are included, use them for bindgen. Bindgen should use the first one.
|
||||
println!("cargo:include={}", headers_paths.join(":"));
|
||||
for headers_path in headers_paths {
|
||||
bindings = bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
|
||||
bindings = bindings.clang_arg(format!("-I{}", headers_path));
|
||||
if cfg!(feature = "image") {
|
||||
image_bindings = image_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
|
||||
image_bindings = image_bindings.clang_arg(format!("-I{}", headers_path));
|
||||
}
|
||||
if cfg!(feature = "ttf") {
|
||||
ttf_bindings = ttf_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
|
||||
ttf_bindings = ttf_bindings.clang_arg(format!("-I{}", headers_path));
|
||||
}
|
||||
if cfg!(feature = "mixer") {
|
||||
mixer_bindings = mixer_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
|
||||
mixer_bindings = mixer_bindings.clang_arg(format!("-I{}", headers_path));
|
||||
}
|
||||
if cfg!(feature = "gfx") {
|
||||
gfx_framerate_bindings = gfx_framerate_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
|
||||
gfx_primitives_bindings = gfx_primitives_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
|
||||
gfx_imagefilter_bindings = gfx_imagefilter_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
|
||||
gfx_rotozoom_bindings = gfx_rotozoom_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
|
||||
gfx_framerate_bindings = gfx_framerate_bindings.clang_arg(format!("-I{}", headers_path));
|
||||
gfx_primitives_bindings = gfx_primitives_bindings.clang_arg(format!("-I{}", headers_path));
|
||||
gfx_imagefilter_bindings = gfx_imagefilter_bindings.clang_arg(format!("-I{}", headers_path));
|
||||
gfx_rotozoom_bindings = gfx_rotozoom_bindings.clang_arg(format!("-I{}", headers_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user