linking should work now
This commit is contained in:
parent
ad8e1f28ec
commit
825c69d40c
@ -18,4 +18,5 @@ categories = []
|
|||||||
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
bindgen = "^0.63.0"
|
bindgen = "^0.63.0"
|
||||||
|
cmake = "^0.1.49"
|
68
build.rs
68
build.rs
@ -1,9 +1,67 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use bindgen::Bindings;
|
/// Compiles raylib
|
||||||
|
fn compile_raylib(raylib_path: &str) {
|
||||||
|
// Construct a config for running cmake
|
||||||
|
let mut cmake_config = cmake::Config::new(raylib_path);
|
||||||
|
let mut cmake_config = cmake_config
|
||||||
|
.define("BUILD_EXAMPLES", "OFF")
|
||||||
|
.define("CMAKE_BUILD_TYPE", "Release");
|
||||||
|
|
||||||
|
// Set the correct build profile
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
{
|
||||||
|
cmake_config = cmake_config.profile("Debug");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
{
|
||||||
|
cmake_config = cmake_config.profile("Release");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the cmake project
|
||||||
|
let destination = cmake_config.build();
|
||||||
|
|
||||||
|
// Tell cargo where the libraries might be
|
||||||
|
println!("cargo:rustc-link-search=native={}", destination.join("lib").display());
|
||||||
|
println!("cargo:rustc-link-search=native={}", destination.join("lib32").display());
|
||||||
|
println!("cargo:rustc-link-search=native={}", destination.join("lib64").display());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Links libraries
|
||||||
|
fn link_libs() {
|
||||||
|
// Handle windows libs
|
||||||
|
if cfg!(windows) {
|
||||||
|
println!("cargo:rustc-link-lib=dylib=winmm");
|
||||||
|
println!("cargo:rustc-link-lib=dylib=gdi32");
|
||||||
|
println!("cargo:rustc-link-lib=dylib=user32");
|
||||||
|
println!("cargo:rustc-link-lib=dylib=shell32");
|
||||||
|
}
|
||||||
|
// Handle MacOS
|
||||||
|
else if cfg!(target_os = "macos") {
|
||||||
|
println!("cargo:rustc-link-search=native=/usr/local/lib");
|
||||||
|
println!("cargo:rustc-link-lib=framework=OpenGL");
|
||||||
|
println!("cargo:rustc-link-lib=framework=Cocoa");
|
||||||
|
println!("cargo:rustc-link-lib=framework=IOKit");
|
||||||
|
println!("cargo:rustc-link-lib=framework=CoreFoundation");
|
||||||
|
println!("cargo:rustc-link-lib=framework=CoreVideo");
|
||||||
|
}
|
||||||
|
// Handle UNIX
|
||||||
|
else if cfg!(unix) {
|
||||||
|
println!("cargo:rustc-link-search=/usr/local/lib");
|
||||||
|
println!("cargo:rustc-link-lib=X11");
|
||||||
|
}
|
||||||
|
// Fail on other platforms
|
||||||
|
else {
|
||||||
|
panic!("Unsupported platform");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link raylib itself
|
||||||
|
println!("cargo:rustc-link-lib=static=raylib");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates `bindings.rs` file
|
||||||
fn generate_bindings(header_file: &str) {
|
fn generate_bindings(header_file: &str) {
|
||||||
|
|
||||||
// Generate the data
|
// Generate the data
|
||||||
let bindings = bindgen::Builder::default()
|
let bindings = bindgen::Builder::default()
|
||||||
.header(header_file)
|
.header(header_file)
|
||||||
@ -22,6 +80,12 @@ pub fn main() {
|
|||||||
// Files to watch that should trigger a rebuild
|
// Files to watch that should trigger a rebuild
|
||||||
println!("cargo:rerun-if-changed=src/wrapper.h");
|
println!("cargo:rerun-if-changed=src/wrapper.h");
|
||||||
|
|
||||||
|
// Compile raylib
|
||||||
|
compile_raylib("third_party/raylib");
|
||||||
|
|
||||||
|
// Link libraries
|
||||||
|
link_libs();
|
||||||
|
|
||||||
// Generate bindings
|
// Generate bindings
|
||||||
generate_bindings("src/wrapper.h");
|
generate_bindings("src/wrapper.h");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user