blob: 87af5d7d5fef7af6a59e3bb9167fb7833eab69a1 [file] [log] [blame]
diff --git a/src/expand.rs b/src/expand.rs
index 813ba85d..3d4e3148 100644
--- a/src/expand.rs
+++ b/src/expand.rs
@@ -23,7 +23,7 @@ fn try_cfg(introducer: &str, args: TokenStream, input: TokenStream) -> Result<To
let expr = expr::parse(full_args)?;
token::parse_end(full_args)?;
- if expr.eval(crate::RUSTVERSION) {
+ if expr.eval(crate::rust_version()) {
Ok(input)
} else {
Ok(TokenStream::new())
@@ -31,7 +31,7 @@ fn try_cfg(introducer: &str, args: TokenStream, input: TokenStream) -> Result<To
}
pub fn try_attr(args: attr::Args, input: TokenStream) -> Result<TokenStream> {
- if !args.condition.eval(crate::RUSTVERSION) {
+ if !args.condition.eval(crate::rust_version()) {
return Ok(input);
}
diff --git a/src/lib.rs b/src/lib.rs
index 2b4c4d79..bb0e376d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -213,12 +213,25 @@ use crate::error::Error;
use crate::version::Version;
use proc_macro::TokenStream;
-#[cfg(not(host_os = "windows"))]
+#[cfg(all(not(host_os = "windows"), not(soong)))]
const RUSTVERSION: Version = include!(concat!(env!("OUT_DIR"), "/version.expr"));
-#[cfg(host_os = "windows")]
+#[cfg(all(host_os = "windows", not(soong)))]
const RUSTVERSION: Version = include!(concat!(env!("OUT_DIR"), "\\version.expr"));
+#[cfg(not(soong))]
+fn rust_version() -> Version { RUSTVERSION }
+
+#[cfg(soong)]
+fn rust_version() -> Version {
+ let v: Vec<&str> = option_env!("ANDROID_RUST_VERSION").unwrap().split('.').collect();
+ Version {
+ minor: v[1].parse().unwrap(),
+ patch: v[2].parse().unwrap(),
+ channel: version::Channel::Stable,
+ }
+}
+
#[proc_macro_attribute]
pub fn stable(args: TokenStream, input: TokenStream) -> TokenStream {
expand::cfg("stable", args, input)
@@ -274,7 +287,7 @@ pub fn cfg(input: TokenStream) -> TokenStream {
let ref mut args = iter::new(input);
let expr = expr::parse(args)?;
token::parse_end(args)?;
- let boolean = expr.eval(RUSTVERSION);
+ let boolean = expr.eval(rust_version());
let ident = Ident::new(&boolean.to_string(), Span::call_site());
Ok(TokenStream::from(TokenTree::Ident(ident)))
})()