Skip to content

Commit d10c839

Browse files
David Tolnayfacebook-github-bot
authored andcommitted
Parse default edition from buckconfig
Summary: Ordinarily this would be controlled from a BUCK_TREE file / PACKAGE file using `write_package_value`. But our existing PACKAGE files in fbsource are very specific to internal use (with things like Citadel CI config) and are stripped by ShipIt as part of the export to GitHub. This diff reproduces the hierarchical effect of a PACKAGE file using `read_config`. Reviewed By: JakobDegen Differential Revision: D74375801 fbshipit-source-id: eb7d256aaf7cfb3b013b905e1b1df560982223e1
1 parent 07fed16 commit d10c839

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

shim/shims.bzl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def cpp_binary(
243243
)
244244

245245
def rust_library(
246+
edition = None,
246247
rustc_flags = [],
247248
deps = [],
248249
named_deps = None,
@@ -265,6 +266,7 @@ def rust_library(
265266
visibility = ["PUBLIC"]
266267

267268
prelude.rust_library(
269+
edition = edition or _default_rust_edition(),
268270
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
269271
deps = deps,
270272
visibility = visibility,
@@ -273,6 +275,7 @@ def rust_library(
273275
)
274276

275277
def rust_binary(
278+
edition = None,
276279
rustc_flags = [],
277280
deps = [],
278281
autocargo = None,
@@ -286,20 +289,23 @@ def rust_binary(
286289

287290
# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
288291
prelude.rust_binary(
292+
edition = edition or _default_rust_edition(),
289293
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
290294
deps = deps,
291295
visibility = visibility,
292296
**kwargs
293297
)
294298

295299
def rust_unittest(
300+
edition = None,
296301
rustc_flags = [],
297302
deps = [],
298303
visibility = ["PUBLIC"],
299304
**kwargs):
300305
deps = _fix_deps(deps)
301306

302307
prelude.rust_test(
308+
edition = edition or _default_rust_edition(),
303309
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
304310
deps = deps,
305311
visibility = visibility,
@@ -436,6 +442,26 @@ def _fix_resources(resources):
436442

437443
fail("Unexpected type {} for resources".format(type(resources)))
438444

445+
def _default_rust_edition():
446+
package = native.package_name()
447+
448+
# Parse buckconfig entries in the following form:
449+
#
450+
# [rust]
451+
# default_edition = 2024
452+
# default_edition:buck2 = 2021
453+
# default_edition:buck2/dice = 2024
454+
#
455+
if package:
456+
split = package.split("/")
457+
for i in range(len(split)):
458+
parent_directory = "/".join(split[:len(split) - i])
459+
edition = read_config("rust", "default_edition:" + parent_directory)
460+
if edition != None:
461+
return edition
462+
463+
return read_config("rust", "default_edition")
464+
439465
# Do a nasty conversion of e.g. ("supercaml", None, "ocaml-dev") to
440466
# 'fbcode//third-party-buck/platform010/build/supercaml:ocaml-dev'
441467
# (which will then get mapped to `shim//third-party/ocaml:ocaml-dev`).

0 commit comments

Comments
 (0)