|
| 1 | +# Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
| 2 | +# for details. All rights reserved. Use of this source code is governed by a |
| 3 | +# BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import("//build/config/sysroot.gni") |
| 6 | +import("//build/toolchain/ccache.gni") |
| 7 | +import("//build/toolchain/gcc_toolchain.gni") |
| 8 | +import("//build/toolchain/goma.gni") |
| 9 | + |
| 10 | +if (use_goma) { |
| 11 | + assert(!use_ccache, "Goma and ccache can't be used together.") |
| 12 | + compiler_prefix = "$goma_dir/gomacc " |
| 13 | +} else if (use_ccache) { |
| 14 | + compiler_prefix = "ccache " |
| 15 | +} else { |
| 16 | + compiler_prefix = "" |
| 17 | +} |
| 18 | + |
| 19 | +toolchain("fuchsia") { |
| 20 | + assert(target_cpu == "x64", "We currently only support 'x64' for fuchsia.") |
| 21 | + toolchain_bin = |
| 22 | + rebase_path("//buildtools/$host_os-$target_cpu/clang/bin", root_out_dir) |
| 23 | + fuchsia_sdk = rebase_path("//third_party/fuchsia/sdk/$host_os", root_out_dir) |
| 24 | + |
| 25 | + # We can't do string interpolation ($ in strings) on things with dots in |
| 26 | + # them. To allow us to use $cc below, for example, we create copies of |
| 27 | + # these values in our scope. |
| 28 | + cc = "${toolchain_bin}/clang" |
| 29 | + cxx = "${toolchain_bin}/clang++" |
| 30 | + ar = "${toolchain_bin}/llvm-ar" |
| 31 | + ld = "${toolchain_bin}/clang++" |
| 32 | + readelf = "${toolchain_bin}/llvm-readelf" |
| 33 | + nm = "${toolchain_bin}/llvm-nm" |
| 34 | + strip = "${toolchain_bin}/llvm-strip" |
| 35 | + |
| 36 | + target_triple_flags = "--target=x86_64-fuchsia" |
| 37 | + sysroot_flags = "--sysroot ${fuchsia_sdk}/arch/${target_cpu}/sysroot" |
| 38 | + lto_flags = "" |
| 39 | + |
| 40 | + # These library switches can apply to all tools below. |
| 41 | + lib_switch = "-l" |
| 42 | + lib_dir_switch = "-L" |
| 43 | + |
| 44 | + tool("cc") { |
| 45 | + depfile = "{{output}}.d" |
| 46 | + command = "$compiler_prefix $cc -MD -MF $depfile $target_triple_flags $sysroot_flags $lto_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
| 47 | + depsformat = "gcc" |
| 48 | + description = "CC {{output}}" |
| 49 | + outputs = |
| 50 | + [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] |
| 51 | + } |
| 52 | + |
| 53 | + tool("cxx") { |
| 54 | + depfile = "{{output}}.d" |
| 55 | + command = "$compiler_prefix $cxx -MD -MF $depfile $target_triple_flags $sysroot_flags $lto_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" |
| 56 | + depsformat = "gcc" |
| 57 | + description = "CXX {{output}}" |
| 58 | + outputs = |
| 59 | + [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] |
| 60 | + } |
| 61 | + |
| 62 | + tool("asm") { |
| 63 | + depfile = "{{output}}.d" |
| 64 | + command = "$compiler_prefix $cc -MD -MF $depfile $target_triple_flags $sysroot_flags $lto_flags {{defines}} {{include_dirs}} {{asmflags}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
| 65 | + depsformat = "gcc" |
| 66 | + description = "ASM {{output}}" |
| 67 | + outputs = |
| 68 | + [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ] |
| 69 | + } |
| 70 | + |
| 71 | + tool("alink") { |
| 72 | + rspfile = "{{output}}.rsp" |
| 73 | + command = "rm -f {{output}} && $ar rcs {{output}} @$rspfile" |
| 74 | + description = "AR {{output}}" |
| 75 | + rspfile_content = "{{inputs}}" |
| 76 | + outputs = |
| 77 | + [ "{{target_out_dir}}/{{target_output_name}}{{output_extension}}" ] |
| 78 | + default_output_extension = ".a" |
| 79 | + output_prefix = "lib" |
| 80 | + } |
| 81 | + |
| 82 | + tool("solink") { |
| 83 | + soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". |
| 84 | + sofile = "{{root_out_dir}}/$soname" # Possibly including toolchain dir. |
| 85 | + unstripped_sofile = |
| 86 | + "{{root_out_dir}}/so.unstripped/$soname" # Possibly including toolchain |
| 87 | + # dir. |
| 88 | + rspfile = sofile + ".rsp" |
| 89 | + |
| 90 | + # These variables are not built into GN but are helpers that implement |
| 91 | + # (1) linking to produce a .so, (2) extracting the symbols from that file |
| 92 | + # to a temporary file, (3) if the temporary file has differences from the |
| 93 | + # existing .TOC file, overwrite it, otherwise, don't change it. |
| 94 | + tocfile = sofile + ".TOC" |
| 95 | + temporary_tocname = sofile + ".tmp" |
| 96 | + link_command = "$compiler_prefix $ld $target_triple_flags $sysroot_flags $lto_flags -shared {{ldflags}} -o $unstripped_sofile -Wl,--build-id -Wl,-soname=$soname @$rspfile" |
| 97 | + toc_command = "{ $readelf -d $unstripped_sofile | grep SONAME ; $nm -gD -f posix $unstripped_sofile | cut -f1-2 -d' '; } > $temporary_tocname" |
| 98 | + replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $temporary_tocname $tocfile; fi" |
| 99 | + strip_command = "$strip -o $sofile $unstripped_sofile" |
| 100 | + |
| 101 | + command = |
| 102 | + "$link_command && $toc_command && $replace_command && $strip_command" |
| 103 | + rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" |
| 104 | + |
| 105 | + description = "SOLINK $sofile" |
| 106 | + |
| 107 | + default_output_extension = ".so" |
| 108 | + |
| 109 | + output_prefix = "lib" |
| 110 | + |
| 111 | + # Since the above commands only updates the .TOC file when it changes, ask |
| 112 | + # Ninja to check if the timestamp actually changed to know if downstream |
| 113 | + # dependencies should be recompiled. |
| 114 | + restat = true |
| 115 | + |
| 116 | + # Tell GN about the output files. It will link to the sofile but use the |
| 117 | + # tocfile for dependency management. |
| 118 | + outputs = [ |
| 119 | + sofile, |
| 120 | + unstripped_sofile, |
| 121 | + tocfile, |
| 122 | + ] |
| 123 | + |
| 124 | + link_output = sofile |
| 125 | + depend_output = tocfile |
| 126 | + } |
| 127 | + |
| 128 | + tool("link") { |
| 129 | + exename = "{{target_output_name}}{{output_extension}}" |
| 130 | + outfile = "{{root_out_dir}}/$exename" |
| 131 | + rspfile = "$outfile.rsp" |
| 132 | + unstripped_outfile = "{{root_out_dir}}/exe.stripped/$exename" |
| 133 | + command = "$compiler_prefix $ld $target_triple_flags $sysroot_flags $lto_flags {{ldflags}} -o $unstripped_outfile -Wl,--build-id -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}} && ${strip} -o $outfile $unstripped_outfile" |
| 134 | + description = "LINK $outfile" |
| 135 | + rspfile_content = "{{inputs}}" |
| 136 | + outputs = [ |
| 137 | + unstripped_outfile, |
| 138 | + outfile, |
| 139 | + ] |
| 140 | + } |
| 141 | + |
| 142 | + tool("stamp") { |
| 143 | + command = "touch {{output}}" |
| 144 | + description = "STAMP {{output}}" |
| 145 | + } |
| 146 | + |
| 147 | + tool("copy") { |
| 148 | + command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})" |
| 149 | + description = "COPY {{source}} {{output}}" |
| 150 | + } |
| 151 | + |
| 152 | + # When invoking this toolchain not as the default one, these args will be |
| 153 | + # passed to the build. They are ignored when this is the default toolchain. |
| 154 | + toolchain_args = { |
| 155 | + current_cpu = target_cpu |
| 156 | + current_os = target_os |
| 157 | + |
| 158 | + # These values need to be passed through unchanged. |
| 159 | + target_os = target_os |
| 160 | + target_cpu = target_cpu |
| 161 | + |
| 162 | + is_clang = true |
| 163 | + } |
| 164 | +} |
0 commit comments