Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable calling build.rs directly from std/build.rs #556

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
extern crate cc;

use std::env;
use std::path::Path;

fn main() {
// Must be public so the build script of `std` can call it.
pub fn main() {
Comment on lines +6 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heck.

match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() {
"android" => build_android(),
_ => {}
}
}

fn build_android() {
let expansion = match cc::Build::new().file("src/android-api.c").try_expand() {
// Resolve `src/android-api.c` relative to this file.
// Required to support calling this from the `std` build script.
let android_api_c = Path::new(file!())
.parent()
.unwrap()
.join("src/android-api.c");
let expansion = match cc::Build::new().file(android_api_c).try_expand() {
Ok(result) => result,
Err(e) => {
println!("failed to run C compiler: {}", e);
Expand Down
4 changes: 4 additions & 0 deletions crates/as-if-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ default-features = false
optional = true
features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive']

[build-dependencies]
# Dependency of the `backtrace` crate
cc = "1.0.67"

[features]
default = ['backtrace']
backtrace = ['addr2line', 'object']
8 changes: 8 additions & 0 deletions crates/as-if-std/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// backtrace-rs requires a feature check on Android targets, so
// we need to run its build.rs as well.
#[allow(unused_extern_crates)]
#[path = "../../build.rs"]
mod backtrace_build_rs;

fn main() {
println!("cargo:rustc-cfg=backtrace_in_libstd");

backtrace_build_rs::main();
}