Commit 9629015f authored by cstout's avatar cstout Committed by Commit bot

Enable cross compile to android from mac.

Useful for mojo developers.

BUG=486809

Review URL: https://codereview.chromium.org/1128903005

Cr-Commit-Position: refs/heads/master@{#329939}
parent 7be9d959
...@@ -488,11 +488,17 @@ if (is_win) { ...@@ -488,11 +488,17 @@ if (is_win) {
} }
set_default_toolchain("$host_toolchain") set_default_toolchain("$host_toolchain")
} else if (is_android) { } else if (is_android) {
# Use clang for the x86/64 Linux host builds. if (host_os == "linux") {
if (host_cpu == "x86" || host_cpu == "x64") { # Use clang for the x86/64 Linux host builds.
host_toolchain = "//build/toolchain/linux:clang_$host_cpu" if (host_cpu == "x86" || host_cpu == "x64") {
host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
} else {
host_toolchain = "//build/toolchain/linux:$host_cpu"
}
} else if (host_os == "mac") {
host_toolchain = "//build/toolchain/mac:clang_$host_cpu"
} else { } else {
host_toolchain = "//build/toolchain/linux:$host_cpu" assert(false, "Unknown host for android cross compile")
} }
set_default_toolchain("//build/toolchain/android:$current_cpu") set_default_toolchain("//build/toolchain/android:$current_cpu")
} else if (is_linux) { } else if (is_linux) {
...@@ -507,11 +513,11 @@ if (is_win) { ...@@ -507,11 +513,11 @@ if (is_win) {
set_default_toolchain("//build/toolchain/cros:target") set_default_toolchain("//build/toolchain/cros:target")
} }
} else if (is_mac) { } else if (is_mac) {
host_toolchain = "//build/toolchain/mac:clang" host_toolchain = "//build/toolchain/mac:clang_x64"
set_default_toolchain(host_toolchain) set_default_toolchain(host_toolchain)
} else if (is_ios) { } else if (is_ios) {
host_toolchain = "//build/toolchain/mac:host_clang" host_toolchain = "//build/toolchain/mac:clang_x64"
set_default_toolchain("//build/toolchain/mac:clang") set_default_toolchain("//build/toolchain/mac:clang_$current_cpu")
} else if (is_nacl) { } else if (is_nacl) {
# TODO(GYP): This will need to change when we get NaCl working # TODO(GYP): This will need to change when we get NaCl working
# on multiple platforms, but this whole block of code (how we define # on multiple platforms, but this whole block of code (how we define
......
...@@ -60,6 +60,8 @@ if (is_android) { ...@@ -60,6 +60,8 @@ if (is_android) {
# architecture, which is different than the names GN uses. # architecture, which is different than the names GN uses.
if (host_os == "linux") { if (host_os == "linux") {
android_host_os = "linux" android_host_os = "linux"
} else if (host_os == "mac") {
android_host_os = "darwin"
} else { } else {
assert(false, "Need Android toolchain support for your build OS.") assert(false, "Need Android toolchain support for your build OS.")
} }
......
...@@ -1582,9 +1582,11 @@ template("unittest_apk") { ...@@ -1582,9 +1582,11 @@ template("unittest_apk") {
deps += invoker.deps deps += invoker.deps
} }
datadeps = [ datadeps = [
"//tools/android/forwarder2",
"//tools/android/md5sum", "//tools/android/md5sum",
] ]
if (host_os == "linux") {
datadeps += [ "//tools/android/forwarder2" ]
}
if (defined(invoker.datadeps)) { if (defined(invoker.datadeps)) {
datadeps += invoker.datadeps datadeps += invoker.datadeps
} }
......
...@@ -49,6 +49,8 @@ template("android_gcc_toolchain") { ...@@ -49,6 +49,8 @@ template("android_gcc_toolchain") {
cxx = compiler_prefix + tool_prefix + "g++" cxx = compiler_prefix + tool_prefix + "g++"
ar = tool_prefix + "ar" ar = tool_prefix + "ar"
ld = cxx ld = cxx
readelf = compiler_prefix + tool_prefix + "readelf"
nm = compiler_prefix + tool_prefix + "nm"
toolchain_os = "android" toolchain_os = "android"
toolchain_cpu = invoker.toolchain_cpu toolchain_cpu = invoker.toolchain_cpu
......
...@@ -13,6 +13,8 @@ concurrent_links = exec_script("get_concurrent_links.py", [], "value") ...@@ -13,6 +13,8 @@ concurrent_links = exec_script("get_concurrent_links.py", [], "value")
# - cxx # - cxx
# - ar # - ar
# - ld # - ld
# - readelf
# - nm
# and the following which is used in the toolchain_args # and the following which is used in the toolchain_args
# - toolchain_cpu (What "current_cpu" should be set to when invoking a # - toolchain_cpu (What "current_cpu" should be set to when invoking a
# build using this toolchain.) # build using this toolchain.)
...@@ -40,6 +42,9 @@ template("gcc_toolchain") { ...@@ -40,6 +42,9 @@ template("gcc_toolchain") {
assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value") assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value")
assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value") assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value")
assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value") assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value")
assert(defined(invoker.readelf),
"gcc_toolchain() must specify a \"readelf\" value")
assert(defined(invoker.nm), "gcc_toolchain() must specify a \"nm\" value")
assert(defined(invoker.toolchain_cpu), assert(defined(invoker.toolchain_cpu),
"gcc_toolchain() must specify a \"toolchain_cpu\"") "gcc_toolchain() must specify a \"toolchain_cpu\"")
assert(defined(invoker.toolchain_os), assert(defined(invoker.toolchain_os),
...@@ -52,6 +57,8 @@ template("gcc_toolchain") { ...@@ -52,6 +57,8 @@ template("gcc_toolchain") {
cxx = invoker.cxx cxx = invoker.cxx
ar = invoker.ar ar = invoker.ar
ld = invoker.ld ld = invoker.ld
readelf = invoker.readelf
nm = invoker.nm
# Bring these into our scope for string interpolation with default values. # Bring these into our scope for string interpolation with default values.
if (defined(invoker.libs_section_prefix)) { if (defined(invoker.libs_section_prefix)) {
...@@ -138,7 +145,7 @@ template("gcc_toolchain") { ...@@ -138,7 +145,7 @@ template("gcc_toolchain") {
temporary_tocname = sofile + ".tmp" temporary_tocname = sofile + ".tmp"
link_command = link_command =
"$ld -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile" "$ld -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile"
toc_command = "{ readelf -d $sofile | grep SONAME ; nm -gD -f p $sofile | cut -f1-2 -d' '; } > $temporary_tocname" toc_command = "{ $readelf -d $sofile | grep SONAME ; $nm -gD -f p $sofile | cut -f1-2 -d' '; } > $temporary_tocname"
replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $temporary_tocname $tocfile; fi" replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $temporary_tocname $tocfile; fi"
command = "$link_command && $toc_command && $replace_command" command = "$link_command && $toc_command && $replace_command"
......
...@@ -23,6 +23,8 @@ gcc_toolchain("arm") { ...@@ -23,6 +23,8 @@ gcc_toolchain("arm") {
ar = "arm-linux-gnueabi-ar" ar = "arm-linux-gnueabi-ar"
ld = cxx ld = cxx
readelf = "arm-linux-gnueabi-readelf"
nm = "arm-linux-gnueabi-nm"
toolchain_cpu = "arm" toolchain_cpu = "arm"
toolchain_os = "linux" toolchain_os = "linux"
...@@ -39,7 +41,8 @@ gcc_toolchain("clang_x86") { ...@@ -39,7 +41,8 @@ gcc_toolchain("clang_x86") {
} }
cc = "${compiler_prefix}$prefix/clang" cc = "${compiler_prefix}$prefix/clang"
cxx = "${compiler_prefix}$prefix/clang++" cxx = "${compiler_prefix}$prefix/clang++"
readelf = "readelf"
nm = "nm"
ar = "ar" ar = "ar"
ld = cxx ld = cxx
...@@ -52,6 +55,8 @@ gcc_toolchain("x86") { ...@@ -52,6 +55,8 @@ gcc_toolchain("x86") {
cc = "${compiler_prefix}gcc" cc = "${compiler_prefix}gcc"
cxx = "$compiler_prefix}g++" cxx = "$compiler_prefix}g++"
readelf = "readelf"
nm = "nm"
ar = "ar" ar = "ar"
ld = cxx ld = cxx
...@@ -71,6 +76,8 @@ gcc_toolchain("clang_x64") { ...@@ -71,6 +76,8 @@ gcc_toolchain("clang_x64") {
cc = "${compiler_prefix}$prefix/clang" cc = "${compiler_prefix}$prefix/clang"
cxx = "${compiler_prefix}$prefix/clang++" cxx = "${compiler_prefix}$prefix/clang++"
readelf = "readelf"
nm = "nm"
ar = "ar" ar = "ar"
ld = cxx ld = cxx
...@@ -83,6 +90,8 @@ gcc_toolchain("x64") { ...@@ -83,6 +90,8 @@ gcc_toolchain("x64") {
cc = "${compiler_prefix}gcc" cc = "${compiler_prefix}gcc"
cxx = "${compiler_prefix}g++" cxx = "${compiler_prefix}g++"
readelf = "readelf"
nm = "nm"
ar = "ar" ar = "ar"
ld = cxx ld = cxx
...@@ -96,6 +105,8 @@ gcc_toolchain("mipsel") { ...@@ -96,6 +105,8 @@ gcc_toolchain("mipsel") {
cxx = "mipsel-linux-gnu-g++" cxx = "mipsel-linux-gnu-g++"
ar = "mipsel-linux-gnu-ar" ar = "mipsel-linux-gnu-ar"
ld = cxx ld = cxx
readelf = "mipsel-linux-gnu-readelf"
nm = "mipsel-linux-gnu-nm"
toolchain_cpu = "mipsel" toolchain_cpu = "mipsel"
toolchain_os = "linux" toolchain_os = "linux"
......
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
import("../goma.gni") import("../goma.gni")
# Should only be running on Mac. assert(host_os == "mac")
assert(is_mac || is_ios)
import("//build/toolchain/clang.gni") import("//build/toolchain/clang.gni")
import("//build/toolchain/goma.gni") import("//build/toolchain/goma.gni")
...@@ -20,19 +19,6 @@ if (use_goma) { ...@@ -20,19 +19,6 @@ if (use_goma) {
goma_prefix = "" goma_prefix = ""
} }
if (is_clang) {
cc = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang",
root_build_dir)
cxx = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang++",
root_build_dir)
} else {
cc = "gcc"
cxx = "g++"
}
cc = goma_prefix + cc
cxx = goma_prefix + cxx
ld = cxx
# This will copy the gyp-mac-tool to the build directory. We pass in the source # This will copy the gyp-mac-tool to the build directory. We pass in the source
# file of the win tool. # file of the win tool.
gyp_mac_tool_source = gyp_mac_tool_source =
...@@ -41,16 +27,15 @@ exec_script("setup_toolchain.py", [ gyp_mac_tool_source ]) ...@@ -41,16 +27,15 @@ exec_script("setup_toolchain.py", [ gyp_mac_tool_source ])
# Shared toolchain definition. Invocations should set toolchain_os to set the # Shared toolchain definition. Invocations should set toolchain_os to set the
# build args in this definition. # build args in this definition.
template("mac_clang_toolchain") { template("mac_toolchain") {
toolchain(target_name) { toolchain(target_name) {
assert(defined(invoker.cc), assert(defined(invoker.cc), "mac_toolchain() must specify a \"cc\" value")
"mac_clang_toolchain() must specify a \"cc\" value") assert(defined(invoker.cxx), "mac_toolchain() must specify a \"cxx\" value")
assert(defined(invoker.cxx), assert(defined(invoker.ld), "mac_toolchain() must specify a \"ld\" value")
"mac_clang_toolchain() must specify a \"cxx\" value") assert(defined(invoker.toolchain_cpu),
assert(defined(invoker.ld), "mac_toolchain() must specify a \"toolchain_cpu\"")
"mac_clang_toolchain() must specify a \"ld\" value")
assert(defined(invoker.toolchain_os), assert(defined(invoker.toolchain_os),
"mac_clang_toolchain() must specify a \"toolchain_os\"") "mac_toolchain() must specify a \"toolchain_os\"")
# We can't do string interpolation ($ in strings) on things with dots in # We can't do string interpolation ($ in strings) on things with dots in
# them. To allow us to use $cc below, for example, we create copies of # them. To allow us to use $cc below, for example, we create copies of
...@@ -194,18 +179,56 @@ template("mac_clang_toolchain") { ...@@ -194,18 +179,56 @@ template("mac_clang_toolchain") {
} }
toolchain_args() { toolchain_args() {
current_cpu = invoker.toolchain_cpu
current_os = invoker.toolchain_os current_os = invoker.toolchain_os
# These values need to be passed through unchanged.
target_os = target_os
target_cpu = target_cpu
if (defined(invoker.is_clang)) {
is_clang = invoker.is_clang
}
} }
} }
} }
# Toolchain representing the target build (either mac or iOS). mac_toolchain("clang_arm") {
mac_clang_toolchain("clang") { toolchain_cpu = "arm"
toolchain_os = current_os toolchain_os = "mac"
prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
root_build_dir)
cc = "${goma_prefix}$prefix/clang"
cxx = "${goma_prefix}$prefix/clang++"
ld = cxx
is_clang = true
}
mac_toolchain("arm") {
toolchain_cpu = "arm"
toolchain_os = "mac"
cc = "${goma_prefix}/gcc"
cxx = "${goma_prefix}/g++"
ld = cxx
is_clang = false
}
mac_toolchain("clang_x64") {
toolchain_cpu = "x64"
toolchain_os = "mac"
prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
root_build_dir)
cc = "${goma_prefix}$prefix/clang"
cxx = "${goma_prefix}$prefix/clang++"
ld = cxx
is_clang = true
} }
# This toolchain provides a way for iOS target compiles to reference targets mac_toolchain("x64") {
# compiled for the host system. It just overrides the OS back to "mac". toolchain_cpu = "x64"
mac_clang_toolchain("host_clang") {
toolchain_os = "mac" toolchain_os = "mac"
cc = "${goma_prefix}/gcc"
cxx = "${goma_prefix}/g++"
ld = cxx
is_clang = false
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment