Skip to content

Commit 3479721

Browse files
authored
Enable calling build.rs directly from std/build.rs (#556)
Enable calling build.rs directly from std/build.rs and call buildscript in `as-if-std` buildscript to test that it will work during bootstrap.
1 parent 037356f commit 3479721

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

build.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
extern crate cc;
22

33
use std::env;
4+
use std::path::Path;
45

5-
fn main() {
6+
// Must be public so the build script of `std` can call it.
7+
pub fn main() {
68
match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() {
79
"android" => build_android(),
810
_ => {}
911
}
1012
}
1113

1214
fn build_android() {
13-
let expansion = match cc::Build::new().file("src/android-api.c").try_expand() {
15+
// Resolve `src/android-api.c` relative to this file.
16+
// Required to support calling this from the `std` build script.
17+
let android_api_c = Path::new(file!())
18+
.parent()
19+
.unwrap()
20+
.join("src/android-api.c");
21+
let expansion = match cc::Build::new().file(android_api_c).try_expand() {
1422
Ok(result) => result,
1523
Err(e) => {
1624
println!("failed to run C compiler: {}", e);

crates/as-if-std/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ default-features = false
2424
optional = true
2525
features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive']
2626

27+
[build-dependencies]
28+
# Dependency of the `backtrace` crate
29+
cc = "1.0.67"
30+
2731
[features]
2832
default = ['backtrace']
2933
backtrace = ['addr2line', 'object']

crates/as-if-std/build.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
// backtrace-rs requires a feature check on Android targets, so
2+
// we need to run its build.rs as well.
3+
#[allow(unused_extern_crates)]
4+
#[path = "../../build.rs"]
5+
mod backtrace_build_rs;
6+
17
fn main() {
28
println!("cargo:rustc-cfg=backtrace_in_libstd");
9+
10+
backtrace_build_rs::main();
311
}

0 commit comments

Comments
 (0)