├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── WORKSPACE ├── build_files ├── BUILD ├── gtest.BUILD ├── org_chromium_binutils_linux_x64.BUILD ├── org_chromium_clang_linux_x64.BUILD ├── org_chromium_clang_mac.BUILD ├── org_chromium_libcxx.BUILD ├── org_chromium_libcxxabi.BUILD └── org_chromium_sysroot_linux_x64.BUILD ├── scripts ├── chromium_repo.py ├── generate_workspace.py ├── install_bazel.sh └── license_block.txt ├── src ├── BUILD ├── allocation_test.cpp ├── string_test.cpp └── version_test.cpp ├── toolchains ├── BUILD ├── libcxx_library.bzl └── repositories.bzl └── tools └── cpp ├── BUILD ├── CROSSTOOL └── tool_wrappers ├── linux_x64 ├── BUILD ├── chromium_ar ├── chromium_as ├── chromium_clang ├── chromium_ld ├── chromium_nm ├── chromium_objcopy ├── chromium_objdump ├── chromium_strip └── ld └── mac ├── BUILD └── osx_clang_wrapper.sh /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | **/*.pyc 3 | bazel-* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | 3 | osx_image: xcode8.3 4 | language: java 5 | 6 | os: 7 | - linux 8 | - osx 9 | 10 | env: 11 | - BAZEL_VERSION=0.12.0 12 | - BAZEL_VERSION=0.13.1 13 | - BAZEL_VERSION=0.14.1 14 | - BAZEL_VERSION=0.15.2 15 | - BAZEL_VERSION=0.16.1 16 | - BAZEL_VERSION=0.17.2 17 | - BAZEL_VERSION=0.18.1 18 | - BAZEL_VERSION=0.19.2 19 | 20 | matrix: 21 | fast_finish: true 22 | 23 | before_install: 24 | - echo $TRAVIS_OS_NAME; 25 | - unset CC 26 | - unset CXX 27 | - scripts/install_bazel.sh 28 | 29 | script: 30 | - bazel test --crosstool_top=//tools/cpp:default-toolchain //src/... 31 | 32 | notifications: 33 | email: false 34 | slack: false 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Visual Supply, Co. All rights reserved. 2 | 3 | Apache License 4 | Version 2.0, January 2004 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, 12 | and distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by 15 | the copyright owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all 18 | other entities that control, are controlled by, or are under common 19 | control with that entity. For the purposes of this definition, 20 | "control" means (i) the power, direct or indirect, to cause the 21 | direction or management of such entity, whether by contract or 22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 23 | outstanding shares, or (iii) beneficial ownership of such entity. 24 | 25 | "You" (or "Your") shall mean an individual or Legal Entity 26 | exercising permissions granted by this License. 27 | 28 | "Source" form shall mean the preferred form for making modifications, 29 | including but not limited to software source code, documentation 30 | source, and configuration files. 31 | 32 | "Object" form shall mean any form resulting from mechanical 33 | transformation or translation of a Source form, including but 34 | not limited to compiled object code, generated documentation, 35 | and conversions to other media types. 36 | 37 | "Work" shall mean the work of authorship, whether in Source or 38 | Object form, made available under the License, as indicated by a 39 | copyright notice that is included in or attached to the work 40 | (an example is provided in the Appendix below). 41 | 42 | "Derivative Works" shall mean any work, whether in Source or Object 43 | form, that is based on (or derived from) the Work and for which the 44 | editorial revisions, annotations, elaborations, or other modifications 45 | represent, as a whole, an original work of authorship. For the purposes 46 | of this License, Derivative Works shall not include works that remain 47 | separable from, or merely link (or bind by name) to the interfaces of, 48 | the Work and Derivative Works thereof. 49 | 50 | "Contribution" shall mean any work of authorship, including 51 | the original version of the Work and any modifications or additions 52 | to that Work or Derivative Works thereof, that is intentionally 53 | submitted to Licensor for inclusion in the Work by the copyright owner 54 | or by an individual or Legal Entity authorized to submit on behalf of 55 | the copyright owner. For the purposes of this definition, "submitted" 56 | means any form of electronic, verbal, or written communication sent 57 | to the Licensor or its representatives, including but not limited to 58 | communication on electronic mailing lists, source code control systems, 59 | and issue tracking systems that are managed by, or on behalf of, the 60 | Licensor for the purpose of discussing and improving the Work, but 61 | excluding communication that is conspicuously marked or otherwise 62 | designated in writing by the copyright owner as "Not a Contribution." 63 | 64 | "Contributor" shall mean Licensor and any individual or Legal Entity 65 | on behalf of whom a Contribution has been received by Licensor and 66 | subsequently incorporated within the Work. 67 | 68 | 2. Grant of Copyright License. Subject to the terms and conditions of 69 | this License, each Contributor hereby grants to You a perpetual, 70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 71 | copyright license to reproduce, prepare Derivative Works of, 72 | publicly display, publicly perform, sublicense, and distribute the 73 | Work and such Derivative Works in Source or Object form. 74 | 75 | 3. Grant of Patent License. Subject to the terms and conditions of 76 | this License, each Contributor hereby grants to You a perpetual, 77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 78 | (except as stated in this section) patent license to make, have made, 79 | use, offer to sell, sell, import, and otherwise transfer the Work, 80 | where such license applies only to those patent claims licensable 81 | by such Contributor that are necessarily infringed by their 82 | Contribution(s) alone or by combination of their Contribution(s) 83 | with the Work to which such Contribution(s) was submitted. If You 84 | institute patent litigation against any entity (including a 85 | cross-claim or counterclaim in a lawsuit) alleging that the Work 86 | or a Contribution incorporated within the Work constitutes direct 87 | or contributory patent infringement, then any patent licenses 88 | granted to You under this License for that Work shall terminate 89 | as of the date such litigation is filed. 90 | 91 | 4. Redistribution. You may reproduce and distribute copies of the 92 | Work or Derivative Works thereof in any medium, with or without 93 | modifications, and in Source or Object form, provided that You 94 | meet the following conditions: 95 | 96 | (a) You must give any other recipients of the Work or 97 | Derivative Works a copy of this License; and 98 | 99 | (b) You must cause any modified files to carry prominent notices 100 | stating that You changed the files; and 101 | 102 | (c) You must retain, in the Source form of any Derivative Works 103 | that You distribute, all copyright, patent, trademark, and 104 | attribution notices from the Source form of the Work, 105 | excluding those notices that do not pertain to any part of 106 | the Derivative Works; and 107 | 108 | (d) If the Work includes a "NOTICE" text file as part of its 109 | distribution, then any Derivative Works that You distribute must 110 | include a readable copy of the attribution notices contained 111 | within such NOTICE file, excluding those notices that do not 112 | pertain to any part of the Derivative Works, in at least one 113 | of the following places: within a NOTICE text file distributed 114 | as part of the Derivative Works; within the Source form or 115 | documentation, if provided along with the Derivative Works; or, 116 | within a display generated by the Derivative Works, if and 117 | wherever such third-party notices normally appear. The contents 118 | of the NOTICE file are for informational purposes only and 119 | do not modify the License. You may add Your own attribution 120 | notices within Derivative Works that You distribute, alongside 121 | or as an addendum to the NOTICE text from the Work, provided 122 | that such additional attribution notices cannot be construed 123 | as modifying the License. 124 | 125 | You may add Your own copyright statement to Your modifications and 126 | may provide additional or different license terms and conditions 127 | for use, reproduction, or distribution of Your modifications, or 128 | for any such Derivative Works as a whole, provided Your use, 129 | reproduction, and distribution of the Work otherwise complies with 130 | the conditions stated in this License. 131 | 132 | 5. Submission of Contributions. Unless You explicitly state otherwise, 133 | any Contribution intentionally submitted for inclusion in the Work 134 | by You to the Licensor shall be under the terms and conditions of 135 | this License, without any additional terms or conditions. 136 | Notwithstanding the above, nothing herein shall supersede or modify 137 | the terms of any separate license agreement you may have executed 138 | with Licensor regarding such Contributions. 139 | 140 | 6. Trademarks. This License does not grant permission to use the trade 141 | names, trademarks, service marks, or product names of the Licensor, 142 | except as required for reasonable and customary use in describing the 143 | origin of the Work and reproducing the content of the NOTICE file. 144 | 145 | 7. Disclaimer of Warranty. Unless required by applicable law or 146 | agreed to in writing, Licensor provides the Work (and each 147 | Contributor provides its Contributions) on an "AS IS" BASIS, 148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 149 | implied, including, without limitation, any warranties or conditions 150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 151 | PARTICULAR PURPOSE. You are solely responsible for determining the 152 | appropriateness of using or redistributing the Work and assume any 153 | risks associated with Your exercise of permissions under this License. 154 | 155 | 8. Limitation of Liability. In no event and under no legal theory, 156 | whether in tort (including negligence), contract, or otherwise, 157 | unless required by applicable law (such as deliberate and grossly 158 | negligent acts) or agreed to in writing, shall any Contributor be 159 | liable to You for damages, including any direct, indirect, special, 160 | incidental, or consequential damages of any character arising as a 161 | result of this License or out of the use or inability to use the 162 | Work (including but not limited to damages for loss of goodwill, 163 | work stoppage, computer failure or malfunction, or any and all 164 | other commercial damages or losses), even if such Contributor 165 | has been advised of the possibility of such damages. 166 | 167 | 9. Accepting Warranty or Additional Liability. While redistributing 168 | the Work or Derivative Works thereof, You may choose to offer, 169 | and charge a fee for, acceptance of support, warranty, indemnity, 170 | or other liability obligations and/or rights consistent with this 171 | License. However, in accepting such obligations, You may act only 172 | on Your own behalf and on Your sole responsibility, not on behalf 173 | of any other Contributor, and only if You agree to indemnify, 174 | defend, and hold each Contributor harmless for any liability 175 | incurred by, or claims asserted against, such Contributor by reason 176 | of your accepting any such warranty or additional liability. 177 | 178 | END OF TERMS AND CONDITIONS 179 | 180 | APPENDIX: How to apply the Apache License to your work. 181 | 182 | To apply the Apache License to your work, attach the following 183 | boilerplate notice, with the fields enclosed by brackets "[]" 184 | replaced with your own identifying information. (Don't include 185 | the brackets!) The text should be enclosed in the appropriate 186 | comment syntax for the file format. We also recommend that a 187 | file or class name and description of purpose be included on the 188 | same "printed page" as the copyright notice for easier 189 | identification within third-party archives. 190 | 191 | Copyright 2017, Visual Supply, Co. 192 | 193 | Licensed under the Apache License, Version 2.0 (the "License"); 194 | you may not use this file except in compliance with the License. 195 | You may obtain a copy of the License at 196 | 197 | http://www.apache.org/licenses/LICENSE-2.0 198 | 199 | Unless required by applicable law or agreed to in writing, software 200 | distributed under the License is distributed on an "AS IS" BASIS, 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | See the License for the specific language governing permissions and 203 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bazel Toolchains 2 | 3 | [![Build Status](https://travis-ci.org/vsco/bazel-toolchains.svg?branch=master)](https://travis-ci.org/vsco/bazel-toolchains) 4 | 5 | A collection of [Bazel](https://bazel.build) C++ build infrastructure based on [Chromium](https://chromium.org)'s 6 | [LLVM](https://llvm.org) toolchain. There are tags corresponding to Chromium releases. The build targets currently 7 | supported are Linux x64 and macOS. As in Chromium, the Linux toolchain has a sysroot, bundled copies of binutils, and a 8 | copy of libc++. The macOS build is less hermetic, and relies on system binutils and libraries. 9 | 10 | Use it in your Bazel WORKSPACE file like this: 11 | 12 | ``` 13 | git_repository( 14 | name = 'co_vsco_bazel_toolchains', 15 | remote = 'https://github.com/vsco/bazel-toolchains', 16 | tag = 'v64.0.3282.167', 17 | ) 18 | 19 | load("@co_vsco_bazel_toolchains//toolchains:repositories.bzl", "bazel_toolchains_repositories") 20 | bazel_toolchains_repositories() 21 | ``` 22 | 23 | Invoke Bazel with the custom toolchain: 24 | 25 | `bazel build --crosstool_top=@co_vsco_bazel_toolchains//tools/cpp:default-toolchain //your/build:target` 26 | 27 | ## Bazel Compatibility 28 | 29 | `vsco/bazel-toolchains` is tested against the following build matrix: 30 | 31 | | Bazel Version | OSX | Linux | 32 | | :-------------- | :-: | :---: | 33 | | 0.20.0+ | ✗ | ✗ | 34 | | 0.19.2 | ✓ | ✓ | 35 | | 0.18.1 | ✓ | ✓ | 36 | | 0.17.2 | ✓ | ✓ | 37 | | 0.16.1 | ✓ | ✓ | 38 | | 0.15.2 | ✓ | ✓ | 39 | | 0.14.1 | ✓ | ✓ | 40 | | 0.13.1 | ✓ | ✓ | 41 | | 0.12.0 | ✓ | ✓ | 42 | | ~0.11.x~ | ✗ | ✗ | 43 | | ~0.10.x~ | ✗ | ✗ | 44 | | ~0.9.x~ | ✗ | ✗ | 45 | 46 | Builds beyond the listed versions are not currently tested. 47 | 48 | Bazel `0.20.0+` introduced breaking changes to the [C++ Toolchain API](https://github.com/bazelbuild/bazel/issues/6434) 49 | which need to be addressed for consumers of this repo in a non-breaking manner. 50 | 51 | ## Prerequisites 52 | 53 | On macOS, run `xcode-select --install` in Terminal. 54 | 55 | ## Running the Python scripts 56 | 57 | The files in the `scripts/` directory are written in Python. Follow these 58 | [instructions](http://docs.python-guide.org/en/latest/starting/installation/) 59 | to install a version of Python that comes with the necessary tools for installation of third party libraries. On macOS, 60 | this means `brew install python`, and then following the instructions printed by `brew info python` (It's recommended to use `python@2` for macOS). 61 | 62 | Once that's working, type `pip install requests` to install the necessary dependencies. 63 | 64 | From the root of this repository, type `python scripts/generate_workspace.py --rev="64.0.3282.167"` where --rev is the 65 | Chromium tag you wish to pull from. The script will print status messages to `stderr` and write a file similar to 66 | toolchains/repositories.bzl to `stdout`. 67 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | # Chromium toolchain corresponding to Chromium 64.0.3282.167 2 | workspace(name = "co_vsco_bazel_toolchains") 3 | 4 | load("//toolchains:repositories.bzl", "bazel_toolchains_repositories") 5 | bazel_toolchains_repositories() 6 | 7 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 8 | 9 | # GTest 10 | http_archive( 11 | name = "gtest", 12 | url = "https://github.com/google/googletest/archive/release-1.8.0.zip", 13 | sha256 = "f3ed3b58511efd272eb074a3a6d6fb79d7c2e6a0e374323d1e6bcbcc1ef141bf", 14 | build_file = "//build_files:gtest.BUILD", 15 | strip_prefix = "googletest-release-1.8.0/googletest", 16 | ) 17 | -------------------------------------------------------------------------------- /build_files/BUILD: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "build_files", 3 | srcs = glob(["*.BUILD"]), 4 | visibility = ["//visibility:public"], 5 | ) 6 | -------------------------------------------------------------------------------- /build_files/gtest.BUILD: -------------------------------------------------------------------------------- 1 | cc_library( 2 | name = "main", 3 | srcs = glob( 4 | ["src/*.cc"], 5 | exclude = ["src/gtest-all.cc"] 6 | ), 7 | hdrs = glob([ 8 | "include/**/*.h", 9 | "src/*.h" 10 | ]), 11 | copts = [ 12 | '-Iexternal/gtest/include', 13 | '-Wno-unused-const-variable', 14 | ], 15 | linkopts = ["-v"], 16 | visibility = ["//visibility:public"], 17 | ) 18 | -------------------------------------------------------------------------------- /build_files/org_chromium_binutils_linux_x64.BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | filegroup( 4 | name = "ar", 5 | srcs = [ 6 | "bin/ar", 7 | ], 8 | ) 9 | 10 | filegroup( 11 | name = "as", 12 | srcs = [ 13 | "bin/as", 14 | ], 15 | ) 16 | 17 | filegroup( 18 | name = "ld", 19 | srcs = [ 20 | "bin/ld", 21 | ], 22 | ) 23 | 24 | filegroup( 25 | name = "ld.bfd", 26 | srcs = [ 27 | "bin/ld.bfd", 28 | ], 29 | ) 30 | 31 | filegroup( 32 | name = "ld.gold", 33 | srcs = [ 34 | "bin/ld.gold", 35 | ], 36 | ) 37 | 38 | filegroup( 39 | name = "nm", 40 | srcs = [ 41 | "bin/nm", 42 | ], 43 | ) 44 | 45 | filegroup( 46 | name = "objcopy", 47 | srcs = [ 48 | "bin/objcopy", 49 | ], 50 | ) 51 | 52 | filegroup( 53 | name = "objdump", 54 | srcs = [ 55 | "bin/objdump", 56 | ], 57 | ) 58 | 59 | filegroup( 60 | name = "ranlib", 61 | srcs = [ 62 | "bin/ranlib", 63 | ], 64 | ) 65 | 66 | filegroup( 67 | name = "readelf", 68 | srcs = [ 69 | "bin/readelf", 70 | ], 71 | ) 72 | 73 | filegroup( 74 | name = "strip", 75 | srcs = [ 76 | "bin/strip", 77 | ], 78 | ) 79 | 80 | filegroup( 81 | name = "binutils_components", 82 | srcs = [ 83 | ":ar", 84 | ":as", 85 | ":ld", 86 | ":ld.bfd", 87 | ":ld.gold", 88 | ":nm", 89 | ":objcopy", 90 | ":objdump", 91 | ":ranlib", 92 | ":readelf", 93 | ":strip", 94 | ], 95 | ) 96 | -------------------------------------------------------------------------------- /build_files/org_chromium_clang_linux_x64.BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | filegroup( 4 | name = "clang", 5 | srcs = [ 6 | "bin/clang", 7 | ], 8 | ) 9 | 10 | filegroup( 11 | name = "lib", 12 | srcs = glob(["lib/**"]), 13 | ) 14 | 15 | filegroup( 16 | name = "compiler_components", 17 | srcs = [ 18 | ":clang", 19 | ], 20 | ) 21 | -------------------------------------------------------------------------------- /build_files/org_chromium_clang_mac.BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | filegroup( 4 | name = "clang", 5 | srcs = [ 6 | "bin/clang", 7 | ], 8 | ) 9 | 10 | filegroup( 11 | name = "include", 12 | srcs = glob(["include/**"]), 13 | ) 14 | 15 | filegroup( 16 | name = "lib", 17 | srcs = glob(["lib/**"]), 18 | ) 19 | 20 | filegroup( 21 | name = "compiler_components", 22 | srcs = [ 23 | ":clang", 24 | ":include", 25 | ":lib", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /build_files/org_chromium_libcxx.BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | # Copyright 2017 The Chromium Authors. All rights reserved. 4 | # Use of this source code is governed by a BSD-style license that can be 5 | # found in the LICENSE file. 6 | # 7 | # Based on the BUILD.gn version in the Chromium tree. 8 | 9 | filegroup( 10 | name = "libcxx_includes", 11 | srcs = glob(["include/**/*"]) 12 | ) 13 | 14 | load("@co_vsco_bazel_toolchains//toolchains:libcxx_library.bzl", "libcxx_library") 15 | 16 | libcxx_copts = [ 17 | "-fPIC", 18 | "-fstrict-aliasing", 19 | "-nostdinc++", 20 | "-std=c++11", 21 | "-O2", 22 | "-g" 23 | ] 24 | 25 | libcxx_headers = glob(["src/support/runtime/*.ipp"]) + glob(["include/**/*"]) 26 | 27 | libcxx_defines = [ 28 | "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", 29 | "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS", 30 | "_LIBCPP_BUILDING_LIBRARY", 31 | "LIBCXX_BUILDING_LIBCXXABI" 32 | 33 | # This resets the visibility to default only for the various 34 | # flavors of operator new and operator delete. These symbols 35 | # are weak and get overriden by Chromium-provided ones, but if 36 | # these symbols had hidden visibility, this would make the 37 | # Chromium symbols hidden too because elf visibility rules 38 | # require that linkers use the least visible form when merging, 39 | # and if this is hidden, then when we merge it with tcmalloc's 40 | # operator new, hidden visibility would win. However, tcmalloc 41 | # needs a visible operator new to also override operator new 42 | # references from system libraries. 43 | # TODO(lld): Ask lld for a --force-public-visibility flag or 44 | # similar to that overrides the default elf merging rules, and 45 | # make tcmalloc's gn config pass that to all its dependencies, 46 | # then remove this override here. 47 | #"_LIBCPP_OVERRIDABLE_FUNC_VIS=__attribute__((__visibility__(\"\"default\"\"")))", 48 | ] 49 | 50 | libcxx_deps = [ 51 | "@co_vsco_bazel_toolchains//tools/cpp/tool_wrappers/linux_x64:tool-wrappers", 52 | "@org_chromium_sysroot_linux_x64//:sysroot", 53 | "@org_chromium_libcxx//:libcxx_includes", 54 | "@org_chromium_libcxxabi//:libcxxabi_includes", 55 | "@org_chromium_clang_linux_x64//:lib", 56 | ] 57 | 58 | libcxx_srcs = [ 59 | "src/algorithm.cpp", 60 | "src/any.cpp", 61 | "src/bind.cpp", 62 | "src/chrono.cpp", 63 | "src/condition_variable.cpp", 64 | "src/debug.cpp", 65 | "src/exception.cpp", 66 | "src/functional.cpp", 67 | "src/future.cpp", 68 | "src/hash.cpp", 69 | "src/ios.cpp", 70 | "src/iostream.cpp", 71 | "src/locale.cpp", 72 | "src/memory.cpp", 73 | "src/mutex.cpp", 74 | "src/new.cpp", 75 | "src/optional.cpp", 76 | "src/random.cpp", 77 | "src/regex.cpp", 78 | "src/shared_mutex.cpp", 79 | "src/stdexcept.cpp", 80 | "src/string.cpp", 81 | "src/strstream.cpp", 82 | "src/system_error.cpp", 83 | "src/thread.cpp", 84 | "src/typeinfo.cpp", 85 | "src/utility.cpp", 86 | "src/valarray.cpp", 87 | "src/variant.cpp", 88 | "src/vector.cpp", 89 | "src/include/atomic_support.h", 90 | "src/include/config_elast.h", 91 | "src/include/refstring.h", 92 | ] 93 | 94 | libcxx_library( 95 | name = "cxx-linux_x64", 96 | copts = libcxx_copts, 97 | hdrs = libcxx_headers, 98 | defines = libcxx_defines, 99 | srcs = libcxx_srcs, 100 | deps = libcxx_deps 101 | ) 102 | -------------------------------------------------------------------------------- /build_files/org_chromium_libcxxabi.BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | # Copyright 2017 The Chromium Authors. All rights reserved. 4 | # Use of this source code is governed by a BSD-style license that can be 5 | # found in the LICENSE file. 6 | # 7 | # Based on the BUILD.gn version in the Chromium tree. 8 | 9 | config_setting( 10 | name = "is_mac", 11 | values = {"cpu": "darwin"}, 12 | ) 13 | 14 | config_setting ( 15 | name = "is_arm", 16 | values = {"cpu": "armeabi-v7a"} 17 | ) 18 | 19 | filegroup( 20 | name = "libcxxabi_includes", 21 | srcs = glob(["include/**/*"]) 22 | ) 23 | 24 | cc_library( 25 | name = "include", 26 | includes = [":libcxxabi_includes"] 27 | ) 28 | 29 | load("@co_vsco_bazel_toolchains//toolchains:libcxx_library.bzl", "libcxx_library") 30 | 31 | libcxxabi_copts = [ 32 | "-O2", 33 | "-g" 34 | ] 35 | 36 | libcxxabi_defines = [ 37 | "LIBCXX_BUILDING_LIBCXXABI" 38 | ] 39 | 40 | libcxxabi_srcs = [ 41 | "src/include/refstring.h", 42 | "src/abort_message.h", 43 | "src/abort_message.cpp", 44 | "src/cxa_aux_runtime.cpp", 45 | "src/cxa_default_handlers.cpp", 46 | "src/cxa_demangle.cpp", 47 | "src/cxa_exception.hpp", 48 | "src/cxa_exception.cpp", 49 | "src/cxa_exception_storage.cpp", 50 | "src/cxa_guard.cpp", 51 | "src/cxa_handlers.hpp", 52 | "src/cxa_handlers.cpp", 53 | 54 | # This file is supposed to be used in fno-exception builds of 55 | # libc++abi. We build lib++/libc++abi with exceptions enabled. 56 | #"src/cxa_noexception.cpp", 57 | 58 | "src/cxa_personality.cpp", 59 | "src/cxa_unexpected.cpp", 60 | "src/cxa_vector.cpp", 61 | "src/cxa_virtual.cpp", 62 | "src/fallback_malloc.h", 63 | "src/fallback_malloc.cpp", 64 | "src/private_typeinfo.h", 65 | "src/private_typeinfo.cpp", 66 | "src/stdlib_exception.cpp", 67 | "src/stdlib_stdexcept.cpp", 68 | "src/stdlib_typeinfo.cpp", 69 | ] + select({ 70 | ":is_mac": [], 71 | "//conditions:default": [ "src/cxa_thread_atexit.cpp" ], 72 | }) 73 | 74 | libcxxabi_deps = [ 75 | "@org_chromium_libcxx//:libcxx_includes", 76 | "@co_vsco_bazel_toolchains//tools/cpp/tool_wrappers/linux_x64:tool-wrappers", 77 | "@org_chromium_sysroot_linux_x64//:sysroot", 78 | "@org_chromium_clang_linux_x64//:lib", 79 | ] 80 | 81 | libcxx_library( 82 | name = "cxxabi-linux_x64", 83 | copts = libcxxabi_copts, 84 | defines = libcxxabi_defines, 85 | hdrs = glob(["include/**/*"]), 86 | srcs = libcxxabi_srcs, 87 | deps = libcxxabi_deps, 88 | ) 89 | -------------------------------------------------------------------------------- /build_files/org_chromium_sysroot_linux_x64.BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | filegroup( 4 | name = "sysroot", 5 | srcs = glob(["*/**"]), 6 | ) 7 | -------------------------------------------------------------------------------- /scripts/chromium_repo.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import hashlib 3 | import functools 4 | import json 5 | import requests 6 | import sys 7 | import tempfile 8 | 9 | # Given a revision of Chromium like "61.0.3153.4", these files are needed: 10 | # 11 | # Clang version download: 12 | # https://chromium.googlesource.com/chromium/src/+/61.0.3153.4/tools/clang/scripts/update.py 13 | # Then, use the Clang version to produce a download url used to calculate a sha256. 14 | # 15 | # Sysroot version download: 16 | # https://chromium.googlesource.com/chromium/src/+/61.0.3153.4/build/linux/sysroot_scripts/sysroots.json 17 | # Then, use the sysroot version found in the JSON to produce a download url used to calculate a sha256. 18 | # 19 | # libcxx download. 20 | # Buildtools revision: 21 | # https://chromium.googlesource.com/chromium/src/+/61.0.3153.4/DEPS 22 | # Then, use the buildtools revision to download something like this: 23 | # https://chromium.googlesource.com/chromium/buildtools/+/5ad14542a6a74dd914f067b948c5d3e8d170396b/DEPS 24 | # Then, return the revisions for libcxx etc. found in that file. 25 | # 26 | # Binutils version download: 27 | # https://chromium.googlesource.com/chromium/src/+/61.0.3153.4/third_party/binutils/Linux_x64/binutils.tar.bz2.sha1 28 | 29 | SRC_REPO = "https://chromium.googlesource.com/chromium/src/+" 30 | TOOLS_REPO = "https://chromium.googlesource.com/chromium/buildtools/+" 31 | DATA_STORE = "https://commondatastorage.googleapis.com" 32 | 33 | def download(url, stream=False): 34 | print >> sys.stderr, "Downloading %s" % url 35 | response = requests.get(url, stream=stream) 36 | if response.status_code != 200: 37 | raise Exception("Unexpected status code %d" % response.status_code) 38 | return response 39 | 40 | def base64_dl(url): 41 | # Appending '?format=TEXT' downloads a base64 version of the raw file, instead of the HTML view. 42 | return base64.b64decode(download(url + "?format=TEXT").text) 43 | 44 | def progressbar_download(url, f): 45 | with open(f, "wb") as f: 46 | response = download(url, stream=True) 47 | total_length = response.headers.get('content-length') 48 | if total_length is None: # no content length header 49 | f.write(response.content) 50 | else: 51 | dl = 0 52 | total_length = int(total_length) 53 | for data in response.iter_content(chunk_size=4096): 54 | dl += len(data) 55 | f.write(data) 56 | done = int(50 * dl / total_length) 57 | sys.stderr.write("\r[%s%s]" % ('=' * done, ' ' * (50-done)) ) 58 | sys.stderr.flush() 59 | sys.stderr.write("\n") 60 | 61 | def download_clang_rev(revision): 62 | clang_script = base64_dl("%s/%s/tools/clang/scripts/update.py" % (SRC_REPO, revision)) 63 | exec(clang_script) 64 | return "%s-%s" % (CLANG_REVISION, CLANG_SUB_REVISION) 65 | 66 | def calc_sha256(url): 67 | with tempfile.NamedTemporaryFile() as f: 68 | progressbar_download(url, f.name) 69 | digest = hashlib.sha256() 70 | [digest.update(chunk) for chunk in iter(functools.partial(f.read, 65336), '')] 71 | return digest.hexdigest() 72 | 73 | def clang_url(platform, clang_rev): 74 | return ("%(data_store)s/chromium-browser-clang/%(platform)s/clang-%(rev)s.tgz" % 75 | {"platform": platform, "data_store": DATA_STORE, "rev": clang_rev}) 76 | 77 | def download_clang_info(revision): 78 | clang_rev = download_clang_rev(revision) 79 | return [{ 80 | "platform": p, 81 | "url": clang_url(p, clang_rev), 82 | "sha256": calc_sha256(clang_url(p, clang_rev)) 83 | } for p in ["Mac", "Linux_x64"]] 84 | 85 | def sysroot_url(sysroot): 86 | return ("%s/chrome-linux-sysroot/toolchain/%s/%s" % (DATA_STORE, sysroot["Revision"], sysroot["Tarball"])).encode('ascii', 'ignore') 87 | 88 | # Only need a sysroot for amd64 at the moment 89 | def download_sysroot_info(revision): 90 | sysroot_json = base64_dl("%s/%s/build/linux/sysroot_scripts/sysroots.json" % (SRC_REPO, revision)) 91 | sysroots = json.loads(sysroot_json) 92 | amd64 = sysroots["stretch_amd64"] 93 | amd64["platform"] = "Linux_x64" 94 | return [{ 95 | "platform": p["platform"], 96 | "url": sysroot_url(p), 97 | "sha256": calc_sha256(sysroot_url(p)) 98 | } for p in [amd64]] 99 | 100 | def binutils_url(sha): 101 | return "%s/chromium-binutils/%s" % (DATA_STORE, sha) 102 | 103 | def download_binutils_info(revision): 104 | binutils_platforms = [ 105 | (p, base64_dl("%s/%s/third_party/binutils/%s/binutils.tar.bz2.sha1" % (SRC_REPO, revision, p))) 106 | for p in ["Linux_x64"]] 107 | return [{ 108 | "type": "tar.bz2", 109 | "platform": bp[0], 110 | "url": binutils_url(bp[1]), 111 | "sha256": calc_sha256(binutils_url(bp[1])), 112 | } for bp in binutils_platforms] 113 | 114 | def download_toolchain_info(revision): 115 | # DEPS files call a function named "Var" that doesn't have to be correct 116 | # for this purpose, but must return a string. This shim works. 117 | def Var(s): 118 | return s 119 | deps = base64_dl("%s/%s/DEPS" % (SRC_REPO, revision)) 120 | exec(deps) 121 | tool_deps = base64_dl("%s/%s/DEPS" % (TOOLS_REPO, vars['buildtools_revision'])) 122 | exec(tool_deps) 123 | return [{'name': name, 'rev': vars[name + "_revision"]} for name in ["libcxx", "libcxxabi"]] 124 | -------------------------------------------------------------------------------- /scripts/generate_workspace.py: -------------------------------------------------------------------------------- 1 | # Prints a Bazel WORKSPACE file to stdout. 2 | # Download status updates are printed to stderr. 3 | 4 | import argparse 5 | import chromium_repo 6 | import os 7 | 8 | class Repository: 9 | def __init__(self, name, repo_type, **kwargs): 10 | self.name = name 11 | self.repo_type = repo_type 12 | self.args = dict((k,v) for k, v in kwargs.iteritems() if v is not None) 13 | 14 | def print_invocation(self): 15 | print " " + self.name + "()" 16 | 17 | def print_def(self): 18 | print """ 19 | def %(name)s(): 20 | %(repo_type)s( 21 | name = '%(name)s', 22 | build_file = str(Label('//build_files:%(name)s.BUILD')),""" % {'name': self.name, 'repo_type': self.repo_type} 23 | 24 | for key, value in self.args.iteritems(): 25 | print \ 26 | " %(key)s = %(value)s," % {'key': key, 'value': value} 27 | print \ 28 | " )" 29 | 30 | def get_archive_type(repo): 31 | archive_type = repo.get('type', None) 32 | if archive_type is None: 33 | return None 34 | 35 | return "'" + archive_type + "'" 36 | 37 | def get_http_archives(revision, prefix, fetch_func): 38 | return [Repository( 39 | name = prefix + repo['platform'].lower(), 40 | repo_type = 'http_archive', 41 | urls = [repo['url']], 42 | sha256 = "'" + repo['sha256'] + "'", 43 | type = get_archive_type(repo), 44 | ) for repo in fetch_func(revision)] 45 | 46 | def get_git_repositories(revision, fetch_func): 47 | return [Repository( 48 | name = 'org_chromium_' + repo['name'], 49 | repo_type = 'new_git_repository', 50 | remote = "'" + 'https://chromium.googlesource.com/chromium/llvm-project/' + repo['name'] + "'", 51 | commit = "'" + repo['rev'] + "'" 52 | ) for repo in fetch_func(revision)] 53 | 54 | def print_workspace(revision): 55 | repos = (get_http_archives(revision, 'org_chromium_clang_', chromium_repo.download_clang_info) + 56 | get_http_archives(revision, 'org_chromium_sysroot_', chromium_repo.download_sysroot_info) + 57 | get_http_archives(revision, 'org_chromium_binutils_', chromium_repo.download_binutils_info) + 58 | get_git_repositories(revision, chromium_repo.download_toolchain_info)) 59 | 60 | base_dir = os.path.dirname(os.path.abspath(__file__)) 61 | with open(os.path.join(base_dir, 'license_block.txt')) as f: 62 | print f.read() 63 | print '# Defines external repositories needed by bazel-toolchains.' 64 | print '# Chromium toolchain corresponds to Chromium %s.\n' % revision 65 | print 'load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")' 66 | print 'load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")\n' 67 | print 'def bazel_toolchains_repositories():' 68 | for repo in repos: 69 | repo.print_invocation() 70 | for repo in repos: 71 | repo.print_def() 72 | print '' 73 | 74 | if __name__ == '__main__': 75 | parser = argparse.ArgumentParser() 76 | parser.add_argument("-r", "--rev", action="store", required=True) 77 | args = parser.parse_args() 78 | print_workspace(args.rev) 79 | -------------------------------------------------------------------------------- /scripts/install_bazel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # This script installs Bazel for Debian or MacOS for usage in the Travis CI environment. 4 | # 5 | # Required config: 6 | # - CI 7 | # - TRAVIS 8 | # - TRAVIS_OS_NAME 9 | # - BAZEL_VERSION: Bazel version to install 10 | # 11 | # Optional configs: 12 | # - BAZEL_INSTALL: Location to fetch the installers to, default: ${HOME}/bazel/install 13 | # 14 | set -e 15 | 16 | if [ -z "$CI" ] || [ -z "$TRAVIS" ]; then 17 | echo "error: this is intended to be run under travis-ci, exiting..." 18 | exit 1; 19 | fi 20 | 21 | if [ -z "$BAZEL_VERSION" ]; then 22 | echo "error: BAZEL_VERSION required, exiting..." 23 | exit 1; 24 | fi 25 | 26 | if [ -z "$BAZEL_INSTALL" ]; then 27 | BAZEL_INSTALL="${HOME}/bazel/install" 28 | fi 29 | 30 | mkdir -p $BAZEL_INSTALL 31 | pushd $BAZEL_INSTALL 32 | 33 | if [ "$TRAVIS_OS_NAME" == "linux" ]; then 34 | echo "Installing Bazel ${BAZEL_VERSION} for Linux" 35 | DEBIAN_INSTALL_SCRIPT="bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh" 36 | wget --no-clobber "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/${DEBIAN_INSTALL_SCRIPT}" 37 | chmod +x ${DEBIAN_INSTALL_SCRIPT} 38 | ./${DEBIAN_INSTALL_SCRIPT} --user 39 | elif [ "$TRAVIS_OS_NAME" == "osx" ]; then 40 | echo "Installing Bazel ${BAZEL_VERSION} for Darwin" 41 | DARWIN_INSTALL_SCRIPT=bazel-${BAZEL_VERSION}-installer-darwin-x86_64.sh 42 | curl -sLO "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/${DARWIN_INSTALL_SCRIPT}" 43 | chmod +x ${DARWIN_INSTALL_SCRIPT} 44 | ./${DARWIN_INSTALL_SCRIPT} --user 45 | else 46 | echo "error: unsupported TRAVIS_OS_NAME: ${TRAVIS_OS_NAME}, exiting" 47 | exit 1; 48 | fi 49 | 50 | popd 51 | -------------------------------------------------------------------------------- /scripts/license_block.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # Copyright 2017 VSCO. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | -------------------------------------------------------------------------------- /src/BUILD: -------------------------------------------------------------------------------- 1 | config_setting( 2 | name = 'darwin_mode', 3 | values = {'cpu': 'darwin'}, 4 | ) 5 | 6 | cc_test( 7 | name = 'test', 8 | srcs = glob(['*_test.cpp']), 9 | copts = ['-Iexternal/gtest/include'], 10 | deps = [ 11 | '@gtest//:main', 12 | ] + select({ 13 | ':darwin_mode': [], 14 | '//conditions:default': [ 15 | ], 16 | }), 17 | ) -------------------------------------------------------------------------------- /src/allocation_test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include 3 | 4 | namespace vsco { 5 | 6 | TEST(Allocation, NewDelete) { 7 | std::string *foo = new std::string("abcd"); 8 | foo->pop_back(); 9 | EXPECT_STREQ("abc", foo->c_str()); 10 | delete foo; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/string_test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include 3 | 4 | namespace vsco { 5 | 6 | TEST(String, PopBack) { 7 | std::string foo = "abcd"; 8 | foo.pop_back(); 9 | EXPECT_EQ("abc", foo); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/version_test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | 3 | namespace vsco { 4 | 5 | TEST(CompilerMeta, AppleBuild) { 6 | #if defined(__apple_build_version__) 7 | // __apple_build_version__ shouldn't be defined in the Chromium toolchain 8 | ASSERT_TRUE(false); 9 | #else 10 | ASSERT_GE(__clang_major__, 6); 11 | #endif 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /toolchains/BUILD: -------------------------------------------------------------------------------- 1 | filegroup( 2 | name = "repositories", 3 | srcs = ["repositories.bzl"], 4 | visibility = ["//visibility:public"], 5 | ) 6 | -------------------------------------------------------------------------------- /toolchains/libcxx_library.bzl: -------------------------------------------------------------------------------- 1 | # Mimics cc_library, but doesn't need the toolchain (which would be a circular dependency) 2 | 3 | def _needs_pic(): 4 | return True 5 | 6 | def _dir(s): 7 | return "/".join(s.split("/")[:-1]) 8 | 9 | def _obj_directory(ctx): 10 | return "/".join([ctx.bin_dir.path, _dir(ctx.build_file_path), "_objs"]) 11 | 12 | def _compilation_output(ctx, src, suffix): 13 | return "/".join([_obj_directory(ctx), ctx.label.name, src.path.rstrip(".cpp") + suffix]) 14 | 15 | def _dep_file(ctx, src): 16 | suffix = ".pic.d" if _needs_pic() else ".d" 17 | return _compilation_output(ctx, src, suffix) 18 | 19 | def _obj_file(ctx, src): 20 | suffix = ".pic.o" if _needs_pic() else ".o" 21 | return _compilation_output(ctx, src, suffix) 22 | 23 | def _impl_libcxx_library(ctx): 24 | dep_files = depset() 25 | for dep in ctx.attr.deps: 26 | dep_files += dep.files 27 | 28 | deps_list = dep_files.to_list() 29 | srcs_list = depset(ctx.files.srcs).to_list() 30 | hdrs_list = depset(ctx.files.hdrs).to_list() 31 | cpp_options = [ 32 | "--sysroot=external/org_chromium_sysroot_linux_x64", "-nostdinc++", 33 | "-isystem", "external/org_chromium_libcxxabi/include", 34 | "-isystem", "external/org_chromium_libcxx/include", 35 | "-isystem", "external/org_chromium_clang_linux_x64/lib/clang/6.0.0/include", 36 | "-isystem", "external/org_chromium_sysroot_linux_x64/usr/include/x86_64-linux-gnu", 37 | "-isystem", "external/org_chromium_sysroot_linux_x64/usr/include", 38 | "-U_FORTIFY_SOURCE", "-fstack-protector", "-fPIE", "-fdiagnostics-color=always", "-Wall", 39 | "-Wunused-parameter", "-Wno-sequence-point", "-fno-omit-frame-pointer" 40 | ] 41 | cxx_options = ["-std=c++1y"] 42 | unfiltered = [ 43 | "-no-canonical-prefixes", "-Wno-builtin-macro-redefined", 44 | "-D__DATE__=\"redacted\"", "-D__TIMESTAMP__=\"redacted\"", 45 | "-D__TIME__=\"redacted\"" 46 | ] 47 | 48 | obj_deps = [] 49 | obj_files = [] 50 | for src in srcs_list: 51 | if not src.path.endswith("cpp"): 52 | continue 53 | 54 | obj_dep = ctx.actions.declare_file(_dep_file(ctx, src)) 55 | obj_deps.append(obj_dep) 56 | 57 | obj_file = ctx.actions.declare_file(_obj_file(ctx, src)) 58 | obj_files.append(obj_file) 59 | 60 | ctx.actions.run( 61 | outputs = [ obj_file, obj_dep ], 62 | inputs = srcs_list + hdrs_list + deps_list, 63 | arguments = cpp_options + cxx_options + ctx.attr.copts + 64 | [ 65 | "-MD", "-MF", obj_dep.path, 66 | "-frandom-seed=%s" % obj_file.path, 67 | "-fPIC" if _needs_pic() else "", 68 | ] + [ 69 | "-D" + attr for attr in ctx.attr.defines 70 | ] + unfiltered + [ 71 | "-c", src.path, "-o", obj_file.path 72 | ], 73 | executable = "external/co_vsco_bazel_toolchains/tools/cpp/tool_wrappers/linux_x64/chromium_clang", 74 | env = {"PWD": "/proc/self/cwd"}, 75 | ) 76 | 77 | ctx.actions.run( 78 | outputs = [ ctx.outputs.out ], 79 | inputs = obj_files + deps_list, 80 | arguments = ["rcsD", ctx.outputs.out.path] + [obj.path for obj in obj_files], 81 | executable = "external/co_vsco_bazel_toolchains/tools/cpp/tool_wrappers/linux_x64/chromium_ar", 82 | env = {"PWD": "/proc/self/cwd"}, 83 | ) 84 | 85 | libcxx_library = rule( 86 | _impl_libcxx_library, 87 | attrs = { 88 | "copts": attr.string_list(), 89 | "hdrs": attr.label_list(allow_files = True), 90 | "defines": attr.string_list(), 91 | "srcs": attr.label_list(allow_files = True), 92 | "deps": attr.label_list(), 93 | }, 94 | outputs = { 95 | "out": "lib%{name}.a", 96 | }, 97 | ) 98 | -------------------------------------------------------------------------------- /toolchains/repositories.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # Copyright 2017 VSCO. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Defines external repositories needed by bazel-toolchains. 17 | # Chromium toolchain corresponds to Chromium 65.0.3325.69. 18 | 19 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 20 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository") 21 | 22 | def bazel_toolchains_repositories(): 23 | org_chromium_clang_mac() 24 | org_chromium_clang_linux_x64() 25 | org_chromium_sysroot_linux_x64() 26 | org_chromium_binutils_linux_x64() 27 | org_chromium_libcxx() 28 | org_chromium_libcxxabi() 29 | 30 | def org_chromium_clang_mac(): 31 | http_archive( 32 | name = 'org_chromium_clang_mac', 33 | build_file = str(Label('//build_files:org_chromium_clang_mac.BUILD')), 34 | sha256 = '4b2a7a65ac1ee892b318c723eec8771f514bb306f346aa8216bb0006f19d87b7', 35 | urls = ['https://commondatastorage.googleapis.com/chromium-browser-clang/Mac/clang-321529-2.tgz'], 36 | ) 37 | 38 | def org_chromium_clang_linux_x64(): 39 | http_archive( 40 | name = 'org_chromium_clang_linux_x64', 41 | build_file = str(Label('//build_files:org_chromium_clang_linux_x64.BUILD')), 42 | sha256 = '76d4eb1ad011e3127c4a9de9b9f5d4ac624b5a9395c4d7395c9e0a487b13daf6', 43 | urls = ['https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-321529-2.tgz'], 44 | ) 45 | 46 | def org_chromium_sysroot_linux_x64(): 47 | http_archive( 48 | name = 'org_chromium_sysroot_linux_x64', 49 | build_file = str(Label('//build_files:org_chromium_sysroot_linux_x64.BUILD')), 50 | sha256 = '84656a6df544ecef62169cfe3ab6e41bb4346a62d3ba2a045dc5a0a2ecea94a3', 51 | urls = ['https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/2202c161310ffde63729f29d27fe7bb24a0bc540/debian_stretch_amd64_sysroot.tar.xz'], 52 | ) 53 | 54 | def org_chromium_binutils_linux_x64(): 55 | http_archive( 56 | name = 'org_chromium_binutils_linux_x64', 57 | build_file = str(Label('//build_files:org_chromium_binutils_linux_x64.BUILD')), 58 | sha256 = 'd3e03aa37dd59d6b3b0df4654b964ef5361d913d50c1e2724a6f1335762fcda6', 59 | type = 'tar.bz2', 60 | urls = ['https://commondatastorage.googleapis.com/chromium-binutils/5230f6066998df2f4d61d5fa586152ab20cca300'], 61 | ) 62 | 63 | def org_chromium_libcxx(): 64 | new_git_repository( 65 | name = 'org_chromium_libcxx', 66 | build_file = str(Label('//build_files:org_chromium_libcxx.BUILD')), 67 | commit = 'f56f1bba1ade4a408d403ff050d50e837bae47df', 68 | remote = 'https://chromium.googlesource.com/chromium/llvm-project/libcxx', 69 | ) 70 | 71 | def org_chromium_libcxxabi(): 72 | new_git_repository( 73 | name = 'org_chromium_libcxxabi', 74 | build_file = str(Label('//build_files:org_chromium_libcxxabi.BUILD')), 75 | commit = '05ba3281482304ae8de31123a594972a495da06d', 76 | remote = 'https://chromium.googlesource.com/chromium/llvm-project/libcxxabi', 77 | ) 78 | -------------------------------------------------------------------------------- /tools/cpp/BUILD: -------------------------------------------------------------------------------- 1 | cc_toolchain_suite( 2 | name = "default-toolchain", 3 | toolchains = { 4 | "darwin|compiler": "cc_toolchain_apple", 5 | "k8|clang": "cc_toolchain_linux", 6 | }, 7 | visibility = ["//visibility:public"], 8 | ) 9 | 10 | cc_toolchain( 11 | name = "cc_toolchain_linux", 12 | all_files = ":linux_toolchain_deps", 13 | compiler_files = ":linux_toolchain_deps", 14 | cpu = "k8", 15 | dwp_files = ":linux_toolchain_deps", 16 | dynamic_runtime_libs = [":empty"], 17 | linker_files = ":linux_toolchain_deps", 18 | objcopy_files = ":linux_toolchain_deps", 19 | static_runtime_libs = [":empty"], 20 | strip_files = ":linux_toolchain_deps", 21 | supports_param_files = 0, 22 | visibility = ["//visibility:public"], 23 | ) 24 | 25 | cc_toolchain( 26 | name = "cc_toolchain_apple", 27 | all_files = ":apple_toolchain_deps", 28 | compiler_files = ":apple_toolchain_deps", 29 | cpu = "darwin", 30 | dwp_files = ":apple_toolchain_deps", 31 | dynamic_runtime_libs = [":empty"], 32 | linker_files = ":apple_toolchain_deps", 33 | objcopy_files = ":apple_toolchain_deps", 34 | static_runtime_libs = [":empty"], 35 | strip_files = ":apple_toolchain_deps", 36 | supports_param_files = 0, 37 | visibility = ["//visibility:public"], 38 | ) 39 | 40 | filegroup( 41 | name = "empty", 42 | srcs = [], 43 | visibility = ["//visibility:private"], 44 | ) 45 | 46 | filegroup( 47 | name = "apple_toolchain_deps", 48 | srcs = [ 49 | "//tools/cpp/tool_wrappers/mac:clang", 50 | "@org_chromium_clang_mac//:compiler_components", 51 | ], 52 | visibility = ["//visibility:private"], 53 | ) 54 | 55 | filegroup( 56 | name = "linux_toolchain_deps", 57 | srcs = [ 58 | "//tools/cpp/tool_wrappers/linux_x64:tool-wrappers", 59 | "@org_chromium_binutils_linux_x64//:binutils_components", 60 | "@org_chromium_clang_linux_x64//:compiler_components", 61 | "@org_chromium_sysroot_linux_x64//:sysroot", 62 | "@org_chromium_libcxx//:cxx-linux_x64", 63 | "@org_chromium_libcxxabi//:cxxabi-linux_x64", 64 | "@org_chromium_clang_linux_x64//:lib", 65 | "@org_chromium_libcxx//:libcxx_includes", 66 | "@org_chromium_libcxxabi//:libcxxabi_includes", 67 | ], 68 | visibility = ["//visibility:public"], 69 | ) 70 | 71 | config_setting( 72 | name = "debug", 73 | values = {"compilation_mode": "dbg"}, 74 | ) 75 | 76 | config_setting( 77 | name = "linux", 78 | values = {"cpu": "k8"}, 79 | ) 80 | 81 | config_setting( 82 | name = "apple", 83 | values = {"cpu": "darwin"}, 84 | ) 85 | 86 | config_setting( 87 | name = "clang-linux", 88 | values = { 89 | "compiler": "clang", 90 | "cpu": "k8", 91 | }, 92 | ) 93 | 94 | config_setting( 95 | name = "apple_debug", 96 | values = { 97 | "compilation_mode": "dbg", 98 | "cpu": "darwin", 99 | }, 100 | ) 101 | -------------------------------------------------------------------------------- /tools/cpp/CROSSTOOL: -------------------------------------------------------------------------------- 1 | major_version: "local" 2 | minor_version: "" 3 | default_target_cpu: "same_as_host" 4 | 5 | default_toolchain { 6 | cpu: "darwin" 7 | toolchain_identifier: "osx" 8 | } 9 | 10 | # We use Clang on Ubuntu. 11 | default_toolchain { 12 | cpu: "k8" 13 | toolchain_identifier: "clang-chromium-linux" 14 | } 15 | 16 | # Chromium's Clang on Linux 17 | toolchain { 18 | toolchain_identifier: "clang-chromium-linux" 19 | abi_libc_version: "local" 20 | abi_version: "local" 21 | builtin_sysroot: "" 22 | compiler: "clang" 23 | 24 | # Include paths 25 | compiler_flag: "--sysroot=external/org_chromium_sysroot_linux_x64" 26 | compiler_flag: "-nostdinc++" 27 | compiler_flag: "-isystem" 28 | compiler_flag: "external/org_chromium_libcxxabi/include" 29 | compiler_flag: "-isystem" 30 | compiler_flag: "external/org_chromium_libcxx/include" 31 | compiler_flag: "-isystem" 32 | compiler_flag: "external/org_chromium_clang_linux_x64/lib/clang/6.0.0/include" 33 | compiler_flag: "-isystem" 34 | compiler_flag: "external/org_chromium_sysroot_linux_x64/usr/include/x86_64-linux-gnu" 35 | compiler_flag: "-isystem" 36 | compiler_flag: "external/org_chromium_sysroot_linux_x64/usr/include" 37 | 38 | cxx_builtin_include_directory: "%package(@org_chromium_clang_linux_x64//lib/clang/6.0.0/include)%" 39 | cxx_builtin_include_directory: "%package(@org_chromium_sysroot_linux_x64//usr/include/x86_64-linux-gnu)%" 40 | cxx_builtin_include_directory: "%package(@org_chromium_sysroot_linux_x64//usr/include)%" 41 | 42 | cxx_flag: "-std=c++1y" 43 | host_system_name: "local" 44 | linker_flag: "-latomic" 45 | linker_flag: "-lm" 46 | linker_flag: "-lpthread" 47 | linker_flag: "--sysroot=external/org_chromium_sysroot_linux_x64" 48 | linker_flag: "-Lbazel-out/host/bin/external/org_chromium_libcxx/" 49 | linker_flag: "-lcxx-linux_x64" 50 | linker_flag: "-Lbazel-out/host/bin/external/org_chromium_libcxxabi" 51 | linker_flag: "-lcxxabi-linux_x64" 52 | 53 | needsPic: true 54 | objcopy_embed_flag: "-I" 55 | objcopy_embed_flag: "binary" 56 | supports_fission: false 57 | supports_gold_linker: false 58 | supports_incremental_linker: false 59 | supports_interface_shared_objects: false 60 | supports_normalizing_ar: false 61 | supports_start_end_lib: false 62 | target_cpu: "k8" 63 | target_libc: "local" 64 | target_system_name: "local" 65 | 66 | # Chromium toolchain, no gcov 67 | tool_path {name: "gcc" path: "tool_wrappers/linux_x64/chromium_clang" } 68 | tool_path {name: "ld" path: "tool_wrappers/linux_x64/chromium_ld" } 69 | tool_path {name: "ar" path: "tool_wrappers/linux_x64/chromium_ar" } 70 | tool_path {name: "cpp" path: "tool_wrappers/linux_x64/chromium_clang" } 71 | tool_path {name: "nm" path: "tool_wrappers/linux_x64/chromium_nm" } 72 | tool_path {name: "objcopy" path: "tool_wrappers/linux_x64/chromium_objcopy" } 73 | tool_path {name: "objdump" path: "tool_wrappers/linux_x64/chromium_objdump" } 74 | tool_path {name: "strip" path: "tool_wrappers/linux_x64/chromium_strip" } 75 | tool_path {name: "gcov" path: "/bin/false" } 76 | 77 | # Anticipated future default. 78 | # This makes GCC and Clang do what we want when called through symlinks. 79 | unfiltered_cxx_flag: "-no-canonical-prefixes" 80 | linker_flag: "-no-canonical-prefixes" 81 | 82 | # Make C++ compilation deterministic. Use linkstamping instead of these 83 | # compiler symbols. 84 | unfiltered_cxx_flag: "-Wno-builtin-macro-redefined" 85 | unfiltered_cxx_flag: "-D__DATE__=\"redacted\"" 86 | unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\"" 87 | unfiltered_cxx_flag: "-D__TIME__=\"redacted\"" 88 | 89 | # Security hardening on by default. 90 | # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases. 91 | # We need to undef it before redefining it as some distributions now have 92 | # it enabled by default. 93 | compiler_flag: "-U_FORTIFY_SOURCE" 94 | compiler_flag: "-fstack-protector" 95 | compiler_flag: "-fPIE" 96 | linker_flag: "-pie" 97 | linker_flag: "-Wl,-z,relro,-z,now" 98 | 99 | # Enable coloring even if there's no attached terminal. Bazel removes the 100 | # escape sequences if --nocolor is specified. 101 | compiler_flag: "-fdiagnostics-color=always" 102 | 103 | # All warnings are enabled. Maybe enable -Werror as well? 104 | compiler_flag: "-Wall" 105 | # Enable a few more warnings that aren't part of -Wall. 106 | compiler_flag: "-Wunused-parameter" 107 | # But disable some that are problematic. 108 | compiler_flag: "-Wno-sequence-point" # has false positives 109 | 110 | # Uncomment for debugging. 111 | # compiler_flag: "-v" 112 | # linker_flag: "-v" 113 | 114 | # Keep stack frames for debugging, even in opt mode. 115 | compiler_flag: "-fno-omit-frame-pointer" 116 | 117 | # Stamp the binary with a unique identifier. 118 | linker_flag: "-Wl,--build-id=md5" 119 | linker_flag: "-Wl,--hash-style=gnu" 120 | 121 | # Stamp the binary with a unique identifier. 122 | linker_flag: "-Wl,--build-id=md5" 123 | linker_flag: "-Wl,--hash-style=gnu" 124 | 125 | compilation_mode_flags { 126 | mode: DBG 127 | # Enable debug symbols. 128 | compiler_flag: "-g" 129 | } 130 | compilation_mode_flags { 131 | mode: OPT 132 | 133 | # No debug symbols. 134 | # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or 135 | # even generally? However, that can't happen here, as it requires special 136 | # handling in Bazel. 137 | compiler_flag: "-g0" 138 | 139 | # Conservative choice for -O 140 | # -O3 can increase binary size and even slow down the resulting binaries. 141 | # Profile first and / or use FDO if you need better performance than this. 142 | compiler_flag: "-O2" 143 | 144 | # Disable assertions 145 | compiler_flag: "-DNDEBUG" 146 | 147 | # Removal of unused code and data at link time (can this increase binary size in some cases?). 148 | compiler_flag: "-ffunction-sections" 149 | compiler_flag: "-fdata-sections" 150 | linker_flag: "-Wl,--gc-sections" 151 | } 152 | } 153 | 154 | 155 | # Chromium Clang on OS X 156 | toolchain { 157 | toolchain_identifier: "osx" 158 | abi_version: "local" 159 | abi_libc_version: "local" 160 | builtin_sysroot: "" 161 | compiler: "compiler" 162 | host_system_name: "local" 163 | needsPic: true 164 | target_libc: "macosx" 165 | target_cpu: "darwin" 166 | target_system_name: "local" 167 | 168 | 169 | # Uncomment for debugging. 170 | # compiler_flag: "-v" 171 | 172 | cxx_flag: "-std=c++1y" 173 | linker_flag: "-undefined" 174 | linker_flag: "dynamic_lookup" 175 | linker_flag: "-headerpad_max_install_names" 176 | ar_flag: "-static" 177 | ar_flag: "-s" 178 | ar_flag: "-o" 179 | compiler_flag: "-nostdinc++" 180 | compiler_flag: "-isystem" 181 | compiler_flag: "external/org_chromium_clang_mac/include/c++/v1" 182 | compiler_flag: "-isystem" 183 | compiler_flag: "external/org_chromium_clang_mac/lib/clang/6.0.0/include" 184 | compiler_flag: "-isystem" 185 | compiler_flag: "/usr/include" 186 | compiler_flag: "-isystem" 187 | compiler_flag: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include" 188 | cxx_builtin_include_directory: "/usr/include" 189 | cxx_builtin_include_directory: "/System/Library/Frameworks" 190 | cxx_builtin_include_directory: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include" 191 | objcopy_embed_flag: "-I" 192 | objcopy_embed_flag: "binary" 193 | 194 | # Anticipated future default. 195 | unfiltered_cxx_flag: "-no-canonical-prefixes" 196 | 197 | # Make C++ compilation deterministic. Use linkstamping instead of these 198 | # compiler symbols. 199 | unfiltered_cxx_flag: "-Wno-builtin-macro-redefined" 200 | unfiltered_cxx_flag: "-D__DATE__=\"redacted\"" 201 | unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\"" 202 | unfiltered_cxx_flag: "-D__TIME__=\"redacted\"" 203 | 204 | # Security hardening on by default. 205 | # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases. 206 | compiler_flag: "-D_FORTIFY_SOURCE=1" 207 | compiler_flag: "-fstack-protector" 208 | 209 | # Enable coloring even if there's no attached terminal. Bazel removes the 210 | # escape sequences if --nocolor is specified. 211 | compiler_flag: "-fcolor-diagnostics" 212 | 213 | # All warnings are enabled. Maybe enable -Werror as well? 214 | compiler_flag: "-Wall" 215 | # Enable a few more warnings that aren't part of -Wall. 216 | compiler_flag: "-Wthread-safety" 217 | compiler_flag: "-Wself-assign" 218 | 219 | # Keep stack frames for debugging, even in opt mode. 220 | compiler_flag: "-fno-omit-frame-pointer" 221 | 222 | # Anticipated future default. 223 | linker_flag: "-no-canonical-prefixes" 224 | 225 | tool_path {name: "ld" path: "/usr/bin/ld" } 226 | tool_path {name: "cpp" path: "/usr/bin/cpp" } 227 | tool_path {name: "dwp" path: "/usr/bin/dwp" } 228 | tool_path {name: "gcov" path: "/usr/bin/gcov" } 229 | tool_path {name: "nm" path: "/usr/bin/nm" } 230 | tool_path {name: "objcopy" path: "/usr/bin/objcopy" } 231 | tool_path {name: "objdump" path: "/usr/bin/objdump" } 232 | tool_path {name: "strip" path: "/usr/bin/strip" } 233 | tool_path {name: "gcc" path: "tool_wrappers/mac/osx_clang_wrapper.sh" } 234 | tool_path {name: "ar" path: "/usr/bin/libtool" } 235 | 236 | compilation_mode_flags { 237 | mode: DBG 238 | # Enable debug symbols. 239 | compiler_flag: "-g" 240 | } 241 | compilation_mode_flags { 242 | mode: OPT 243 | # No debug symbols. 244 | # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or even generally? 245 | # However, that can't happen here, as it requires special handling in Bazel. 246 | compiler_flag: "-g0" 247 | 248 | # Conservative choice for -O 249 | # -O3 can increase binary size and even slow down the resulting binaries. 250 | # Profile first and / or use FDO if you need better performance than this. 251 | compiler_flag: "-O2" 252 | 253 | # Disable assertions 254 | compiler_flag: "-DNDEBUG" 255 | 256 | # Removal of unused code and data at link time (can this increase binary size in some cases?). 257 | compiler_flag: "-ffunction-sections" 258 | compiler_flag: "-fdata-sections" 259 | } 260 | linking_mode_flags { mode: DYNAMIC } 261 | } 262 | -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ['//visibility:public']) 2 | 3 | filegroup( 4 | name = "clang", 5 | srcs = [ 6 | "chromium_clang", 7 | "@org_chromium_clang_linux_x64//:clang", 8 | ], 9 | ) 10 | 11 | filegroup( 12 | name = "ar", 13 | srcs = [ 14 | "chromium_ar", 15 | "@org_chromium_binutils_linux_x64//:ar", 16 | ], 17 | ) 18 | 19 | filegroup( 20 | name = "as", 21 | srcs = [ 22 | "chromium_as", 23 | "@org_chromium_binutils_linux_x64//:as", 24 | ], 25 | ) 26 | 27 | filegroup( 28 | name = "ld_and_symlink", 29 | srcs = [ 30 | "chromium_ld", 31 | "ld", 32 | "@org_chromium_binutils_linux_x64//:ld", 33 | ], 34 | ) 35 | 36 | filegroup( 37 | name = "nm", 38 | srcs = [ 39 | "chromium_nm", 40 | "@org_chromium_binutils_linux_x64//:ar", 41 | ], 42 | ) 43 | 44 | filegroup( 45 | name = "objcopy", 46 | srcs = [ 47 | "chromium_objcopy", 48 | "@org_chromium_binutils_linux_x64//:objcopy", 49 | ], 50 | ) 51 | 52 | filegroup( 53 | name = "objdump", 54 | srcs = [ 55 | "chromium_objdump", 56 | "@org_chromium_binutils_linux_x64//:objdump", 57 | ], 58 | ) 59 | 60 | filegroup( 61 | name = "strip", 62 | srcs = [ 63 | "chromium_strip", 64 | "@org_chromium_binutils_linux_x64//:strip", 65 | ], 66 | ) 67 | 68 | filegroup( 69 | name = "tool-wrappers", 70 | srcs = [ 71 | ":clang", 72 | ":ar", 73 | ":as", 74 | ":ld_and_symlink", 75 | ":nm", 76 | ":objcopy", 77 | ":objdump", 78 | ":strip", 79 | ], 80 | ) 81 | -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/chromium_ar: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a chromium_ar \ 4 | external/org_chromium_binutils_linux_x64/bin/ar \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/chromium_as: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a chromium_as \ 4 | external/org_chromium_binutils_linux_x64/bin/as \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/chromium_clang: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | exec -a "$0" external/org_chromium_clang_linux_x64/bin/clang "$@" -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/chromium_ld: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a chromium_ld \ 4 | external/org_chromium_binutils_linux_x64/bin/ld \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/chromium_nm: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a chromium_nm \ 4 | external/org_chromium_binutils_linux_x64/bin/nm \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/chromium_objcopy: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a chromium_objcopy \ 4 | external/org_chromium_binutils_linux_x64/bin/objcopy \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/chromium_objdump: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a chromium_objdump \ 4 | external/org_chromium_binutils_linux_x64/bin/objdump \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/chromium_strip: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a chromium_strip \ 4 | external/org_chromium_binutils_linux_x64/bin/strip \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/linux_x64/ld: -------------------------------------------------------------------------------- 1 | chromium_ld -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/mac/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ['//tools/cpp:__pkg__']) 2 | 3 | filegroup( 4 | name = "clang", 5 | srcs = [ 6 | "osx_clang_wrapper.sh", 7 | "@org_chromium_clang_mac//:clang", 8 | ], 9 | ) -------------------------------------------------------------------------------- /tools/cpp/tool_wrappers/mac/osx_clang_wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2015 The Bazel Authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # OS X relpath is not really working. This is a wrapper script around gcc 18 | # to simulate relpath behavior. 19 | # 20 | # This wrapper uses install_name_tool to replace all paths in the binary 21 | # (bazel-out/.../path/to/original/library.so) by the paths relative to 22 | # the binary. It parses the command line to behave as rpath is supposed 23 | # to work. 24 | # 25 | # See https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac 26 | # on how to set those paths for Mach-O binaries. 27 | # 28 | set -eu 29 | 30 | GCC=external/org_chromium_clang_mac/bin/clang 31 | INSTALL_NAME_TOOL="/usr/bin/install_name_tool" 32 | 33 | LIBS= 34 | LIB_DIRS= 35 | RPATHS= 36 | OUTPUT= 37 | # let parse the option list 38 | for i in "$@"; do 39 | if [[ "${OUTPUT}" = "1" ]]; then 40 | OUTPUT=$i 41 | elif [[ "$i" =~ ^-l(.*)$ ]]; then 42 | LIBS="${BASH_REMATCH[1]} $LIBS" 43 | elif [[ "$i" =~ ^-L(.*)$ ]]; then 44 | LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS" 45 | elif [[ "$i" =~ ^-Wl,-rpath,\@loader_path/(.*)$ ]]; then 46 | RPATHS="${BASH_REMATCH[1]} ${RPATHS}" 47 | elif [[ "$i" = "-o" ]]; then 48 | # output is coming 49 | OUTPUT=1 50 | fi 51 | done 52 | 53 | # Call gcc 54 | ${GCC} -B /usr/bin "$@" 55 | 56 | function get_library_path() { 57 | for libdir in ${LIB_DIRS}; do 58 | if [ -f ${libdir}/lib$1.so ]; then 59 | echo "${libdir}/lib$1.so" 60 | elif [ -f ${libdir}/lib$1.dylib ]; then 61 | echo "${libdir}/lib$1.dylib" 62 | fi 63 | done 64 | } 65 | 66 | # A convenient method to return the actual path even for non symlinks 67 | # and multi-level symlinks. 68 | function get_realpath() { 69 | local previous="$1" 70 | local next=$(readlink "${previous}") 71 | while [ -n "${next}" ]; do 72 | previous="${next}" 73 | next=$(readlink "${previous}") 74 | done 75 | echo "${previous}" 76 | } 77 | 78 | # Get the path of a lib inside a tool 79 | function get_otool_path() { 80 | # the lib path is the path of the original lib relative to the workspace 81 | get_realpath $1 | sed 's|^.*/bazel-out/|bazel-out/|' 82 | } 83 | 84 | # Do replacements in the output 85 | for rpath in ${RPATHS}; do 86 | for lib in ${LIBS}; do 87 | unset libname 88 | if [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.so" ]; then 89 | libname="lib${lib}.so" 90 | elif [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.dylib" ]; then 91 | libname="lib${lib}.dylib" 92 | fi 93 | # ${libname-} --> return $libname if defined, or undefined otherwise. This is to make 94 | # this set -e friendly 95 | if [[ -n "${libname-}" ]]; then 96 | libpath=$(get_library_path ${lib}) 97 | if [ -n "${libpath}" ]; then 98 | ${INSTALL_NAME_TOOL} -change $(get_otool_path "${libpath}") \ 99 | "@loader_path/${rpath}/${libname}" "${OUTPUT}" 100 | fi 101 | fi 102 | done 103 | done 104 | --------------------------------------------------------------------------------