blob: 89dfc783efeba1bcab6ec78109d1bf0c9119af87 [file] [log] [blame]
Brian Silverman7d89e282021-11-17 17:36:54 -08001# Copyright 2018 The Bazel Authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15workspace(
16 name = "com_grail_bazel_toolchain",
17)
18
19load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies")
20
21bazel_toolchain_dependencies()
22
23load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")
24
25llvm_toolchain(
26 name = "llvm_toolchain",
27 llvm_version = "12.0.0",
28)
29
30load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")
31
32llvm_register_toolchains()
33
34## Toolchain example with a sysroot.
35load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
36
37# This sysroot is used by github.com/vsco/bazel-toolchains.
38http_archive(
39 name = "org_chromium_sysroot_linux_x64",
40 build_file_content = """
41filegroup(
42 name = "sysroot",
43 srcs = glob(["*/**"]),
44 visibility = ["//visibility:public"],
45)
46""",
47 sha256 = "84656a6df544ecef62169cfe3ab6e41bb4346a62d3ba2a045dc5a0a2ecea94a3",
48 urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/2202c161310ffde63729f29d27fe7bb24a0bc540/debian_stretch_amd64_sysroot.tar.xz"],
49)
50
51llvm_toolchain(
52 name = "llvm_toolchain_with_sysroot",
53 llvm_version = "12.0.0",
54 sysroot = {
55 "linux-x86_64": "@org_chromium_sysroot_linux_x64//:sysroot",
56 },
57 # We can share the downloaded LLVM distribution with the first configuration.
58 toolchain_roots = {
59 "": "@llvm_toolchain_llvm//",
60 },
61)
62
63# Well known repos; present here only for testing.
64
65http_archive(
66 name = "com_google_googletest",
67 sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
68 strip_prefix = "googletest-release-1.10.0",
69 urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"],
70)
71
72http_archive(
73 name = "com_github_google_benchmark",
74 sha256 = "3c6a165b6ecc948967a1ead710d4a181d7b0fbcaa183ef7ea84604994966221a",
75 strip_prefix = "benchmark-1.5.0",
76 urls = ["https://github.com/google/benchmark/archive/v1.5.0.tar.gz"],
77)
78
79http_archive(
80 name = "com_google_absl",
81 sha256 = "59b862f50e710277f8ede96f083a5bb8d7c9595376146838b9580be90374ee1f",
82 strip_prefix = "abseil-cpp-20210324.2",
83 urls = ["https://github.com/abseil/abseil-cpp/archive/20210324.2.tar.gz"],
84)
85
86http_archive(
87 name = "openssl",
88 build_file = "//tests/openssl:openssl.bazel",
89 sha256 = "f6fb3079ad15076154eda9413fed42877d668e7069d9b87396d0804fdb3f4c90",
90 strip_prefix = "openssl-1.1.1c",
91 urls = ["https://www.openssl.org/source/openssl-1.1.1c.tar.gz"],
92)
93
94http_archive(
95 name = "io_bazel_rules_go",
96 sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb",
97 urls = [
98 "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
99 "https://github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
100 ],
101)
102
103load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
104
105go_rules_dependencies()
106
107go_register_toolchains(version = "1.17")
108
109# For testing rules_foreign_cc.
110# See https://bazelbuild.github.io/rules_foreign_cc/0.6.0/cmake.html
111
112http_archive(
113 name = "rules_foreign_cc",
114 sha256 = "69023642d5781c68911beda769f91fcbc8ca48711db935a75da7f6536b65047f",
115 strip_prefix = "rules_foreign_cc-0.6.0",
116 url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.6.0.tar.gz",
117)
118
119load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
120
121rules_foreign_cc_dependencies()
122
123_ALL_CONTENT = """\
124filegroup(
125 name = "all_srcs",
126 srcs = glob(["**"]),
127 visibility = ["//visibility:public"],
128)
129"""
130
131http_archive(
132 name = "pcre",
133 build_file_content = _ALL_CONTENT,
134 sha256 = "0b8e7465dc5e98c757cc3650a20a7843ee4c3edf50aaf60bb33fd879690d2c73",
135 strip_prefix = "pcre-8.43",
136 urls = [
137 "https://mirror.bazel.build/ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz",
138 "https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz",
139 ],
140)
141
142http_archive(
143 name = "rules_rust",
144 sha256 = "531bdd470728b61ce41cf7604dc4f9a115983e455d46ac1d0c1632f613ab9fc3",
145 strip_prefix = "rules_rust-d8238877c0e552639d3e057aadd6bfcf37592408",
146 urls = [
147 # `main` branch as of 2021-08-23
148 "https://github.com/bazelbuild/rules_rust/archive/d8238877c0e552639d3e057aadd6bfcf37592408.tar.gz",
149 ],
150)
151
152load("@rules_rust//rust:repositories.bzl", "rust_repositories")
153
154rust_repositories(
155 edition = "2018",
156 version = "1.55.0",
157)
158
159# We're using `git2` as our Rust test because it links against C code
160# (`libgit2-sys`) using `cc`, has tests, and is non-trivial but not _massive_.
161#
162# Ordinarily we'd just run the `rules_rust` tests but those break when run
163# from another workspace (some of the skylib unittests expect paths within the
164# main workspace and fail when paths like `external/rules_rust/...` are
165# produced) and we want to test usage of the cc_toolchain via the `cc` crate
166# anyways (as of this writing nothing in `@rules_rust//tests` seems to test
167# this).
168GIT2_RS_VER = "0.13.22"
169
170GIT2_RS_SHA = "9c1cbbfc9a1996c6af82c2b4caf828d2c653af4fcdbb0e5674cc966eee5a4197"
171
172http_archive(
173 name = "git2",
174 build_file_content = """
175package(default_visibility = ["//visibility:public"])
176
177load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
178load("@crates//:defs.bzl", "crates_from", "dev_crates_from", "crate")
179
180DEV_CRATES = dev_crates_from("@git2//:Cargo.toml")
181DEV_CRATES.remove(crate("paste")) # This is a proc_macro crate!
182
183rust_library(
184 name = "git2",
185 srcs = glob(["src/**/*.rs"]),
186 deps = crates_from("@git2//:Cargo.toml"),
187)
188
189rust_test(
190 name = "git2-tests",
191 crate = ":git2",
192 deps = DEV_CRATES,
193 proc_macro_deps = [crate("paste")],
194)
195
196[
197 rust_test(
198 name = t[len("tests/"):][:-len(".rs")],
199 srcs = [t],
200 deps = [":git2"] + DEV_CRATES,
201 proc_macro_deps = [crate("paste")],
202 )
203 for t in glob(["tests/*.rs"])
204]
205""",
206 canonical_id = GIT2_RS_VER,
207 patch_args = ["-p1"],
208 # We need to remove some `[target]` entries in `git2`'s `Cargo.toml` to
209 # make `crate-universe` happy.
210 #
211 # See: https://github.com/bazelbuild/rules_rust/issues/783
212 patches = ["//tests/rust:git2-rs-cargo-toml.patch"],
213 sha256 = GIT2_RS_SHA,
214 strip_prefix = "git2-{ver}".format(ver = GIT2_RS_VER),
215 type = "tar.gz",
216 url = "https://crates.io/api/v1/crates/git2/{ver}/download".format(ver = GIT2_RS_VER),
217)
218
219# Snippets for `crate_universe`:
220RULES_RUST_CRATE_UNIVERSE_URL_TEMPLATE = "https://github.com/bazelbuild/rules_rust/releases/download/crate_universe-13/crate_universe_resolver-{host_triple}{extension}"
221
222RULES_RUST_CRATE_UNIVERSE_SHA256_CHECKSUMS = {
223 "aarch64-apple-darwin": "c6017cd8a4fee0f1796a8db184e9d64445dd340b7f48a65130d7ee61b97051b4",
224 "aarch64-unknown-linux-gnu": "d0a310b03b8147e234e44f6a93e8478c260a7c330e5b35515336e7dd67150f35",
225 "x86_64-apple-darwin": "762f1c77b3cf1de8e84d7471442af1314157efd90720c7e1f2fff68556830ee2",
226 "x86_64-pc-windows-gnu": "c44bd97373d690587e74448b13267077d133f04e89bedfc9d521ae8ba55dddb9",
227 "x86_64-unknown-linux-gnu": "aebf51af6a3dd33fdac463b35b0c3f4c47ab93e052099199673289e2025e5824",
228}
229
230load("@rules_rust//crate_universe:defs.bzl", "crate_universe")
231
232crate_universe(
233 name = "crates",
234 cargo_toml_files = [
235 "@git2//:Cargo.toml",
236 ],
237 resolver_download_url_template = RULES_RUST_CRATE_UNIVERSE_URL_TEMPLATE,
238 resolver_sha256s = RULES_RUST_CRATE_UNIVERSE_SHA256_CHECKSUMS,
239)
240
241load("@crates//:defs.bzl", "pinned_rust_install")
242
243pinned_rust_install()