}
define_handles! {
'owned:
+ FreeFunctions,
TokenStream,
TokenStreamBuilder,
TokenStreamIter,
macro_rules! with_api {
($S:ident, $self:ident, $m:ident) => {
$m! {
+ FreeFunctions {
+ fn drop($self: $S::FreeFunctions);
+ fn track_env_var(var: &str, value: Option<&str>);
+ },
TokenStream {
fn drop($self: $S::TokenStream);
fn clone($self: &$S::TokenStream) -> $S::TokenStream;
/// Declare an associated item of one of the traits below, optionally
/// adjusting it (i.e., adding bounds to types and default bodies to methods).
macro_rules! associated_item {
+ (type FreeFunctions) =>
+ (type FreeFunctions: 'static;);
(type TokenStream) =>
(type TokenStream: 'static + Clone;);
(type TokenStreamBuilder) =>
self.0.fmt(f)
}
}
+
+pub mod tracked_env {
+ use std::env::{self, VarError};
+ use std::ffi::OsStr;
+
+ /// Retrieve an environment variable and add it to build dependency info.
+ /// Build system executing the compiler will know that the variable was accessed during
+ /// compilation, and will be able to rerun the build when the value of that variable changes.
+ /// Besides the dependency tracking this function should be equivalent to `env::var` from the
+ /// standard library, except that the argument must be UTF-8.
+ pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> {
+ use std::ops::Deref;
+
+ let key: &str = key.as_ref();
+ let value = env::var(key);
+ super::bridge::client::FreeFunctions::track_env_var(
+ key,
+ value.as_ref().map(|t| t.deref()).ok(),
+ );
+ value
+ }
+}
}
}
+pub struct FreeFunctions;
+
#[derive(Clone)]
pub struct TokenStreamIter {
trees: IntoIter<TokenTree>,
}
impl server::Types for Rustc {
+ type FreeFunctions = FreeFunctions;
type TokenStream = TokenStream;
type TokenStreamBuilder = TokenStreamBuilder;
type TokenStreamIter = TokenStreamIter;
type MultiSpan = Vec<Span>;
}
+impl server::FreeFunctions for Rustc {
+ fn track_env_var(&mut self, _var: &str, _value: Option<&str>) {
+ // FIXME: track env var accesses
+ // https://github.com/rust-lang/rust/pull/71858
+ }
+}
+
impl server::TokenStream for Rustc {
fn new(&mut self) -> Self::TokenStream {
Self::TokenStream::new()
use crate::not_bash::{pushd, run};
// Latest stable, feel free to send a PR if this lags behind.
-const REQUIRED_RUST_VERSION: u32 = 46;
+const REQUIRED_RUST_VERSION: u32 = 47;
pub struct InstallCmd {
pub client: Option<ClientOpt>,