mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Use the build script to set the rpath in MacOS instead of mach. This is another step toward allowing building servo without mach.
73 lines
2.9 KiB
Rust
73 lines
2.9 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use gl_generator::{Api, Fallbacks, Profile, Registry};
|
|
use serde_json::{self, Value};
|
|
use std::env;
|
|
use std::fs::File;
|
|
use std::path::PathBuf;
|
|
use vergen::EmitBuilder;
|
|
|
|
fn main() {
|
|
let target = env::var("TARGET").unwrap();
|
|
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());
|
|
|
|
if let Err(error) = EmitBuilder::builder()
|
|
.fail_on_error()
|
|
.git_sha(true /* short */)
|
|
.emit()
|
|
{
|
|
println!(
|
|
"cargo:warning=Could not generate git version information: {:?}",
|
|
error
|
|
);
|
|
println!("cargo:rustc-env=VERGEN_GIT_SHA=nogit");
|
|
}
|
|
|
|
// On MacOS, all dylib dependencies are shipped along with the binary
|
|
// in the "/lib" directory. Setting the rpath here, allows the dynamic
|
|
// linker to locate them. See `man dyld` for more info.
|
|
#[cfg(target_os = "macos")]
|
|
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/lib/");
|
|
|
|
// Generate GL bindings
|
|
// For now, we only support EGL, and only on Windows and Android.
|
|
if target.contains("android") || target.contains("windows") {
|
|
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
|
|
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
|
|
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
|
|
.unwrap();
|
|
|
|
// Historically, Android builds have succeeded with rust-link-lib=EGL.
|
|
// On Windows when relying on %LIBS% to contain libEGL.lib, however,
|
|
// we must explicitly use rustc-link-lib=libEGL or rustc will attempt
|
|
// to link EGL.lib instead.
|
|
if target.contains("windows") {
|
|
println!("cargo:rustc-link-lib=libEGL");
|
|
} else {
|
|
println!("cargo:rust-link-lib=EGL");
|
|
}
|
|
}
|
|
|
|
if target.contains("linux") ||
|
|
target.contains("dragonfly") ||
|
|
target.contains("freebsd") ||
|
|
target.contains("openbsd")
|
|
{
|
|
let mut file = File::create(&dest.join("glx_bindings.rs")).unwrap();
|
|
Registry::new(Api::Glx, (1, 4), Profile::Core, Fallbacks::All, [])
|
|
.write_bindings(gl_generator::StructGenerator, &mut file)
|
|
.unwrap();
|
|
}
|
|
|
|
// Merge prefs.json and package-prefs.json
|
|
let mut default_prefs = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
default_prefs.push("../../../resources/prefs.json");
|
|
let mut prefs: Value = serde_json::from_reader(File::open(&default_prefs).unwrap()).unwrap();
|
|
let mut pkg_prefs = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
pkg_prefs.push("../../../resources/package-prefs.json");
|
|
let pkg_prefs: Value = serde_json::from_reader(File::open(&pkg_prefs).unwrap()).unwrap();
|
|
let file = File::create(&dest.join("prefs.json")).unwrap();
|
|
serde_json::to_writer(file, &prefs).unwrap();
|
|
}
|