Skip to content

Commit 8b71cb9

Browse files
committed
Enable calling build.rs directly from std/build.rs
1 parent 0533d47 commit 8b71cb9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

build.rs

Lines changed: 10 additions & 2 deletions
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);

0 commit comments

Comments
 (0)