File tree Expand file tree Collapse file tree 5 files changed +39
-0
lines changed
crates/proc_macro_srv/src Expand file tree Collapse file tree 5 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,7 @@ macro_rules! define_handles {
160
160
}
161
161
define_handles ! {
162
162
' owned:
163
+ FreeFunctions ,
163
164
TokenStream ,
164
165
TokenStreamBuilder ,
165
166
TokenStreamIter ,
Original file line number Diff line number Diff line change @@ -57,6 +57,10 @@ use std::thread;
57
57
macro_rules! with_api {
58
58
( $S: ident, $self: ident, $m: ident) => {
59
59
$m! {
60
+ FreeFunctions {
61
+ fn drop( $self: $S:: FreeFunctions ) ;
62
+ fn track_env_var( var: & str , value: Option <& str >) ;
63
+ } ,
60
64
TokenStream {
61
65
fn drop( $self: $S:: TokenStream ) ;
62
66
fn clone( $self: & $S:: TokenStream ) -> $S:: TokenStream ;
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ use super::client::HandleStore;
11
11
/// Declare an associated item of one of the traits below, optionally
12
12
/// adjusting it (i.e., adding bounds to types and default bodies to methods).
13
13
macro_rules! associated_item {
14
+ ( type FreeFunctions ) =>
15
+ ( type FreeFunctions : ' static ; ) ;
14
16
( type TokenStream ) =>
15
17
( type TokenStream : ' static + Clone ; ) ;
16
18
( type TokenStreamBuilder ) =>
Original file line number Diff line number Diff line change @@ -924,3 +924,25 @@ impl fmt::Debug for Literal {
924
924
self . 0 . fmt ( f)
925
925
}
926
926
}
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
+ }
Original file line number Diff line number Diff line change @@ -242,6 +242,8 @@ impl TokenStreamBuilder {
242
242
}
243
243
}
244
244
245
+ pub struct FreeFunctions ;
246
+
245
247
#[ derive( Clone ) ]
246
248
pub struct TokenStreamIter {
247
249
trees : IntoIter < TokenTree > ,
@@ -254,6 +256,7 @@ pub struct Rustc {
254
256
}
255
257
256
258
impl server:: Types for Rustc {
259
+ type FreeFunctions = FreeFunctions ;
257
260
type TokenStream = TokenStream ;
258
261
type TokenStreamBuilder = TokenStreamBuilder ;
259
262
type TokenStreamIter = TokenStreamIter ;
@@ -267,6 +270,13 @@ impl server::Types for Rustc {
267
270
type MultiSpan = Vec < Span > ;
268
271
}
269
272
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
+
270
280
impl server:: TokenStream for Rustc {
271
281
fn new ( & mut self ) -> Self :: TokenStream {
272
282
Self :: TokenStream :: new ( )
You can’t perform that action at this time.
0 commit comments