Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit how the Android port works. #20912

Merged
merged 6 commits into from Jul 31, 2018
Next

new android port: Remove Android code from /ports/servo/

  • Loading branch information
paulrouget committed Jul 31, 2018
commit cbaf19c65c894bf5bdab442c612bbccbde5fee6a
@@ -33,7 +33,7 @@ googlevr = ["libservo/googlevr"]
oculusvr = ["libservo/oculusvr"]
unstable = ["libservo/unstable"]

[dependencies]
[target.'cfg(not(target_os = "android"))'.dependencies]
backtrace = "0.3"
bitflags = "1.0"
euclid = "0.18"
@@ -44,8 +44,6 @@ libservo = {path = "../../components/servo"}
log = "0.4"
tinyfiledialogs = "3.0"
winit = {version = "0.16", features = ["icon_loading"]}

[target.'cfg(not(target_os = "android"))'.dependencies]
sig = "0.1"

[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
@@ -54,10 +52,6 @@ osmesa-sys = "0.1.2"
[target.'cfg(target_os = "linux")'.dependencies]
x11 = "2.0.0"

[target.'cfg(target_os = "android")'.dependencies]
android_injected_glue = "0.2"
servo-egl = "0.2"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = "0.2"
user32-sys = "0.2"
@@ -17,9 +17,7 @@ use servo::servo_url::ServoUrl;
use servo::webrender_api::ScrollLocation;
use std::mem;
use std::rc::Rc;
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
use std::thread;
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
use tinyfiledialogs::{self, MessageBoxIcon};

pub struct Browser {
@@ -100,7 +98,8 @@ impl Browser {
String::from("")
};
let title = "URL or search query";
if let Some(input) = get_url_input(title, &url) {
let input = tinyfiledialogs::input_box(title, title, &url);
if let Some(input) = input {
if let Some(url) = sanitize_url(&input) {
self.event_queue.push(WindowEvent::LoadUrl(id, url));
}
@@ -263,7 +262,11 @@ impl Browser {
self.window.set_inner_size(size);
}
EmbedderMsg::Alert(message, sender) => {
display_alert_dialog(message.to_owned());
if !opts::get().headless {
let _ = thread::Builder::new().name("display alert dialog".to_owned()).spawn(move || {
tinyfiledialogs::message_box_ok("Alert!", &message, MessageBoxIcon::Warning);
}).unwrap().join().expect("Thread spawning failed");
}
if let Err(e) = sender.send(()) {
let reason = format!("Failed to send Alert response: {}", e);
self.event_queue.push(WindowEvent::SendError(browser_id, reason));
@@ -324,8 +327,7 @@ impl Browser {
};
},
EmbedderMsg::SelectFiles(patterns, multiple_files, sender) => {
let res = match (opts::get().headless,
platform_get_selected_files(patterns, multiple_files)) {
let res = match (opts::get().headless, get_selected_files(patterns, multiple_files)) {
(true, _) | (false, None) => sender.send(None),
(false, Some(files)) => sender.send(Some(files))
};
@@ -346,31 +348,6 @@ impl Browser {

}

#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
fn display_alert_dialog(message: String) {
if !opts::get().headless {
let _ = thread::Builder::new().name("display alert dialog".to_owned()).spawn(move || {
tinyfiledialogs::message_box_ok("Alert!", &message, MessageBoxIcon::Warning);
}).unwrap().join().expect("Thread spawning failed");
}
}

#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
fn display_alert_dialog(_message: String) {
// tinyfiledialogs not supported on Android
}

#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
fn get_url_input(_title: &str, _url: &str) -> Option<String> {
// tinyfiledialogs not supported on Android
None
}

#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
fn get_url_input(title: &str, url: &str) -> Option<String> {
tinyfiledialogs::input_box(title, title, url)
}

#[cfg(target_os = "linux")]
fn platform_get_selected_devices(devices: Vec<String>) -> Option<String> {
let picker_name = "Choose a device";
@@ -403,10 +380,7 @@ fn platform_get_selected_devices(devices: Vec<String>) -> Option<String> {
None
}

#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
fn platform_get_selected_files(patterns: Vec<FilterPattern>,
multiple_files: bool)
-> Option<Vec<String>> {
fn get_selected_files(patterns: Vec<FilterPattern>, multiple_files: bool) -> Option<Vec<String>> {
let picker_name = if multiple_files { "Pick files" } else { "Pick a file" };
thread::Builder::new().name(picker_name.to_owned()).spawn(move || {
let mut filters = vec![];
@@ -426,14 +400,6 @@ fn platform_get_selected_files(patterns: Vec<FilterPattern>,
}).unwrap().join().expect("Thread spawning failed")
}

#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
fn platform_get_selected_files(_patterns: Vec<FilterPattern>,
_multiple_files: bool)
-> Option<Vec<String>> {
warn!("File picker not implemented");
None
}

fn sanitize_url(request: &str) -> Option<ServoUrl> {
let request = request.trim();
ServoUrl::parse(&request).ok()
@@ -5,18 +5,7 @@
#[cfg(windows)]
extern crate winres;

use std::env;
use std::path::Path;
use std::process;
use std::process::{Command, Stdio};

fn main() {
// build.rs is not platform-specific, so we have to check the target here.
let target = env::var("TARGET").unwrap();
if target.contains("android") {
android_main()
}

#[cfg(windows)]
{
let mut res = winres::WindowsResource::new();
@@ -25,89 +14,3 @@ fn main() {
res.compile().unwrap();
}
}

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");
let ndk_path = Path::new(&ndk_path);

// Build up the path to the NDK compilers
// Options for host are: "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"
// per: https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html

let host = env::var("HOST").unwrap();
let google_host = match host.as_ref() {
"i686-unknown-linux-gnu" => "linux-x86",
"x86_64-apple-darwin" => "darwin-x86_64",
"x86_64-unknown-linux-gnu" => "linux-x86_64",
_ => panic!("Unknown support android cross-compile host: {}", host)
};

let target = env::var("TARGET").unwrap();
let arch = if target.contains("arm") {
"arch-arm"
} else if target.contains("aarch64") {
"arch-arm64"
} else if target.contains("x86") || target.contains("i686") {
"arch-x86"
} else if target.contains("mips") {
"arch-mips"
} else {
panic!("Invalid target architecture {}", target);
};

let platform = if target.contains("aarch64") {
"android-21"
} else {
"android-18"
};

let (toolchain, prefix) = if target.contains("armv7") {
let toolchain = "arm-linux-androideabi";
(toolchain.into(), toolchain.into())
} else if target.contains("i686") {
("x86".into(), target)
} else {
(target.clone(), target)
};

let toolchain_path = ndk_path.join("toolchains").join(format!("{}-4.9", toolchain)).join("prebuilt").
join(google_host);
println!("toolchain path is: {}", toolchain_path.to_str().unwrap());

// Get the output directory.
let out_dir = env::var("OUT_DIR").expect("Cargo should have set the OUT_DIR environment variable");
let directory = Path::new(&out_dir);

// compiling android_native_app_glue.c
if Command::new(toolchain_path.join("bin").join(format!("{}-gcc", prefix)))
.arg(ndk_path.join("sources").join("android").join("native_app_glue").join("android_native_app_glue.c"))
.arg("-c")
.arg("-o").arg(directory.join("android_native_app_glue.o"))
.arg("--sysroot").arg(ndk_path.join("platforms").join(platform).join(arch))
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status().unwrap().code().unwrap() != 0
{
println!("Error while executing gcc");
process::exit(1)
}

// compiling libandroid_native_app_glue.a
if Command::new(toolchain_path.join("bin").join(format!("{}-ar", prefix)))
.arg("rcs")
.arg(directory.join("libandroid_native_app_glue.a"))
.arg(directory.join("android_native_app_glue.o"))
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status().unwrap().code().unwrap() != 0
{
println!("Error while executing ar");
process::exit(1)
}

println!("cargo:rustc-link-lib=static=android_native_app_glue");
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=log");
println!("cargo:rustc-link-lib=android");
}
@@ -401,12 +401,12 @@ impl Window {
}
}

#[cfg(not(any(target_arch = "arm", target_arch = "aarch64", target_os = "android")))]
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
fn gl_version() -> GlRequest {
return GlRequest::Specific(Api::OpenGl, (3, 2));
}

#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_os = "android"))]
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
fn gl_version() -> GlRequest {
GlRequest::Specific(Api::OpenGlEs, (3, 0))
}
@@ -634,7 +634,6 @@ impl Window {
}
}

/// Has no effect on Android.
pub fn set_cursor(&self, cursor: CursorKind) {
match self.kind {
WindowKind::Window(ref window, ..) => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.