aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenČ›iu Nicola <[email protected]>2020-08-03 11:57:04 +0100
committerLaurenČ›iu Nicola <[email protected]>2020-10-08 15:06:20 +0100
commit3d169bd3f4cdc2dc3dd09eadbbc17c19214d69f3 (patch)
tree8e8d829f5926401ac8303001fb435b504311c203
parente5f252ade72fee4776396122dc91a17ddc185a66 (diff)
Add track_env_var to the proc macro server
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/client.rs1
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/mod.rs4
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/server.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/mod.rs22
-rw-r--r--crates/proc_macro_srv/src/rustc_server.rs10
-rw-r--r--xtask/src/install.rs2
6 files changed, 40 insertions, 1 deletions
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/client.rs b/crates/proc_macro_srv/src/proc_macro/bridge/client.rs
index cb4b3bdb0..55d6330cc 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/client.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/client.rs
@@ -160,6 +160,7 @@ macro_rules! define_handles {
160} 160}
161define_handles! { 161define_handles! {
162 'owned: 162 'owned:
163 FreeFunctions,
163 TokenStream, 164 TokenStream,
164 TokenStreamBuilder, 165 TokenStreamBuilder,
165 TokenStreamIter, 166 TokenStreamIter,
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs b/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs
index aeb05aad4..b97886eb9 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs
@@ -57,6 +57,10 @@ use std::thread;
57macro_rules! with_api { 57macro_rules! with_api {
58 ($S:ident, $self:ident, $m:ident) => { 58 ($S:ident, $self:ident, $m:ident) => {
59 $m! { 59 $m! {
60 FreeFunctions {
61 fn drop($self: $S::FreeFunctions);
62 fn track_env_var(var: &str, value: Option<&str>);
63 },
60 TokenStream { 64 TokenStream {
61 fn drop($self: $S::TokenStream); 65 fn drop($self: $S::TokenStream);
62 fn clone($self: &$S::TokenStream) -> $S::TokenStream; 66 fn clone($self: &$S::TokenStream) -> $S::TokenStream;
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/server.rs b/crates/proc_macro_srv/src/proc_macro/bridge/server.rs
index 45d41ac02..3acb239af 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/server.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/server.rs
@@ -11,6 +11,8 @@ use super::client::HandleStore;
11/// Declare an associated item of one of the traits below, optionally 11/// Declare an associated item of one of the traits below, optionally
12/// adjusting it (i.e., adding bounds to types and default bodies to methods). 12/// adjusting it (i.e., adding bounds to types and default bodies to methods).
13macro_rules! associated_item { 13macro_rules! associated_item {
14 (type FreeFunctions) =>
15 (type FreeFunctions: 'static;);
14 (type TokenStream) => 16 (type TokenStream) =>
15 (type TokenStream: 'static + Clone;); 17 (type TokenStream: 'static + Clone;);
16 (type TokenStreamBuilder) => 18 (type TokenStreamBuilder) =>
diff --git a/crates/proc_macro_srv/src/proc_macro/mod.rs b/crates/proc_macro_srv/src/proc_macro/mod.rs
index ee0dc9722..fc6e7344f 100644
--- a/crates/proc_macro_srv/src/proc_macro/mod.rs
+++ b/crates/proc_macro_srv/src/proc_macro/mod.rs
@@ -924,3 +924,25 @@ impl fmt::Debug for Literal {
924 self.0.fmt(f) 924 self.0.fmt(f)
925 } 925 }
926} 926}
927
928pub 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}
diff --git a/crates/proc_macro_srv/src/rustc_server.rs b/crates/proc_macro_srv/src/rustc_server.rs
index 7d1695c86..c5fe3591e 100644
--- a/crates/proc_macro_srv/src/rustc_server.rs
+++ b/crates/proc_macro_srv/src/rustc_server.rs
@@ -242,6 +242,8 @@ impl TokenStreamBuilder {
242 } 242 }
243} 243}
244 244
245pub struct FreeFunctions;
246
245#[derive(Clone)] 247#[derive(Clone)]
246pub struct TokenStreamIter { 248pub struct TokenStreamIter {
247 trees: IntoIter<TokenTree>, 249 trees: IntoIter<TokenTree>,
@@ -254,6 +256,7 @@ pub struct Rustc {
254} 256}
255 257
256impl server::Types for Rustc { 258impl server::Types for Rustc {
259 type FreeFunctions = FreeFunctions;
257 type TokenStream = TokenStream; 260 type TokenStream = TokenStream;
258 type TokenStreamBuilder = TokenStreamBuilder; 261 type TokenStreamBuilder = TokenStreamBuilder;
259 type TokenStreamIter = TokenStreamIter; 262 type TokenStreamIter = TokenStreamIter;
@@ -267,6 +270,13 @@ impl server::Types for Rustc {
267 type MultiSpan = Vec<Span>; 270 type MultiSpan = Vec<Span>;
268} 271}
269 272
273impl 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
270impl server::TokenStream for Rustc { 280impl server::TokenStream for Rustc {
271 fn new(&mut self) -> Self::TokenStream { 281 fn new(&mut self) -> Self::TokenStream {
272 Self::TokenStream::new() 282 Self::TokenStream::new()
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
index d829790d7..fcc4f05e4 100644
--- a/xtask/src/install.rs
+++ b/xtask/src/install.rs
@@ -7,7 +7,7 @@ use anyhow::{bail, format_err, Context, Result};
7use crate::not_bash::{pushd, run}; 7use crate::not_bash::{pushd, run};
8 8
9// Latest stable, feel free to send a PR if this lags behind. 9// Latest stable, feel free to send a PR if this lags behind.
10const REQUIRED_RUST_VERSION: u32 = 46; 10const REQUIRED_RUST_VERSION: u32 = 47;
11 11
12pub struct InstallCmd { 12pub struct InstallCmd {
13 pub client: Option<ClientOpt>, 13 pub client: Option<ClientOpt>,