aboutsummaryrefslogtreecommitdiff
path: root/pw_toolchain/host_clang/BUILD.gn
blob: 4e4ddb733ad2c1cdb889f12a44df6aba29b0175b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright 2020 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

import("//build_overrides/pigweed.gni")

# See https://github.com/google/sanitizers
config("sanitize_address") {
  cflags = [ "-fsanitize=address" ]
  ldflags = cflags
}

config("sanitize_memory") {
  cflags = [ "-fsanitize=memory" ]
  ldflags = cflags
}

config("sanitize_undefined") {
  cflags = [ "-fsanitize=undefined" ]
  ldflags = cflags
}

# Locate XCode's sysroot for Clang.
config("xcode_sysroot") {
  if (current_os == "mac") {
    _xcode_sysroot = exec_script("$dir_pw_build/py/pw_build/exec.py",
                                 [
                                   "--",
                                   "/usr/bin/xcrun",
                                   "--show-sdk-path",
                                 ],
                                 "trim string")
    cflags = [ "--sysroot=$_xcode_sysroot" ]
    ldflags = cflags
  }
}

# The CIPD provided Clang/LLVM toolchain must link against the matched
# libc++ which is also from CIPD. However, by default, Clang on Mac (but
# not on Linux) will fall back to the system libc++, which is
# incompatible due to an ABI change.
#
# Pull the appropriate pathd from our Pigweed env setup.
config("no_system_libcpp") {
  if (current_os == "mac") {
    install_dir = getenv("PW_PIGWEED_CIPD_INSTALL_DIR")
    assert(install_dir != "",
           "You forgot to activate the Pigweed environment; " +
               "did you source pw_env_setup/setup.sh?")
    ldflags = [
      # Force dropping the system libc++
      "-nostdlib++",

      # Use the libc++ from CIPD.
      getenv("PW_PIGWEED_CIPD_INSTALL_DIR") + "/lib/libc++.a",
    ]
  }
}