Auto merge of #14280 - larsbergstrom:fix_fake_ld, r=Ms2ger

Move build.rs along with the other Servo files from components to ports

<!-- Please describe your changes on the following line: -->
r? @Ms2ger

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14280)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-21 09:20:51 -06:00 committed by GitHub
commit 6cc1976cca
3 changed files with 1 additions and 1 deletions

View file

@ -4,7 +4,6 @@ name = "libservo"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
build = "build.rs"
publish = false
[lib]

View file

@ -1,85 +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 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("ANDROID_NDK").ok().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 toolchain_path = ndk_path.join("toolchains").join("arm-linux-androideabi-4.9").join("prebuilt").
join(google_host);
println!("toolchain path is: {}", toolchain_path.to_str().unwrap());
let target = env::var("TARGET").unwrap();
let arch = if target.contains("arm") {
"arch-arm"
} else if target.contains("x86") {
"arch-x86"
} else if target.contains("mips") {
"arch-mips"
} else {
panic!("Invalid target architecture {}", target);
};
// Get the output directory.
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(toolchain_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"))
.arg("--sysroot").arg(ndk_path.join("platforms").join("android-18").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("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");
}