diff --git a/Cargo.lock b/Cargo.lock index 59cc45d04a97..6410126aa2b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2173,22 +2173,6 @@ dependencies = [ "webvr_traits 0.0.1", ] -[[package]] -name = "libsimpleservo" -version = "0.0.1" -dependencies = [ - "android_injected_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "android_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jni 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", - "libservo 0.0.1", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "libz-sys" version = "1.0.18" @@ -3719,6 +3703,39 @@ name = "signpost" version = "0.1.0" source = "git+https://github.com/pcwalton/signpost.git#7ed712507f343c38646b9d1fefd049166f9c9a18" +[[package]] +name = "simpleservo" +version = "0.0.1" +dependencies = [ + "gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libservo 0.0.1", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "simpleservo_capi" +version = "0.0.1" +dependencies = [ + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "simpleservo 0.0.1", +] + +[[package]] +name = "simpleservo_jniapi" +version = "0.0.1" +dependencies = [ + "android_injected_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "android_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "jni 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "simpleservo 0.0.1", +] + [[package]] name = "siphasher" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index f20f4d1194ed..0cfd8e310537 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,8 @@ [workspace] members = [ "ports/servo", - "ports/libsimpleservo/", + "ports/libsimpleservo/capi/", + "ports/libsimpleservo/jniapi/", "ports/libmlservo/", "tests/unit/*", ] diff --git a/ports/libsimpleservo/Cargo.toml b/ports/libsimpleservo/api/Cargo.toml similarity index 76% rename from ports/libsimpleservo/Cargo.toml rename to ports/libsimpleservo/api/Cargo.toml index dd339a9e45e7..a8c61f2c8f16 100644 --- a/ports/libsimpleservo/Cargo.toml +++ b/ports/libsimpleservo/api/Cargo.toml @@ -1,28 +1,16 @@ [package] -name = "libsimpleservo" +name = "simpleservo" version = "0.0.1" -build = "build.rs" authors = ["The Servo Project Developers"] license = "MPL-2.0" edition = "2018" publish = false -[lib] -name = "simpleservo" -crate-type = ["cdylib"] -test = false -bench = false - [dependencies] -libservo = { path = "../../components/servo" } +libservo = { path = "../../../components/servo" } log = "0.4" serde_json = "1.0" -[target.'cfg(target_os = "android")'.dependencies] -android_injected_glue = "0.2" -android_logger = "0.7" -jni = "0.10.2" - [target.'cfg(not(target_os = "macos"))'.dependencies] libc = "0.2" @@ -31,7 +19,6 @@ winapi = "0.3.2" [build-dependencies] gl_generator = "0.10" -cc = "1.0" [features] default = ["unstable", "default-except-unstable"] diff --git a/ports/libsimpleservo/api/build.rs b/ports/libsimpleservo/api/build.rs new file mode 100644 index 000000000000..711cf1a96d01 --- /dev/null +++ b/ports/libsimpleservo/api/build.rs @@ -0,0 +1,28 @@ +/* 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 std::env; +use std::fs::File; +use std::path::Path; + +fn main() { + let target = env::var("TARGET").unwrap(); + // Generate GL bindings + // For now, we only support EGL, and only on Windows and Android. + if target.contains("android") || target.contains("windows") { + let dest = env::var("OUT_DIR").unwrap(); + let mut file = File::create(&Path::new(&dest).join("egl_bindings.rs")).unwrap(); + if target.contains("android") { + Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, []) + .write_bindings(gl_generator::StaticStructGenerator, &mut file) + .unwrap(); + } + if target.contains("windows") { + Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, []) + .write_bindings(gl_generator::StructGenerator, &mut file) + .unwrap(); + }; + } +} diff --git a/ports/libsimpleservo/src/gl_glue.rs b/ports/libsimpleservo/api/src/gl_glue.rs similarity index 92% rename from ports/libsimpleservo/src/gl_glue.rs rename to ports/libsimpleservo/api/src/gl_glue.rs index 5248c47b5668..e4e5176089ef 100644 --- a/ports/libsimpleservo/src/gl_glue.rs +++ b/ports/libsimpleservo/api/src/gl_glue.rs @@ -2,14 +2,17 @@ * 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 std::rc::Rc; + +pub type ServoGl = Rc; + #[cfg(any(target_os = "android", target_os = "windows"))] #[allow(non_camel_case_types)] pub mod egl { - use servo::gl::{Gl, GlesFns}; + use servo::gl::GlesFns; use std::ffi::CString; #[cfg(not(target_os = "windows"))] use std::os::raw::c_void; - use std::rc::Rc; #[cfg(target_os = "windows")] use winapi::um::libloaderapi::{GetProcAddress, LoadLibraryA}; @@ -39,7 +42,7 @@ pub mod egl { include!(concat!(env!("OUT_DIR"), "/egl_bindings.rs")); #[cfg(target_os = "android")] - pub fn init() -> Result, &'static str> { + pub fn init() -> Result { info!("Loading EGL..."); unsafe { let egl = Egl; @@ -84,9 +87,7 @@ pub mod egl { target_os = "macos" ))] pub mod gl { - use servo::gl::Gl; - use std::rc::Rc; - pub fn init() -> Result, &'static str> { + pub fn init() -> Result { // FIXME: Add an OpenGL version unimplemented!() } diff --git a/ports/libsimpleservo/src/api.rs b/ports/libsimpleservo/api/src/lib.rs similarity index 99% rename from ports/libsimpleservo/src/api.rs rename to ports/libsimpleservo/api/src/lib.rs index 2d68bad07c3f..2611ff2b5f65 100644 --- a/ports/libsimpleservo/src/api.rs +++ b/ports/libsimpleservo/api/src/lib.rs @@ -2,6 +2,11 @@ * 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/. */ +#[macro_use] +extern crate log; + +pub mod gl_glue; + use servo::compositing::windowing::{ AnimationState, EmbedderCoordinates, MouseWindowEvent, WindowEvent, WindowMethods, }; diff --git a/ports/libsimpleservo/capi/Cargo.toml b/ports/libsimpleservo/capi/Cargo.toml new file mode 100644 index 000000000000..2cc9228c9df7 --- /dev/null +++ b/ports/libsimpleservo/capi/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "simpleservo_capi" +version = "0.0.1" +authors = ["The Servo Project Developers"] +license = "MPL-2.0" +edition = "2018" +publish = false + +[lib] +name = "simpleservo" +crate-type = ["cdylib"] +test = false +bench = false + +[dependencies] +simpleservo = { path = "../api" } +log = "0.4" + +[features] +default = ["unstable", "default-except-unstable"] +default-except-unstable = ["webdriver", "max_log_level"] +max_log_level = ["simpleservo/max_log_level"] +webdriver = ["simpleservo/webdriver"] +energy-profiling = ["simpleservo/energy-profiling"] +debugmozjs = ["simpleservo/debugmozjs"] +unstable = ["simpleservo/unstable"] +googlevr = ["simpleservo/googlevr"] +oculusvr = ["simpleservo/oculusvr"] +native-bluetooth = ["simpleservo/native-bluetooth"] +webgl_backtrace = ["simpleservo/webgl_backtrace"] +js_backtrace = ["simpleservo/js_backtrace"] diff --git a/ports/libsimpleservo/src/capi.rs b/ports/libsimpleservo/capi/src/lib.rs similarity index 96% rename from ports/libsimpleservo/src/capi.rs rename to ports/libsimpleservo/capi/src/lib.rs index 2167ce77dfc2..4319b858d627 100644 --- a/ports/libsimpleservo/src/capi.rs +++ b/ports/libsimpleservo/capi/src/lib.rs @@ -2,13 +2,15 @@ * 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 crate::api::{self, EventLoopWaker, HostTrait, InitOptions, ReadFileTrait, ServoGlue, SERVO}; -use crate::gl_glue; -use servo::gl; +#[macro_use] +extern crate log; + +use simpleservo::{ + self, gl_glue, EventLoopWaker, HostTrait, InitOptions, ReadFileTrait, ServoGlue, SERVO, +}; use std::ffi::{CStr, CString}; use std::mem; use std::os::raw::c_char; -use std::rc::Rc; fn call(f: F) where @@ -55,7 +57,7 @@ pub struct CInitOptions { /// The returned string is not freed. This will leak. #[no_mangle] pub extern "C" fn servo_version() -> *const c_char { - let v = api::servo_version(); + let v = simpleservo::servo_version(); let text = CString::new(v).expect("Can't create string"); let ptr = text.as_ptr(); mem::forget(text); @@ -64,7 +66,7 @@ pub extern "C" fn servo_version() -> *const c_char { fn init( opts: CInitOptions, - gl: Rc, + gl: gl_glue::ServoGl, wakeup: extern "C" fn(), readfile: extern "C" fn(*const c_char) -> *const c_char, callbacks: CHostCallbacks, @@ -88,7 +90,7 @@ fn init( let readfile = Box::new(ReadFileCallback::new(readfile)); let callbacks = Box::new(HostCallbacks::new(callbacks)); - api::init(opts, gl, wakeup, readfile, callbacks).unwrap(); + simpleservo::init(opts, gl, wakeup, readfile, callbacks).unwrap(); } #[cfg(target_os = "windows")] @@ -122,7 +124,7 @@ pub extern "C" fn init_with_gl( #[no_mangle] pub extern "C" fn deinit() { debug!("deinit"); - api::deinit(); + simpleservo::deinit(); } #[no_mangle] diff --git a/ports/libsimpleservo/jniapi/Cargo.toml b/ports/libsimpleservo/jniapi/Cargo.toml new file mode 100644 index 000000000000..498ac05f055d --- /dev/null +++ b/ports/libsimpleservo/jniapi/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "simpleservo_jniapi" +version = "0.0.1" +build = "build.rs" +authors = ["The Servo Project Developers"] +license = "MPL-2.0" +edition = "2018" +publish = false + +[lib] +name = "simpleservo" +crate-type = ["cdylib"] +test = false +bench = false + +[dependencies] +android_injected_glue = "0.2" +android_logger = "0.7" +jni = "0.10.2" +log = "0.4" +simpleservo = { path = "../api" } +libc = "0.2" + +[build-dependencies] +cc = "1.0" + +[features] +default = ["unstable", "default-except-unstable"] +default-except-unstable = ["webdriver", "max_log_level"] +max_log_level = ["simpleservo/max_log_level"] +webdriver = ["simpleservo/webdriver"] +energy-profiling = ["simpleservo/energy-profiling"] +debugmozjs = ["simpleservo/debugmozjs"] +unstable = ["simpleservo/unstable"] +googlevr = ["simpleservo/googlevr"] +oculusvr = ["simpleservo/oculusvr"] +native-bluetooth = ["simpleservo/native-bluetooth"] +webgl_backtrace = ["simpleservo/webgl_backtrace"] +js_backtrace = ["simpleservo/js_backtrace"] diff --git a/ports/libsimpleservo/build.rs b/ports/libsimpleservo/jniapi/build.rs similarity index 52% rename from ports/libsimpleservo/build.rs rename to ports/libsimpleservo/jniapi/build.rs index 0e7638e50367..e97cb3101111 100644 --- a/ports/libsimpleservo/build.rs +++ b/ports/libsimpleservo/jniapi/build.rs @@ -2,20 +2,10 @@ * 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 std::env; -use std::fs::File; use std::path::Path; fn main() { - let target = env::var("TARGET").unwrap(); - if target.contains("android") { - android_main() - } - generate_gl_bindings(&target); -} - -fn android_main() { // Get the NDK path from NDK_HOME env. let ndk_path = env::var_os("ANDROID_NDK").expect("Please set the ANDROID_NDK environment variable"); @@ -41,21 +31,3 @@ fn android_main() { println!("cargo:rustc-link-lib=log"); println!("cargo:rustc-link-lib=android"); } - -fn generate_gl_bindings(target: &str) { - // For now, we only support EGL, and only on Windows and Android. - if target.contains("android") || target.contains("windows") { - let dest = env::var("OUT_DIR").unwrap(); - let mut file = File::create(&Path::new(&dest).join("egl_bindings.rs")).unwrap(); - if target.contains("android") { - Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, []) - .write_bindings(gl_generator::StaticStructGenerator, &mut file) - .unwrap(); - } - if target.contains("windows") { - Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, []) - .write_bindings(gl_generator::StructGenerator, &mut file) - .unwrap(); - }; - } -} diff --git a/ports/libsimpleservo/src/jniapi.rs b/ports/libsimpleservo/jniapi/src/lib.rs similarity index 98% rename from ports/libsimpleservo/src/jniapi.rs rename to ports/libsimpleservo/jniapi/src/lib.rs index b6ece2822dd5..3bb0b30de1c2 100644 --- a/ports/libsimpleservo/src/jniapi.rs +++ b/ports/libsimpleservo/jniapi/src/lib.rs @@ -4,14 +4,18 @@ #![allow(non_snake_case)] +#[macro_use] +extern crate log; + use android_logger::{self, Filter}; -use crate::api::{self, EventLoopWaker, HostTrait, InitOptions, ReadFileTrait, ServoGlue, SERVO}; -use crate::gl_glue; use jni::objects::{GlobalRef, JClass, JObject, JString, JValue}; use jni::sys::{jboolean, jfloat, jint, jstring, JNI_TRUE}; use jni::{errors, JNIEnv, JavaVM}; use libc::{dup2, pipe, read}; use log::Level; +use simpleservo::{ + self, gl_glue, EventLoopWaker, HostTrait, InitOptions, ReadFileTrait, ServoGlue, SERVO, +}; use std::os::raw::{c_char, c_int, c_void}; use std::sync::{Arc, Mutex}; use std::thread; @@ -37,7 +41,7 @@ where #[no_mangle] pub fn Java_org_mozilla_servoview_JNIServo_version(env: JNIEnv, _class: JClass) -> jstring { - let v = api::servo_version(); + let v = simpleservo::servo_version(); new_string(&env, &v).unwrap_or_else(|null| null) } @@ -62,8 +66,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_init( // debug!() will only show in a debug build. Use info!() if logs // should show up in adb logcat with a release build. let filters = [ - "simpleservo::api", - "simpleservo::jniapi", + "simpleservo", "simpleservo::gl_glue::egl", // Show JS errors by default. "script::dom::bindings::error", @@ -102,7 +105,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_init( let callbacks = Box::new(HostCallbacks::new(callbacks_ref, &env)); if let Err(err) = - gl_glue::egl::init().and_then(|gl| api::init(opts, gl, wakeup, readfile, callbacks)) + gl_glue::egl::init().and_then(|gl| simpleservo::init(opts, gl, wakeup, readfile, callbacks)) { throw(&env, err) }; @@ -123,7 +126,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_requestShutdown(env: JNIEnv, _class: #[no_mangle] pub fn Java_org_mozilla_servoview_JNIServo_deinit(_env: JNIEnv, _class: JClass) { debug!("deinit"); - api::deinit(); + simpleservo::deinit(); } #[no_mangle] diff --git a/ports/libsimpleservo/src/lib.rs b/ports/libsimpleservo/src/lib.rs deleted file mode 100644 index aaa96f66a722..000000000000 --- a/ports/libsimpleservo/src/lib.rs +++ /dev/null @@ -1,21 +0,0 @@ -/* 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/. */ - -#[macro_use] -extern crate log; - -mod api; -mod gl_glue; - -// If not Android, expose the C-API -#[cfg(not(target_os = "android"))] -mod capi; -#[cfg(not(target_os = "android"))] -pub use crate::capi::*; - -// If Android, expose the JNI-API -#[cfg(target_os = "android")] -mod jniapi; -#[cfg(target_os = "android")] -pub use crate::jniapi::*; diff --git a/python/servo/command_base.py b/python/servo/command_base.py index 6c193191fb0d..393808213a6e 100644 --- a/python/servo/command_base.py +++ b/python/servo/command_base.py @@ -716,7 +716,7 @@ def ports_servo_crate(self): def add_manifest_path(self, args, android=False, libsimpleservo=False): if "--manifest-path" not in args: if libsimpleservo or android: - manifest = self.ports_libsimpleservo_manifest() + manifest = self.ports_libsimpleservo_manifest(android) else: manifest = self.ports_servo_manifest() args.append("--manifest-path") @@ -725,8 +725,12 @@ def add_manifest_path(self, args, android=False, libsimpleservo=False): def ports_servo_manifest(self): return path.join(self.context.topdir, "ports", "servo", "Cargo.toml") - def ports_libsimpleservo_manifest(self): - return path.join(self.context.topdir, "ports", "libsimpleservo", "Cargo.toml") + def ports_libsimpleservo_manifest(self, android=False): + if android: + api = "jniapi" + else: + api = "capi" + return path.join(self.context.topdir, "ports", "libsimpleservo", api, "Cargo.toml") def servo_features(self): """Return a list of optional features to enable for the Servo crate"""