Add an OUT_DIR option for finding bindgen output for Android Android are currently using a sed line to replace our include! to a module import. As those don't quite behave the same, and we don't want to carry patches (even as sed lines) downstream like this, we need to find a convention that works for everyone. Most of the Rust world uses environment variables to communicate between the build system and source. However, rather than principled convention, where each target was passed in a separate environment variable, Rust picked an inflexible convention of setting an OUT_DIR variable, and then hardcoding everything else relative to it. It simply assumes the build placed everything in that directory. This is problematic for more complex build systems, which would now take on I/O costs to copy files around into where Rust wants. It's also less convenient for the build file author. So, instead we went with an environment variable that carries the entire path. This has worked out, except that Android's build tool, Soong, cannot express this! It has no way to specify that some build product's path should be passed in via some environment variable. Soong does, however, have some (less preferred, less efficient) way to emulate the OUT_DIR behavior, by copying files around until it's in the place that the Rust convention expects. So introduce that option too, gated on cfg(soong). Update-Note: When this rolls into Android, remove the sed logic from Android.bp and instead set up the OUT_DIR cargo emulation. Bug: b:291253039 Change-Id: Id0afe9259f15f041c953dc5ad945cb9eda24ffc7 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/68048 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
diff --git a/rust/bssl-sys/src/lib.rs b/rust/bssl-sys/src/lib.rs index fa52ec7..e7f5fc4 100644 --- a/rust/bssl-sys/src/lib.rs +++ b/rust/bssl-sys/src/lib.rs
@@ -7,7 +7,13 @@ // Wrap the bindgen output in a module and re-export it, so we can override it // as needed. mod bindgen { + #[cfg(not(soong))] include!(env!("BINDGEN_RS_FILE")); + // Soong, Android's build tool, does not support configuring environment + // variables like other Rust build systems too. However, it does support + // some hardcoded behavior with the OUT_DIR variable. + #[cfg(soong)] + include!(concat!(env!("OUT_DIR"), "/bssl_sys_bindings.rs")); } pub use bindgen::*;