xref: /aosp_15_r20/external/bazelbuild-rules_rust/examples/WORKSPACE.bazel (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifanworkspace(name = "examples")
2*d4726bddSHONG Yifan
3*d4726bddSHONG Yifan# Users of `rules_rust` will commonly be unable to load it
4*d4726bddSHONG Yifan# using a `local_repository`. Instead, to setup the rules,
5*d4726bddSHONG Yifan# please see https://bazelbuild.github.io/rules_rust/#setup
6*d4726bddSHONG Yifanlocal_repository(
7*d4726bddSHONG Yifan    name = "rules_rust",
8*d4726bddSHONG Yifan    path = "..",
9*d4726bddSHONG Yifan)
10*d4726bddSHONG Yifan
11*d4726bddSHONG Yifanload("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
12*d4726bddSHONG Yifan
13*d4726bddSHONG Yifanrules_rust_dependencies()
14*d4726bddSHONG Yifan
15*d4726bddSHONG Yifanrust_register_toolchains(
16*d4726bddSHONG Yifan    edition = "2018",
17*d4726bddSHONG Yifan)
18*d4726bddSHONG Yifan
19*d4726bddSHONG Yifanload("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")
20*d4726bddSHONG Yifan
21*d4726bddSHONG Yifancrate_universe_dependencies(bootstrap = True)
22*d4726bddSHONG Yifan
23*d4726bddSHONG Yifanload("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
24*d4726bddSHONG Yifan
25*d4726bddSHONG Yifanrust_analyzer_dependencies()
26*d4726bddSHONG Yifan
27*d4726bddSHONG Yifanload("@rules_rust//bindgen:repositories.bzl", "rust_bindgen_dependencies", "rust_bindgen_register_toolchains")
28*d4726bddSHONG Yifan
29*d4726bddSHONG Yifanrust_bindgen_dependencies()
30*d4726bddSHONG Yifan
31*d4726bddSHONG Yifanrust_bindgen_register_toolchains()
32*d4726bddSHONG Yifan
33*d4726bddSHONG Yifanload("@rules_rust//bindgen:transitive_repositories.bzl", "rust_bindgen_transitive_dependencies")
34*d4726bddSHONG Yifan
35*d4726bddSHONG Yifanrust_bindgen_transitive_dependencies()
36*d4726bddSHONG Yifan
37*d4726bddSHONG Yifanload("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
38*d4726bddSHONG Yifan
39*d4726bddSHONG Yifan# We need to load rules_java before anything proto-related happens because otherwise it will pull in its own rules_java which isn't compatible with rules_jvm_external.
40*d4726bddSHONG Yifanhttp_archive(
41*d4726bddSHONG Yifan    name = "rules_java",
42*d4726bddSHONG Yifan    sha256 = "f8ae9ed3887df02f40de9f4f7ac3873e6dd7a471f9cddf63952538b94b59aeb3",
43*d4726bddSHONG Yifan    urls = [
44*d4726bddSHONG Yifan        "https://github.com/bazelbuild/rules_java/releases/download/7.6.1/rules_java-7.6.1.tar.gz",
45*d4726bddSHONG Yifan    ],
46*d4726bddSHONG Yifan)
47*d4726bddSHONG Yifan
48*d4726bddSHONG Yifanload("@rules_rust//proto/protobuf:repositories.bzl", "rust_proto_protobuf_dependencies", "rust_proto_protobuf_register_toolchains")
49*d4726bddSHONG Yifan
50*d4726bddSHONG Yifanrust_proto_protobuf_dependencies()
51*d4726bddSHONG Yifan
52*d4726bddSHONG Yifanrust_proto_protobuf_register_toolchains()
53*d4726bddSHONG Yifan
54*d4726bddSHONG Yifanload("@rules_rust//proto/protobuf:transitive_repositories.bzl", "rust_proto_protobuf_transitive_repositories")
55*d4726bddSHONG Yifan
56*d4726bddSHONG Yifanrust_proto_protobuf_transitive_repositories()
57*d4726bddSHONG Yifan
58*d4726bddSHONG Yifanload("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_dependencies", "rust_wasm_bindgen_register_toolchains")
59*d4726bddSHONG Yifan
60*d4726bddSHONG Yifanrust_wasm_bindgen_dependencies()
61*d4726bddSHONG Yifan
62*d4726bddSHONG Yifanrust_wasm_bindgen_register_toolchains()
63*d4726bddSHONG Yifan
64*d4726bddSHONG Yifanload("@rules_rust//wasm_bindgen/rules_nodejs:repositories.bzl", "nodejs_rust_wasm_bindgen_dependencies")
65*d4726bddSHONG Yifan
66*d4726bddSHONG Yifannodejs_rust_wasm_bindgen_dependencies()
67*d4726bddSHONG Yifan
68*d4726bddSHONG Yifanload("@rules_rust//wasm_bindgen/rules_js:repositories.bzl", "js_rust_wasm_bindgen_dependencies")
69*d4726bddSHONG Yifan
70*d4726bddSHONG Yifanjs_rust_wasm_bindgen_dependencies()
71*d4726bddSHONG Yifan
72*d4726bddSHONG Yifan###############################################################################
73*d4726bddSHONG Yifan# Workspace examples
74*d4726bddSHONG Yifan###############################################################################
75*d4726bddSHONG Yifan
76*d4726bddSHONG Yifan# buildifier: disable=same-origin-load
77*d4726bddSHONG Yifanload("@rules_rust//rust:repositories.bzl", "rust_repository_set")
78*d4726bddSHONG Yifan
79*d4726bddSHONG Yifan# `rust_repository_set` is the core repository rule for downloading and defining
80*d4726bddSHONG Yifan# a rust_toolchain. Should there be a need for a customized toolchain, this macro can
81*d4726bddSHONG Yifan# be used to define and register one.
82*d4726bddSHONG Yifanrust_repository_set(
83*d4726bddSHONG Yifan    name = "fake_toolchain_for_test_of_sha256",
84*d4726bddSHONG Yifan    edition = "2018",
85*d4726bddSHONG Yifan    exec_triple = "x86_64-unknown-linux-gnu",
86*d4726bddSHONG Yifan    extra_target_triples = [],
87*d4726bddSHONG Yifan    sha256s = {
88*d4726bddSHONG Yifan        "rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5",
89*d4726bddSHONG Yifan        "rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc",
90*d4726bddSHONG Yifan        "rustfmt-1.4.12-x86_64-unknown-linux-gnu": "1894e76913303d66bf40885a601462844eec15fca9e76a6d13c390d7000d64b0",
91*d4726bddSHONG Yifan    },
92*d4726bddSHONG Yifan    versions = ["1.46.0"],
93*d4726bddSHONG Yifan)
94*d4726bddSHONG Yifan
95*d4726bddSHONG Yifan###############################################################################
96*d4726bddSHONG Yifan# Examples dependencies
97*d4726bddSHONG Yifan###############################################################################
98*d4726bddSHONG Yifan
99*d4726bddSHONG Yifanhttp_archive(
100*d4726bddSHONG Yifan    name = "build_bazel_rules_nodejs",
101*d4726bddSHONG Yifan    sha256 = "709cc0dcb51cf9028dd57c268066e5bc8f03a119ded410a13b5c3925d6e43c48",
102*d4726bddSHONG Yifan    urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.4/rules_nodejs-5.8.4.tar.gz"],
103*d4726bddSHONG Yifan)
104*d4726bddSHONG Yifan
105*d4726bddSHONG Yifanload("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
106*d4726bddSHONG Yifan
107*d4726bddSHONG Yifannode_repositories()
108*d4726bddSHONG Yifan
109*d4726bddSHONG Yifanload("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
110*d4726bddSHONG Yifan
111*d4726bddSHONG Yifanrules_js_dependencies()
112*d4726bddSHONG Yifan
113*d4726bddSHONG Yifanload("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
114*d4726bddSHONG Yifan
115*d4726bddSHONG Yifannodejs_register_toolchains(
116*d4726bddSHONG Yifan    name = "nodejs",
117*d4726bddSHONG Yifan    node_version = DEFAULT_NODE_VERSION,
118*d4726bddSHONG Yifan)
119*d4726bddSHONG Yifan
120*d4726bddSHONG Yifanload("@bazel_features//:deps.bzl", "bazel_features_deps")
121*d4726bddSHONG Yifan
122*d4726bddSHONG Yifanbazel_features_deps()
123*d4726bddSHONG Yifan
124*d4726bddSHONG Yifanhttp_archive(
125*d4726bddSHONG Yifan    name = "rules_foreign_cc",
126*d4726bddSHONG Yifan    sha256 = "69023642d5781c68911beda769f91fcbc8ca48711db935a75da7f6536b65047f",
127*d4726bddSHONG Yifan    strip_prefix = "rules_foreign_cc-0.6.0",
128*d4726bddSHONG Yifan    url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.6.0.tar.gz",
129*d4726bddSHONG Yifan)
130*d4726bddSHONG Yifan
131*d4726bddSHONG Yifanload("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
132*d4726bddSHONG Yifan
133*d4726bddSHONG Yifanrules_foreign_cc_dependencies()
134*d4726bddSHONG Yifan
135*d4726bddSHONG Yifanload("//sys:sys_deps.bzl", "sys_deps")
136*d4726bddSHONG Yifan
137*d4726bddSHONG Yifansys_deps()
138*d4726bddSHONG Yifan
139*d4726bddSHONG Yifanlocal_repository(
140*d4726bddSHONG Yifan    name = "rules_rust_example_cargo_manifest_dir",
141*d4726bddSHONG Yifan    path = "cargo_manifest_dir/external_crate",
142*d4726bddSHONG Yifan)
143*d4726bddSHONG Yifan
144*d4726bddSHONG Yifan_LIBC_BUILD_FILE_CONTENT = """\
145*d4726bddSHONG Yifanload("@rules_rust//rust:defs.bzl", "rust_library")
146*d4726bddSHONG Yifan
147*d4726bddSHONG Yifanrust_library(
148*d4726bddSHONG Yifan    name = "libc",
149*d4726bddSHONG Yifan    srcs = glob(["src/**/*.rs"]),
150*d4726bddSHONG Yifan    edition = "2015",
151*d4726bddSHONG Yifan    rustc_flags = [
152*d4726bddSHONG Yifan        # In most cases, warnings in 3rd party crates are not interesting as
153*d4726bddSHONG Yifan        # they're out of the control of consumers. The flag here silences
154*d4726bddSHONG Yifan        # warnings. For more details see:
155*d4726bddSHONG Yifan        # https://doc.rust-lang.org/rustc/lints/levels.html
156*d4726bddSHONG Yifan        "--cap-lints=allow",
157*d4726bddSHONG Yifan    ],
158*d4726bddSHONG Yifan    visibility = ["//visibility:public"],
159*d4726bddSHONG Yifan)
160*d4726bddSHONG Yifan"""
161*d4726bddSHONG Yifan
162*d4726bddSHONG Yifanhttp_archive(
163*d4726bddSHONG Yifan    name = "libc",
164*d4726bddSHONG Yifan    build_file_content = _LIBC_BUILD_FILE_CONTENT,
165*d4726bddSHONG Yifan    sha256 = "1ac4c2ac6ed5a8fb9020c166bc63316205f1dc78d4b964ad31f4f21eb73f0c6d",
166*d4726bddSHONG Yifan    strip_prefix = "libc-0.2.20",
167*d4726bddSHONG Yifan    urls = [
168*d4726bddSHONG Yifan        "https://mirror.bazel.build/github.com/rust-lang/libc/archive/0.2.20.zip",
169*d4726bddSHONG Yifan        "https://github.com/rust-lang/libc/archive/0.2.20.zip",
170*d4726bddSHONG Yifan    ],
171*d4726bddSHONG Yifan)
172*d4726bddSHONG Yifan
173*d4726bddSHONG Yifanhttp_archive(
174*d4726bddSHONG Yifan    name = "rules_jvm_external",
175*d4726bddSHONG Yifan    sha256 = "08ea921df02ffe9924123b0686dc04fd0ff875710bfadb7ad42badb931b0fd50",
176*d4726bddSHONG Yifan    strip_prefix = "rules_jvm_external-6.1",
177*d4726bddSHONG Yifan    url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/6.1/rules_jvm_external-6.1.tar.gz",
178*d4726bddSHONG Yifan)
179*d4726bddSHONG Yifan
180*d4726bddSHONG Yifanload("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
181*d4726bddSHONG Yifan
182*d4726bddSHONG Yifanrules_jvm_external_deps()
183*d4726bddSHONG Yifan
184*d4726bddSHONG Yifanload("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
185*d4726bddSHONG Yifan
186*d4726bddSHONG Yifanrules_jvm_external_setup()
187*d4726bddSHONG Yifan
188*d4726bddSHONG Yifanload("@rules_jvm_external//:defs.bzl", "maven_install")
189*d4726bddSHONG Yifan
190*d4726bddSHONG Yifanmaven_install(
191*d4726bddSHONG Yifan    name = "maven",
192*d4726bddSHONG Yifan    artifacts = [
193*d4726bddSHONG Yifan        "net.java.dev.jna:jna:5.14.0",
194*d4726bddSHONG Yifan        "org.hamcrest:hamcrest:2.2",
195*d4726bddSHONG Yifan    ],
196*d4726bddSHONG Yifan    maven_install_json = "@//:maven_install.json",
197*d4726bddSHONG Yifan    repositories = [
198*d4726bddSHONG Yifan        "https://repo1.maven.org/maven2",
199*d4726bddSHONG Yifan    ],
200*d4726bddSHONG Yifan)
201*d4726bddSHONG Yifan
202*d4726bddSHONG Yifanload("@maven//:defs.bzl", "pinned_maven_install")
203*d4726bddSHONG Yifan
204*d4726bddSHONG Yifanpinned_maven_install()
205*d4726bddSHONG Yifan
206*d4726bddSHONG Yifan###############################################################################
207*d4726bddSHONG Yifan
208*d4726bddSHONG Yifanhttp_archive(
209*d4726bddSHONG Yifan    name = "bazel_ci_rules",
210*d4726bddSHONG Yifan    sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
211*d4726bddSHONG Yifan    strip_prefix = "bazelci_rules-1.0.0",
212*d4726bddSHONG Yifan    url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
213*d4726bddSHONG Yifan)
214*d4726bddSHONG Yifan
215*d4726bddSHONG Yifanload("@bazel_ci_rules//:rbe_repo.bzl", "rbe_preconfig")
216*d4726bddSHONG Yifan
217*d4726bddSHONG Yifan# Creates a default toolchain config for RBE.
218*d4726bddSHONG Yifan# Use this as is if you are using the rbe_ubuntu16_04 container,
219*d4726bddSHONG Yifan# otherwise refer to RBE docs.
220*d4726bddSHONG Yifanrbe_preconfig(
221*d4726bddSHONG Yifan    name = "buildkite_config",
222*d4726bddSHONG Yifan    toolchain = "ubuntu1804-bazel-java11",
223*d4726bddSHONG Yifan)
224*d4726bddSHONG Yifan
225*d4726bddSHONG Yifanload("@build_bazel_apple_support//crosstool:setup.bzl", "apple_cc_configure")
226*d4726bddSHONG Yifan
227*d4726bddSHONG Yifan# As of Bazel 7, Bazel's bundled cc_toolchain only supports using CommandLineTools and not a full Xcode.
228*d4726bddSHONG Yifan# This manifests itself if you try to use anything which requires access to $DEVELOPER_DIR, such as our bindgen example which non-hermetically tries to read libc++ headers from the system.
229*d4726bddSHONG Yifan# On CI (and for some of our contributors), we have a full Xcode install, so this fails.
230*d4726bddSHONG Yifan# We register the apple_support cc_toolchain here because it supports both CommandLineTools and full Xcodes.
231*d4726bddSHONG Yifan# See https://github.com/bazelbuild/rules_rust/issues/2207 and https://github.com/bazelbuild/bazel/issues/20638
232*d4726bddSHONG Yifanapple_cc_configure()
233