New Android suppport

This commit is contained in:
Lars Bergstrom 2015-09-24 13:33:55 -05:00
parent 53d8f04ac4
commit 17a6cb5873
25 changed files with 657 additions and 29 deletions

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![feature(alloc_jemalloc)]
#![feature(box_syntax)]
#![feature(iter_arith)]
#![feature(slice_splits)]
@ -12,6 +13,8 @@
extern crate log;
#[macro_use]
extern crate profile_traits;
extern crate alloc_jemalloc;
extern crate hbs_pow;
extern crate ipc_channel;
extern crate libc;

View file

@ -1,7 +1,5 @@
paths = ["../../support/android-rs-glue"]
[target.arm-linux-androideabi]
linker = "../../target/debug/apk-builder"
linker = "./fake-ld.sh"
ar = "arm-linux-androideabi-ar"
[target.arm-unknown-linux-gnueabihf]

View file

@ -2,7 +2,7 @@
name = "servo"
version = "0.0.1"
dependencies = [
"android_glue 0.1.1",
"android_glue 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas 0.0.1",
"canvas_traits 0.0.1",
@ -55,10 +55,6 @@ dependencies = [
"memchr 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "android_glue"
version = "0.1.1"
[[package]]
name = "android_glue"
version = "0.1.1"
@ -677,7 +673,7 @@ dependencies = [
[[package]]
name = "gif"
version = "0.5.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -929,7 +925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"enum_primitive 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gif 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gif 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"png 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -3,6 +3,7 @@
name = "servo"
version = "0.0.1"
authors = ["The Servo Project Developers"]
build = "build.rs"
[lib]
name = "servo"
@ -111,7 +112,6 @@ path = "../../ports/glutin"
optional = true
[dependencies.android_glue]
path = "../../support/android-rs-glue/glue"
optional = true
[dependencies.log]

61
components/servo/build.rs Normal file
View file

@ -0,0 +1,61 @@
/* 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 http://mozilla.org/MPL/2.0/. */
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()
}
}
fn android_main() {
// Get the NDK path from NDK_HOME env.
let ndk_path = env::var("NDK_HOME").ok().expect("Please set the NDK_HOME environment variable");
let ndk_path = Path::new(&ndk_path);
// Get the standalone NDK path from NDK_STANDALONE env.
let standalone_path = env::var("NDK_STANDALONE").ok().expect("Please set the NDK_STANDALONE environment variable");
let standalone_path = Path::new(&standalone_path);
// Get the standalone NDK path from NDK_STANDALONE env.
let out_dir = env::var("OUT_DIR").ok().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(standalone_path.join("bin").join("arm-linux-androideabi-gcc"))
.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"))
.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(standalone_path.join("bin").join("arm-linux-androideabi-ar"))
.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");
}

3
components/servo/fake-ld.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
TARGET_DIR=$OUT_DIR/../../..
arm-linux-androideabi-gcc $@ $LDFLAGS -lc -o $TARGET_DIR/libservo.so -shared && touch $TARGET_DIR/servo

View file

@ -23,6 +23,8 @@ extern crate android_glue;
// The window backed by glutin
extern crate glutin_app as app;
extern crate env_logger;
#[cfg(target_os = "android")]
extern crate libc;
#[macro_use]
extern crate log;
// The Servo engine
@ -171,6 +173,16 @@ fn args() -> Vec<String> {
env::args().collect()
}
// This extern definition ensures that the linker will not discard
// the static native lib bits, which are brought in from the NDK libraries
// we link in from build.rs.
#[cfg(target_os = "android")]
extern {
fn app_dummy() -> libc::c_void;
}
// This macro must be used at toplevel because it defines a nested
// module, but macros can only accept identifiers - not paths -
// preventing the expansion of this macro within the android module
@ -193,6 +205,8 @@ mod android {
//env::set_var("RUST_LOG", "servo,gfx,msg,util,layers,js,std,rt,extra");
redirect_output(STDERR_FILENO);
redirect_output(STDOUT_FILENO);
unsafe { super::app_dummy(); }
}
struct FilePtr(*mut self::libc::types::common::c95::FILE);