|
| 1 | +# Copyright (C) <2021> Intel Corporation |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +# Copyright (C) 2018 The Android Open Source Project |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | + |
| 19 | +# This file is copied from third_party/perfetto/gn/standalone/toolchain/BUILD.gn with modifications. |
| 20 | + |
| 21 | +import("//build/config/compiler/compiler.gni") |
| 22 | +import("wasm.gni") |
| 23 | + |
| 24 | +template("gcc_like_toolchain") { |
| 25 | + toolchain(target_name) { |
| 26 | + ar = invoker.ar |
| 27 | + cc = invoker.cc |
| 28 | + cxx = invoker.cxx |
| 29 | + lib_switch = "-l" |
| 30 | + lib_dir_switch = "-L" |
| 31 | + ld_arg = "" |
| 32 | + external_cflags = "" |
| 33 | + external_cxxflags = "" |
| 34 | + external_ldflags = "" |
| 35 | + strip = "" |
| 36 | + if (defined(invoker.linker) && invoker.linker != "") { |
| 37 | + _invoker_linker = invoker.linker |
| 38 | + ld_arg = "-fuse-ld=$_invoker_linker" |
| 39 | + } |
| 40 | + if (defined(invoker.sysroot) && invoker.sysroot != "") { |
| 41 | + _invoker_sysroot = invoker.sysroot |
| 42 | + cc = "$cc --sysroot=$_invoker_sysroot" |
| 43 | + cxx = "$cxx --sysroot=$_invoker_sysroot" |
| 44 | + } |
| 45 | + if (defined(invoker.gcc_toolchain) && invoker.gcc_toolchain != "") { |
| 46 | + assert(is_clang, "gcc_toolchain can be used only when using clang") |
| 47 | + _invoker_gcc_toolchain = invoker.gcc_toolchain |
| 48 | + ld_arg = "$ld_arg --gcc-toolchain=$_invoker_gcc_toolchain" |
| 49 | + } |
| 50 | + if (defined(invoker.external_cflags)) { |
| 51 | + external_cflags = invoker.external_cflags |
| 52 | + } |
| 53 | + if (defined(invoker.external_cxxflags)) { |
| 54 | + external_cxxflags = invoker.external_cxxflags |
| 55 | + } |
| 56 | + if (defined(invoker.external_ldflags)) { |
| 57 | + external_ldflags = invoker.external_ldflags |
| 58 | + } |
| 59 | + if (defined(invoker.strip)) { |
| 60 | + strip = invoker.strip |
| 61 | + } |
| 62 | + |
| 63 | + # Object files go in this directory. |
| 64 | + object_subdir = "{{target_out_dir}}/{{label_name}}" |
| 65 | + |
| 66 | + tool("cc") { |
| 67 | + depfile = "{{output}}.d" |
| 68 | + command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -fno-stack-protector ${external_cflags} -msimd128 -pthread -D__wasm__ -c {{source}} -o {{output}}" |
| 69 | + depsformat = "gcc" |
| 70 | + outputs = [ "$object_subdir/{{source_name_part}}.o" ] |
| 71 | + description = "compile {{source}}" |
| 72 | + } |
| 73 | + |
| 74 | + tool("cxx") { |
| 75 | + depfile = "{{output}}.d" |
| 76 | + command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -fno-stack-protector ${external_cflags} -msimd128 -pthread -D__wasm__ ${external_cxxflags} -c {{source}} -o {{output}}" |
| 77 | + depsformat = "gcc" |
| 78 | + outputs = [ "$object_subdir/{{source_name_part}}.o" ] |
| 79 | + description = "compile {{source}}" |
| 80 | + } |
| 81 | + |
| 82 | + tool("asm") { |
| 83 | + depfile = "{{output}}.d" |
| 84 | + command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -fno-stack-protector -c {{source}} -o {{output}}" |
| 85 | + depsformat = "gcc" |
| 86 | + outputs = [ "$object_subdir/{{source_name_part}}.o" ] |
| 87 | + description = "assemble {{source}}" |
| 88 | + } |
| 89 | + |
| 90 | + tool("alink") { |
| 91 | + if (current_os == "aix") { |
| 92 | + # AIX does not support either -D (deterministic output) or response |
| 93 | + # files. |
| 94 | + command = "$ar -X64 {{arflags}} -r -c -s {{output}} {{inputs}}" |
| 95 | + } else { |
| 96 | + rspfile = "{{output}}.rsp" |
| 97 | + rspfile_content = "{{inputs}}" |
| 98 | + command = "$ar {{arflags}} -r -c -s -D {{output}} @\"$rspfile\"" |
| 99 | + } |
| 100 | + |
| 101 | + # Remove the output file first so that ar doesn't try to modify the |
| 102 | + # existing file. |
| 103 | + if (host_os == "win") { |
| 104 | + tool_wrapper_path = |
| 105 | + rebase_path("//build/toolchain/win/tool_wrapper.py", root_build_dir) |
| 106 | + command = "cmd /c $python_path $tool_wrapper_path delete-file {{output}} && $command" |
| 107 | + } else { |
| 108 | + command = "rm -f {{output}} && $command" |
| 109 | + } |
| 110 | + |
| 111 | + # Almost all targets build with //build/config/compiler:thin_archive which |
| 112 | + # adds -T to arflags. |
| 113 | + description = "AR {{output}}" |
| 114 | + outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ] |
| 115 | + |
| 116 | + # Shared libraries go in the target out directory by default so we can |
| 117 | + # generate different targets with the same name and not have them collide. |
| 118 | + default_output_dir = "{{target_out_dir}}" |
| 119 | + default_output_extension = ".a" |
| 120 | + output_prefix = "lib" |
| 121 | + } |
| 122 | + |
| 123 | + tool("solink") { |
| 124 | + soname = "{{target_output_name}}{{output_extension}}" |
| 125 | + unstripped_so = "{{root_out_dir}}/$soname" |
| 126 | + rpath = "-Wl,-soname,$soname" |
| 127 | + if (is_mac) { |
| 128 | + rpath = "-Wl,-install_name,@rpath/$soname" |
| 129 | + } |
| 130 | + command = "$cc_wrapper $cxx $ld_arg -shared ${external_ldflags} -fstack-protector {{inputs}} {{solibs}} {{libs}} $rpath -o $unstripped_so" |
| 131 | + outputs = [ unstripped_so ] |
| 132 | + output_prefix = "lib" |
| 133 | + default_output_extension = ".so" |
| 134 | + description = "link $unstripped_so" |
| 135 | + if (strip != "") { |
| 136 | + stripped_so = "{{root_out_dir}}/stripped/$soname" |
| 137 | + outputs += [ stripped_so ] |
| 138 | + command += " && $strip -o $stripped_so $unstripped_so" |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + tool("link") { |
| 143 | + unstripped_exe = |
| 144 | + "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" |
| 145 | + command = "$cc_wrapper $cxx $ld_arg ${external_ldflags} {{inputs}} {{solibs}} {{libs}} -o $unstripped_exe" |
| 146 | + outputs = [ unstripped_exe ] |
| 147 | + description = "link $unstripped_exe" |
| 148 | + if (strip != "") { |
| 149 | + stripped_exe = "{{root_out_dir}}/stripped/{{target_output_name}}{{output_extension}}" |
| 150 | + outputs += [ stripped_exe ] |
| 151 | + command += " && $strip -o $stripped_exe $unstripped_exe" |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + tool("stamp") { |
| 156 | + command = "touch {{output}}" |
| 157 | + description = "stamp {{output}}" |
| 158 | + } |
| 159 | + |
| 160 | + tool("copy") { |
| 161 | + command = "cp -af {{source}} {{output}}" |
| 162 | + description = "COPY {{source}} {{output}}" |
| 163 | + } |
| 164 | + |
| 165 | + toolchain_args = { |
| 166 | + current_cpu = invoker.cpu |
| 167 | + current_os = invoker.os |
| 168 | + } |
| 169 | + } |
| 170 | +} |
| 171 | + |
| 172 | +gcc_like_toolchain("wasm") { |
| 173 | + # emsdk_dir and em_config are defined in wasm.gni. |
| 174 | + cpu = host_cpu |
| 175 | + os = host_os |
| 176 | + ar = "emar --em-config $em_config" |
| 177 | + cc = "emcc --em-config $em_config" |
| 178 | + cxx = "em++ --em-config $em_config" |
| 179 | + strip = "" |
| 180 | +} |
0 commit comments