Buck: build and execute proc-macro2 build script

This commit is contained in:
David Tolnay 2021-08-14 12:06:35 -07:00
parent 4747311a1a
commit 66bac528d2
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 37 additions and 5 deletions

8
third-party/BUCK vendored
View File

@ -1,5 +1,7 @@
# To be generated by Facebook's `reindeer` tool once that is open source.
load("//tools/buck:rust_library.bzl", "rust_library")
rust_library(
name = "bitflags",
srcs = glob(["vendor/bitflags-1.3.1/src/**"]),
@ -42,15 +44,11 @@ rust_library(
rust_library(
name = "proc-macro2",
srcs = glob(["vendor/proc-macro2-1.0.28/src/**"]),
build_script = "vendor/proc-macro2-1.0.28/build.rs",
features = [
"proc-macro",
"span-locations",
],
rustc_flags = [
"--cfg=span_locations",
"--cfg=use_proc_macro",
"--cfg=wrap_proc_macro",
],
visibility = ["PUBLIC"],
deps = [":unicode-xid"],
)

View File

@ -0,0 +1,34 @@
load("//tools/buck:genrule.bzl", "genrule")
def rust_library(
name,
srcs,
features = [],
rustc_flags = [],
build_script = None,
**kwargs):
if build_script:
rust_binary(
name = "%s@build" % name,
srcs = srcs + [build_script],
crate = "build",
crate_root = build_script,
features = features,
rustc_flags = rustc_flags,
)
genrule(
name = "%s@cfg" % name,
out = "output",
cmd = "env RUSTC=rustc TARGET= $(exe :%s@build) | sed -n s/^cargo:rustc-cfg=/--cfg=/p > ${OUT}" % name,
)
rustc_flags = rustc_flags + ["@$(location :%s@cfg)" % name]
native.rust_library(
name = name,
srcs = srcs,
features = features,
rustc_flags = rustc_flags,
**kwargs
)