Skip to content

Commit 6503297

Browse files
committed
Stdlib source bootstrap
1 parent 27c0f78 commit 6503297

23 files changed

Lines changed: 629 additions & 103 deletions

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bazel_dep(name = "platforms", version = "1.1.0")
5757
bazel_dep(name = "protobuf", version = "34.0.bcr.1", repo_name = "com_google_protobuf")
5858
bazel_dep(name = "rules_cc", version = "0.2.8")
5959
bazel_dep(name = "rules_proto", version = "7.1.0")
60-
bazel_dep(name = "llvm", version = "0.7.7")
60+
bazel_dep(name = "llvm", version = "0.7.8")
6161
bazel_dep(name = "aspect_tools_telemetry", version = "0.3.3")
6262

6363
osx = use_extension("@llvm//extensions:osx.bzl", "osx")

MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rs/platforms/config/declare_config_settings.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Config settings for Rust target triples."""
22

3-
load("//rs/platforms:triples.bzl", "SUPPORTED_TARGET_TRIPLES", "triple_to_constraint_set")
3+
load("//rs/platforms:triples.bzl", "ALL_TARGET_TRIPLES", "triple_to_constraint_set")
44

5-
def declare_config_settings(targets = SUPPORTED_TARGET_TRIPLES):
5+
def declare_config_settings(targets = ALL_TARGET_TRIPLES):
66
for target_triple in targets:
77
native.config_setting(
88
name = target_triple,

rs/platforms/declare_platforms.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Platform definitions for Rust target triples."""
22

3-
load("//rs/platforms:triples.bzl", "SUPPORTED_TARGET_TRIPLES", "triple_to_constraint_set")
3+
load("//rs/platforms:triples.bzl", "ALL_TARGET_TRIPLES", "triple_to_constraint_set")
44

5-
def declare_platforms(targets = SUPPORTED_TARGET_TRIPLES):
5+
def declare_platforms(targets = ALL_TARGET_TRIPLES):
66
for target_triple in targets:
77
native.platform(
88
name = target_triple,

rs/platforms/triples.bzl

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def triple_to_constraint_set(target_triple):
99
t = triple(target_triple)
1010

1111
if t.system in ("linux", "nixos"):
12+
# TODO: Add LLVM constraint support for libc-less Linux builds.
13+
# if t.abi == "none":
14+
# constraints.append("@llvm//constraints/libc:unconstrained")
15+
# elif t.abi == "musl" or "musl" in target_triple:
1216
if t.abi == "musl" or "musl" in target_triple:
1317
# Rustc passes `-no-pie` on musl so make sure we align.
1418
constraints.append("@llvm//constraints/libc:musl")
@@ -143,5 +147,43 @@ SUPPORTED_TARGET_TRIPLES = [
143147
#"x86_64-unknown-redox", # ✓ Redox OS
144148
"x86_64-unknown-uefi", # ? 64-bit UEFI
145149

146-
# No Tier3 support.
150+
# Additional Tier 3 targets must opt into source stdlib builds.
147151
]
152+
153+
SOURCE_STDLIB_TARGET_TRIPLES = [
154+
"aarch64-unknown-freebsd",
155+
"aarch64-unknown-netbsd",
156+
"aarch64-unknown-nto-qnx710",
157+
"aarch64-unknown-openbsd",
158+
"arm64e-apple-darwin",
159+
"arm64e-apple-ios",
160+
"armv7-unknown-freebsd",
161+
"armv7-unknown-netbsd-eabihf",
162+
"bpfeb-unknown-none",
163+
"bpfel-unknown-none",
164+
"i386-apple-ios",
165+
"i686-apple-darwin",
166+
"i686-unknown-netbsd",
167+
"i686-unknown-openbsd",
168+
"powerpc-unknown-freebsd",
169+
"powerpc-unknown-linux-musl",
170+
"powerpc-unknown-netbsd",
171+
"powerpc-unknown-openbsd",
172+
"powerpc64-unknown-freebsd",
173+
"powerpc64-unknown-openbsd",
174+
"powerpc64le-unknown-freebsd",
175+
"riscv64-linux-android",
176+
"riscv64gc-unknown-freebsd",
177+
"riscv64gc-unknown-fuchsia",
178+
"riscv64gc-unknown-netbsd",
179+
"riscv64gc-unknown-openbsd",
180+
"s390x-unknown-linux-musl",
181+
"sparc64-unknown-netbsd",
182+
"sparc64-unknown-openbsd",
183+
"wasm64-unknown-unknown",
184+
# TODO: Enable once @llvm has constraint support for libc-less Linux builds.
185+
# "x86_64-unknown-linux-none",
186+
"x86_64-unknown-openbsd",
187+
]
188+
189+
ALL_TARGET_TRIPLES = SUPPORTED_TARGET_TRIPLES + SOURCE_STDLIB_TARGET_TRIPLES

rs/private/BUILD.bazel

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
load("@bazel_lib//:bzl_library.bzl", "bzl_library")
2+
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting")
3+
load("@rules_rust//rust:defs.bzl", "rust_stdlib_filegroup")
24
load(":all_crate_deps_test.bzl", "all_crate_deps_tests")
35
load(":cfg_parser_test.bzl", "cfg_parser_tests")
46
load(":lint_flags_test.bzl", "lint_flags_tests")
57
load(":semver_test.bzl", "semver_select_tests")
68

9+
bool_setting(
10+
name = "source_stdlib_building",
11+
build_setting_default = False,
12+
visibility = ["//visibility:public"],
13+
)
14+
15+
config_setting(
16+
name = "is_source_stdlib_building",
17+
flag_values = {
18+
":source_stdlib_building": "true",
19+
},
20+
visibility = ["//visibility:public"],
21+
)
22+
23+
rust_stdlib_filegroup(
24+
name = "empty_stdlib",
25+
srcs = [],
26+
visibility = ["//visibility:public"],
27+
)
28+
729
all_crate_deps_tests()
830

931
cfg_parser_tests()
@@ -109,6 +131,13 @@ bzl_library(
109131
deps = ["@bazel_lib//lib:repo_utils"],
110132
)
111133

134+
bzl_library(
135+
name = "source_stdlib",
136+
srcs = ["source_stdlib.bzl"],
137+
visibility = ["//rs:__subpackages__"],
138+
deps = ["@rules_rust//rust:bzl_lib"],
139+
)
140+
112141
bzl_library(
113142
name = "git_cargo_workspace_repository",
114143
srcs = ["git_cargo_workspace_repository.bzl"],
@@ -126,6 +155,7 @@ bzl_library(
126155
srcs = ["cargo_repository.bzl"],
127156
visibility = ["//rs:__subpackages__"],
128157
deps = [
158+
"//rs/private:rust_repository_utils",
129159
"@rules_rust//rust/platform:bzl_lib",
130160
"@rules_rust//rust/private:bzl_lib",
131161
],
@@ -168,6 +198,11 @@ bzl_library(
168198
srcs = ["rust_src_repository.bzl"],
169199
visibility = ["//rs:__subpackages__"],
170200
deps = [
201+
":cargo_workspace_graph",
202+
":repository_utils",
203+
":toml2json",
204+
"//rs/platforms:triples",
205+
"@bazel_skylib//lib:paths",
171206
"@bazel_tools//tools/build_defs/repo:utils.bzl",
172207
"@rules_rust//rust/private:bzl_lib",
173208
],
@@ -216,16 +251,6 @@ bzl_library(
216251
],
217252
)
218253

219-
bzl_library(
220-
name = "symlink_utils",
221-
srcs = ["symlink_utils.bzl"],
222-
visibility = ["//rs:__subpackages__"],
223-
deps = [
224-
"@bazel_features//:features",
225-
"@bazel_lib//lib:paths",
226-
],
227-
)
228-
229254
bzl_library(
230255
name = "cargo_lints",
231256
srcs = ["cargo_lints.bzl"],

rs/private/cargo_workspace_graph.bzl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def resolve_cargo_workspace_members(
239239
debug,
240240
dep_label_prefix = None,
241241
allow_missing_resolved_deps = False,
242+
skip_internal_rustc_placeholder_crates = True,
242243
watch_manifests = False,
243244
use_legacy_rules_rust_platforms = False):
244245
platform_cfg_attrs = [triple_to_cfg_attrs(triple) for triple in platform_triples]
@@ -248,9 +249,10 @@ def resolve_cargo_workspace_members(
248249

249250
cfg_match_cache = {None: struct(matches = platform_triples, uses_feature_cfg = False)}
250251

251-
workspace_member_keys = {}
252-
for package in cargo_metadata["packages"]:
253-
workspace_member_keys[(package["name"], package["version"])] = True
252+
workspace_member_keys = set([
253+
(package["name"], package["version"])
254+
for package in cargo_metadata["packages"]
255+
])
254256

255257
resolver_versions_by_name = {name: versions[:] for name, versions in versions_by_name.items()}
256258
workspace_members_by_key = {(package["name"], package["version"]): package for package in workspace_members}
@@ -270,6 +272,7 @@ def resolve_cargo_workspace_members(
270272
possible_deps = prepare_possible_deps(
271273
package.get("dependencies", []),
272274
converter = cargo_metadata_dep_to_dep_dict,
275+
skip_internal_rustc_placeholder_crates = skip_internal_rustc_placeholder_crates,
273276
)
274277

275278
package_index = len(resolver_packages)

rs/private/git_cargo_workspace_repository.bzl

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,8 @@
11
load("@bazel_tools//tools/build_defs/repo:git_worker.bzl", "git_repo")
22
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch")
3-
load(":repository_utils.bzl", "cargo_build_file_values")
3+
load(":repository_utils.bzl", "cargo_build_file_values", "inherit_workspace_package_fields")
44
load(":toml2json.bzl", "run_toml2json")
55

6-
_INHERITABLE_FIELDS = [
7-
"version",
8-
"edition",
9-
"description",
10-
"homepage",
11-
"repository",
12-
"license",
13-
# TODO(zbarsky): Do we need to fixup the path for readme and license_file?
14-
"license_file",
15-
"rust_version",
16-
"readme",
17-
]
18-
19-
def _inherit_workspace_package_fields(cargo_toml, workspace_cargo_toml):
20-
workspace_package = workspace_cargo_toml.get("workspace", {}).get("package")
21-
if not workspace_package:
22-
return cargo_toml
23-
24-
crate_package = cargo_toml["package"]
25-
for field in _INHERITABLE_FIELDS:
26-
value = crate_package.get(field)
27-
if type(value) == "dict" and value.get("workspace") == True:
28-
crate_package[field] = workspace_package.get(field)
29-
30-
return cargo_toml
31-
326
def _render_label_list(labels):
337
return ",\n ".join(['"%s"' % label for label in sorted(labels)])
348

@@ -42,7 +16,7 @@ def _render_build_file(rctx, dest, additive_build_file_content, gen_binaries, wo
4216
package_path = rctx.path(dest).dirname
4317
cargo_toml_path = package_path.get_child("Cargo.toml")
4418
cargo_toml = run_toml2json(rctx, cargo_toml_path)
45-
cargo_toml = _inherit_workspace_package_fields(cargo_toml, workspace_cargo_toml)
19+
cargo_toml = inherit_workspace_package_fields(cargo_toml, workspace_cargo_toml)
4620
package = cargo_toml["package"]
4721

4822
cargo = cargo_build_file_values(
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
def _host_tools_repository_impl(rctx):
2-
defs_bzl_content = """\
3-
RS_HOST_CARGO_LABEL = Label("@{host_cargo_repo}//:bin/cargo{binary_suffix}")
4-
""".format(
5-
host_cargo_repo = rctx.attr.host_cargo_repo,
6-
binary_suffix = rctx.attr.binary_suffix,
7-
)
8-
9-
rctx.file("defs.bzl", defs_bzl_content)
2+
rctx.file("defs.bzl", 'RS_HOST_CARGO_LABEL = Label("%s")\n' % rctx.attr.host_cargo)
103
rctx.file("BUILD.bazel", 'exports_files(["defs.bzl"])')
114

125
return rctx.repo_metadata(reproducible = True)
136

147
host_tools_repository = repository_rule(
158
implementation = _host_tools_repository_impl,
169
attrs = {
17-
"host_cargo_repo": attr.string(mandatory = True),
18-
"binary_suffix": attr.string(mandatory = True),
10+
"host_cargo": attr.label(allow_single_file = True, mandatory = True),
1911
},
2012
)

rs/private/repository_utils.bzl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@ def render_select_build_script_env(platform_items, use_legacy_rules_rust_platfor
4040
def _exclude_deps_from_features(features):
4141
return [f for f in features if not f.startswith("dep:")]
4242

43+
_INHERITABLE_PACKAGE_FIELDS = [
44+
"version",
45+
"edition",
46+
"description",
47+
"homepage",
48+
"repository",
49+
"license",
50+
# TODO(zbarsky): Do we need to fixup the path for readme and license_file?
51+
"license_file",
52+
"rust_version",
53+
"readme",
54+
]
55+
56+
def inherit_workspace_package_fields(cargo_toml, workspace_cargo_toml):
57+
workspace_package = workspace_cargo_toml.get("workspace", {}).get("package")
58+
if not workspace_package:
59+
return cargo_toml
60+
61+
crate_package = cargo_toml["package"]
62+
for field in _INHERITABLE_PACKAGE_FIELDS:
63+
value = crate_package.get(field)
64+
if type(value) == "dict" and value.get("workspace") == True:
65+
crate_package[field] = workspace_package.get(field)
66+
67+
return cargo_toml
68+
4369
def cargo_build_file_values(rctx, cargo_toml, gen_binaries, package_path = "", gen_build_script = None):
4470
package_dir = rctx.path(package_path or ".")
4571
package = cargo_toml["package"]
@@ -141,11 +167,15 @@ _RUST_CRATE_MACRO_CALL = """{indent}rust_crate(
141167
{indent} data = [
142168
{indent} {data}
143169
{indent} ],
170+
{indent} extra_compile_data = [
171+
{indent} {extra_compile_data}
172+
{indent} ],
144173
{indent} crate_features = {crate_features},
145174
{indent} triples = {triples},
146175
{indent} conditional_crate_features = {conditional_crate_features},
147176
{indent} crate_root = {crate_root},
148177
{indent} edition = {edition},
178+
{indent} rustc_env = {rustc_env},
149179
{indent} rustc_flags = {rustc_flags}{conditional_rustc_flags},
150180
{indent} tags = {tags},
151181
{indent} target_compatible_with = RESOLVED_PLATFORMS,
@@ -162,10 +192,12 @@ _RUST_CRATE_MACRO_CALL = """{indent}rust_crate(
162192
{indent} is_proc_macro = {is_proc_macro},
163193
{indent} binaries = {binaries},
164194
{indent} use_legacy_rules_rust_platforms = {use_legacy_rules_rust_platforms},
195+
{indent} cargo_toml_env = {cargo_toml_env},
196+
{indent} skip_deps_verification = {skip_deps_verification},
165197
{indent})
166198
"""
167199

168-
def render_rust_crate_call(attr, values, bazel_metadata = {}, extra_deps = "", indent = ""):
200+
def render_rust_crate_call(attr, values, bazel_metadata = {}, extra_deps = "", indent = "", skip_deps_verification = False):
169201
# We keep conditional_crate_features unrendered here because it must be treated specially for build scripts.
170202
# See `rust_crate.bzl` for details.
171203
crate_features, conditional_crate_features = compute_select(
@@ -195,11 +227,13 @@ def render_rust_crate_call(attr, values, bazel_metadata = {}, extra_deps = "", i
195227
extra_deps = extra_deps,
196228
conditional_deps = " + " + conditional_deps if conditional_deps else "",
197229
data = list_indent.join(['"%s"' % d for d in attr.data]),
230+
extra_compile_data = list_indent.join(['"%s"' % d for d in attr.extra_compile_data]),
198231
crate_features = repr(sorted(crate_features)),
199232
triples = repr(attr.crate_features_select.keys()),
200233
conditional_crate_features = repr(conditional_crate_features),
201234
crate_root = values["crate_root"],
202235
edition = values["edition"],
236+
rustc_env = repr(attr.rustc_env),
203237
rustc_flags = repr(rustc_flags),
204238
conditional_rustc_flags = " + " + conditional_rustc_flags if conditional_rustc_flags else "",
205239
tags = repr(attr.crate_tags),
@@ -218,6 +252,8 @@ def render_rust_crate_call(attr, values, bazel_metadata = {}, extra_deps = "", i
218252
is_proc_macro = values["is_proc_macro"],
219253
binaries = values["binaries"],
220254
use_legacy_rules_rust_platforms = use_legacy_rules_rust_platforms,
255+
cargo_toml_env = attr.cargo_toml_env,
256+
skip_deps_verification = repr(skip_deps_verification),
221257
)
222258

223259
def render_build_file_content(rctx, attr, values, bazel_metadata = {}):
@@ -250,16 +286,19 @@ rust_crate_attrs = {
250286
"build_script_tools": attr.label_list(default = []),
251287
"build_script_tools_select": attr.string_list_dict(),
252288
"build_script_tags": attr.string_list(),
289+
"rustc_env": attr.string_dict(),
253290
"rustc_flags": attr.string_list(),
254291
"rustc_flags_select": attr.string_list_dict(),
255292
"crate_tags": attr.string_list(),
256293
"data": attr.label_list(default = []),
294+
"extra_compile_data": attr.label_list(default = []),
257295
"deps": attr.string_list(default = []),
258296
"deps_select": attr.string_list_dict(),
259297
"aliases": attr.string_dict(),
260298
"crate_features": attr.string_list(),
261299
"crate_features_select": attr.string_list_dict(),
262300
"use_legacy_rules_rust_platforms": attr.bool(),
301+
"cargo_toml_env": attr.bool(default = True),
263302
}
264303

265304
common_attrs = rust_crate_attrs | {

0 commit comments

Comments
 (0)