• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2013 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# This header file defines the "sysroot" variable which is the absolute path
6# of the sysroot. If no sysroot applies, the variable will be an empty string.
7
8declare_args() {
9  # The path of the sysroot that is applied when compiling using the target
10  # toolchain.
11  target_sysroot = ""
12
13  # The path to directory containing linux sysroot images.
14  target_sysroot_dir = "//build/linux"
15
16  # The path of the sysroot for the current toolchain. If empty, default
17  # sysroot is used.
18  sysroot = ""
19
20  # Controls default is_linux sysroot. If set to true, and sysroot
21  # is empty, default sysroot is calculated.
22  use_sysroot =
23      current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm" ||
24      current_cpu == "arm64" || current_cpu == "mipsel" ||
25      current_cpu == "mips64el" || (current_cpu == "riscv64" && is_android)
26}
27
28if (sysroot == "") {
29  if (current_os == target_os && current_cpu == target_cpu &&
30      target_sysroot != "") {
31    sysroot = target_sysroot
32  } else if (is_android) {
33    import("//build/config/android/config.gni")
34
35    # Android uses unified headers, and thus a single compile time sysroot
36    sysroot = "$android_toolchain_root/sysroot"
37  } else if ((is_linux || is_chromeos) && use_sysroot) {
38    # By default build against a sysroot image downloaded from Cloud Storage
39    # during gclient runhooks.
40    if (current_cpu == "x64") {
41      sysroot = "$target_sysroot_dir/debian_bullseye_amd64-sysroot"
42    } else if (current_cpu == "x86") {
43      sysroot = "$target_sysroot_dir/debian_bullseye_i386-sysroot"
44    } else if (current_cpu == "mipsel") {
45      sysroot = "$target_sysroot_dir/debian_bullseye_mipsel-sysroot"
46    } else if (current_cpu == "mips64el") {
47      sysroot = "$target_sysroot_dir/debian_bullseye_mips64el-sysroot"
48    } else if (current_cpu == "arm") {
49      sysroot = "$target_sysroot_dir/debian_bullseye_armhf-sysroot"
50    } else if (current_cpu == "arm64") {
51      sysroot = "$target_sysroot_dir/debian_bullseye_arm64-sysroot"
52    } else {
53      assert(false, "No linux sysroot for cpu: $target_cpu")
54    }
55
56    if (sysroot != "") {
57      _script_arch = current_cpu
58      if (_script_arch == "x86") {
59        _script_arch = "i386"
60      } else if (_script_arch == "x64") {
61        _script_arch = "amd64"
62      }
63      assert(
64          exec_script("//build/dir_exists.py",
65                      [ rebase_path(sysroot) ],
66                      "string") == "True",
67          "Missing sysroot ($sysroot). To fix, run: build/linux/sysroot_scripts/install-sysroot.py --arch=$_script_arch")
68    }
69  } else if (is_mac) {
70    import("//build/config/mac/mac_sdk.gni")
71    sysroot = mac_sdk_path
72  } else if (is_ios) {
73    import("//build/config/ios/ios_sdk.gni")
74    sysroot = ios_sdk_path
75  } else if (is_fuchsia) {
76    if (current_cpu == "arm64" || current_cpu == "x64") {
77      sysroot = "//third_party/fuchsia-sdk/sdk/arch/$current_cpu/sysroot"
78    }
79  }
80}
81