Skip to content

Commit e6a05e6

Browse files
bors[bot]lnicola
andauthored
Merge #5651
5651: Add track_env_var to the proc macro server r=kjeremy a=lnicola See rust-lang/rust#74653. Fixes #6054. Fixes #5640, maybe. Should be merged when 1.47 is released. Proc macros still don't work for me, but it no longer crashes. Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2 parents e95e666 + 3d169bd commit e6a05e6

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

crates/proc_macro_srv/src/proc_macro/bridge/client.rs

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ macro_rules! define_handles {
160160
}
161161
define_handles! {
162162
'owned:
163+
FreeFunctions,
163164
TokenStream,
164165
TokenStreamBuilder,
165166
TokenStreamIter,

crates/proc_macro_srv/src/proc_macro/bridge/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ use std::thread;
5757
macro_rules! with_api {
5858
($S:ident, $self:ident, $m:ident) => {
5959
$m! {
60+
FreeFunctions {
61+
fn drop($self: $S::FreeFunctions);
62+
fn track_env_var(var: &str, value: Option<&str>);
63+
},
6064
TokenStream {
6165
fn drop($self: $S::TokenStream);
6266
fn clone($self: &$S::TokenStream) -> $S::TokenStream;

crates/proc_macro_srv/src/proc_macro/bridge/server.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use super::client::HandleStore;
1111
/// Declare an associated item of one of the traits below, optionally
1212
/// adjusting it (i.e., adding bounds to types and default bodies to methods).
1313
macro_rules! associated_item {
14+
(type FreeFunctions) =>
15+
(type FreeFunctions: 'static;);
1416
(type TokenStream) =>
1517
(type TokenStream: 'static + Clone;);
1618
(type TokenStreamBuilder) =>

crates/proc_macro_srv/src/proc_macro/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -924,3 +924,25 @@ impl fmt::Debug for Literal {
924924
self.0.fmt(f)
925925
}
926926
}
927+
928+
pub mod tracked_env {
929+
use std::env::{self, VarError};
930+
use std::ffi::OsStr;
931+
932+
/// Retrieve an environment variable and add it to build dependency info.
933+
/// Build system executing the compiler will know that the variable was accessed during
934+
/// compilation, and will be able to rerun the build when the value of that variable changes.
935+
/// Besides the dependency tracking this function should be equivalent to `env::var` from the
936+
/// standard library, except that the argument must be UTF-8.
937+
pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> {
938+
use std::ops::Deref;
939+
940+
let key: &str = key.as_ref();
941+
let value = env::var(key);
942+
super::bridge::client::FreeFunctions::track_env_var(
943+
key,
944+
value.as_ref().map(|t| t.deref()).ok(),
945+
);
946+
value
947+
}
948+
}

crates/proc_macro_srv/src/rustc_server.rs

+10
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ impl TokenStreamBuilder {
242242
}
243243
}
244244

245+
pub struct FreeFunctions;
246+
245247
#[derive(Clone)]
246248
pub struct TokenStreamIter {
247249
trees: IntoIter<TokenTree>,
@@ -254,6 +256,7 @@ pub struct Rustc {
254256
}
255257

256258
impl server::Types for Rustc {
259+
type FreeFunctions = FreeFunctions;
257260
type TokenStream = TokenStream;
258261
type TokenStreamBuilder = TokenStreamBuilder;
259262
type TokenStreamIter = TokenStreamIter;
@@ -267,6 +270,13 @@ impl server::Types for Rustc {
267270
type MultiSpan = Vec<Span>;
268271
}
269272

273+
impl server::FreeFunctions for Rustc {
274+
fn track_env_var(&mut self, _var: &str, _value: Option<&str>) {
275+
// FIXME: track env var accesses
276+
// https://github.com/rust-lang/rust/pull/71858
277+
}
278+
}
279+
270280
impl server::TokenStream for Rustc {
271281
fn new(&mut self) -> Self::TokenStream {
272282
Self::TokenStream::new()

xtask/src/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use anyhow::{bail, format_err, Context, Result};
77
use crate::not_bash::{pushd, run};
88

99
// Latest stable, feel free to send a PR if this lags behind.
10-
const REQUIRED_RUST_VERSION: u32 = 46;
10+
const REQUIRED_RUST_VERSION: u32 = 47;
1111

1212
pub struct InstallCmd {
1313
pub client: Option<ClientOpt>,

0 commit comments

Comments
 (0)