Skip to content

Commit

Permalink
wip: android support
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Apr 1, 2020
1 parent 7b5e4e9 commit ae5169f
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 28 deletions.
23 changes: 23 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[target.aarch64-linux-android]
ar = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar"
linker = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang"

[target.arm-linux-androideabi]
ar = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
linker = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"

[target.armv7-linux-androideabi]
ar = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
linker = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"

[target.thumbv7neon-linux-androideabi]
ar = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
linker = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang"

[target.i686-linux-android]
ar = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-ar"
linker = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android29-clang"

[target.x86_64-linux-android]
ar = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-ar"
linker = "./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android29-clang"
13 changes: 12 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
url = https://chromium.googlesource.com/v8/v8
[submodule "build"]
path = build
url = https://github.com/denoland/chromium_build.git
url = https://github.com/gponsinet/chromium_build.git
branch = android_support
[submodule "tools/clang"]
path = tools/clang
url = https://chromium.googlesource.com/chromium/src/tools/clang.git
Expand All @@ -19,6 +20,16 @@
[submodule "buildtools"]
path = buildtools
url = https://github.com/denoland/chromium_buildtools.git
branch = upstream
[submodule "third_party/zlib"]
path = third_party/zlib
url = https://chromium.googlesource.com/chromium/src/third_party/zlib.git
[submodule "third_party/android_ndk"]
path = third_party/android_ndk
url = https://chromium.googlesource.com/android_ndk.git
[submodule "third_party/android_platform"]
path = third_party/android_platform
url = https://chromium.googlesource.com/chromium/src/third_party/android_platform.git
[submodule "third_party/catapult"]
path = third_party/catapult
url = https://chromium.googlesource.com/catapult
3 changes: 3 additions & 0 deletions .gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ default_args = {
v8_use_snapshot = true
is_component_build = false
symbol_level = 1

# see build/config/compiler/BUILD.gn:49
treat_warnings_as_errors = false
}
2 changes: 1 addition & 1 deletion build
Submodule build updated from 56551e to 235a87
74 changes: 52 additions & 22 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ fn build_v8() {
};

if let Some(clang_base_path) = find_compatible_system_clang() {
println!("clang_base_path {}", clang_base_path.display());
gn_args.push(format!("clang_base_path={:?}", clang_base_path));
// TODO: Dedupe this with the one from cc_wrapper()
gn_args.push("treat_warnings_as_errors=false".to_string());
Expand All @@ -72,28 +71,50 @@ fn build_v8() {
gn_args.push(format!("clang_base_path={:?}", clang_base_path));
}

if let Some(p) = env::var_os("SCCACHE") {
cc_wrapper(&mut gn_args, &Path::new(&p));
} else if let Ok(p) = which("sccache") {
cc_wrapper(&mut gn_args, &p);
} else {
println!("cargo:warning=Not using sccache");
}
// if let Some(p) = env::var_os("SCCACHE") {
// cc_wrapper(&mut gn_args, &Path::new(&p));
// } else if let Ok(p) = which("sccache") {
// cc_wrapper(&mut gn_args, &p);
// } else {
// println!("cargo:warning=Not using sccache");
// }

if let Ok(args) = env::var("GN_ARGS") {
for arg in args.split_whitespace() {
gn_args.push(arg.to_string());
}
}

match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
"aarch64" => {
gn_args.push("target_cpu=\"arm64\"".to_string());
maybe_install_sysroot("arm64");
maybe_install_sysroot("amd64");
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
"android" => {
Command::new("env").status();
let cpu = match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
"aarch64" => "arm64",
"arm" => "arm",
"armv7" => "arm",
"thumbv7neon" => "arm",
"x86" => "x86",
"x86_64" => "x64",
_ => unimplemented!(),
};

gn_args.push("target_os=\"android\"".to_string());
gn_args.push("target_cpu=\"x64\"".to_string());
// gn_args.push(format!("target_cpu=\"{}\"", cpu);
gn_args.push(format!("v8_target_cpu=\"{}\"", cpu));
// gn_args.push("use_sysroot=false".to_string());
// gn_args.push("target_sysroot=\"../../../third_party/android_ndk/sysroot\"".to_string());
gn_args.push("is_component_build=false".to_string());
},
_ => match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
"aarch64" => {
gn_args.push("target_cpu=\"arm64\"".to_string());
maybe_install_sysroot("arm64");
maybe_install_sysroot("amd64");
}
"x86_64" => gn_args.push("use_sysroot=false".to_string()),
_ => unimplemented!(),
}
"x86_64" => gn_args.push("use_sysroot=false".to_string()),
_ => unimplemented!(),
};

let gn_root = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand Down Expand Up @@ -265,16 +286,25 @@ fn is_compatible_clang_version(clang_path: &Path) -> bool {
}

fn find_compatible_system_clang() -> Option<PathBuf> {
if let Ok(p) = env::var("CLANG_BASE_PATH") {
let base_path = Path::new(&p);
let clang_path = base_path.join("bin").join("clang");
if is_compatible_clang_version(&clang_path) {
return Some(base_path.to_path_buf());
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
// "android" => {
// let rustc_linker = env::var("RUSTC_LINKER".to_string()).unwrap();
// let linker_path = Path::new(&rustc_linker);
// return Some(linker_path.parent().unwrap().parent().unwrap().to_path_buf());
// },
_ => {
if let Ok(p) = env::var("CLANG_BASE_PATH") {
let base_path = Path::new(&p);
let clang_path = base_path.join("bin").join("clang");
if is_compatible_clang_version(&clang_path) {
return Some(base_path.to_path_buf());
}
}
println!("using Chromiums clang");
None
}
}

println!("using Chromiums clang");
None
}

// Download chromium's clang into OUT_DIR because Cargo will not allow us to
Expand Down
2 changes: 1 addition & 1 deletion buildtools
1 change: 1 addition & 0 deletions third_party/android_ndk
Submodule android_ndk added at 27c0a8
1 change: 1 addition & 0 deletions third_party/android_platform
Submodule android_platform added at 2244b5
1 change: 1 addition & 0 deletions third_party/catapult
Submodule catapult added at 395a62
2 changes: 1 addition & 1 deletion third_party/zlib
Submodule zlib updated from c2eb8a to 156be8
2 changes: 1 addition & 1 deletion tools/clang
Submodule clang updated from 8bf2cd to 7311e7
2 changes: 1 addition & 1 deletion v8
Submodule v8 updated from 3f53e6 to 2f0e62

0 comments on commit ae5169f

Please sign in to comment.