gn build: Create a template for unix toolchains.

Also change the toolchain description to use current_os instead of
host_os so that the template can be used for cross builds, and add
a current_os to the win toolchain to match the unix toolchain.

Differential Revision: https://reviews.llvm.org/D56576

llvm-svn: 350977
This commit is contained in:
Peter Collingbourne 2019-01-11 22:57:57 +00:00
parent 7d7e3256cd
commit ad7f1d605c
1 changed files with 114 additions and 98 deletions

View File

@ -9,20 +9,9 @@ declare_args() {
} }
} }
toolchain("unix") { template("unix_toolchain") {
cc = "cc" toolchain(target_name) {
cxx = "c++" forward_variables_from(invoker, "*")
if (clang_base_path != "") {
cc = "$clang_base_path/bin/clang"
cxx = "$clang_base_path/bin/clang++"
}
ld = cxx # Don't use goma wrapper for linking.
if (use_goma) {
cc = "$goma_dir/gomacc $cc"
cxx = "$goma_dir/gomacc $cxx"
}
tool("cc") { tool("cc") {
depfile = "{{output}}.d" depfile = "{{output}}.d"
@ -45,12 +34,12 @@ toolchain("unix") {
} }
tool("alink") { tool("alink") {
if (host_os == "mac") { if (current_os == "mac") {
command = "libtool -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}" command = "libtool -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}"
} else { } else {
# Remove the output file first so that ar doesn't try to modify the # Remove the output file first so that ar doesn't try to modify the
# existing file. # existing file.
command = "rm -f {{output}} && ar rcsDT {{arflags}} {{output}} {{inputs}}" command = "rm -f {{output}} && $ar rcsDT {{arflags}} {{output}} {{inputs}}"
} }
description = "AR {{output}}" description = "AR {{output}}"
outputs = [ outputs = [
@ -62,7 +51,7 @@ toolchain("unix") {
tool("solink") { tool("solink") {
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
if (host_os == "mac") { if (current_os == "mac") {
command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}" command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".dylib" default_output_extension = ".dylib"
} else { } else {
@ -81,7 +70,7 @@ toolchain("unix") {
tool("solink_module") { tool("solink_module") {
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
if (host_os == "mac") { if (current_os == "mac") {
command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}}" command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".dylib" default_output_extension = ".dylib"
} else { } else {
@ -98,7 +87,7 @@ toolchain("unix") {
tool("link") { tool("link") {
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
if (host_os == "mac") { if (current_os == "mac") {
command = "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}}" command = "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}}"
} else { } else {
command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group" command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group"
@ -124,6 +113,29 @@ toolchain("unix") {
description = "STAMP {{output}}" description = "STAMP {{output}}"
} }
} }
}
unix_toolchain("unix") {
cc = "cc"
cxx = "c++"
if (clang_base_path != "") {
cc = "$clang_base_path/bin/clang"
cxx = "$clang_base_path/bin/clang++"
}
ld = cxx # Don't use goma wrapper for linking.
if (use_goma) {
cc = "$goma_dir/gomacc $cc"
cxx = "$goma_dir/gomacc $cxx"
}
ar = "ar"
toolchain_args = {
current_os = host_os
}
}
toolchain("win") { toolchain("win") {
cl = "cl" cl = "cl"
@ -228,4 +240,8 @@ toolchain("win") {
command = "cmd /c type nul > {{output}}" command = "cmd /c type nul > {{output}}"
description = "STAMP {{output}}" description = "STAMP {{output}}"
} }
toolchain_args = {
current_os = "win"
}
} }