-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pyo3-build-config: inline config when not cross compiling
- Loading branch information
David Hewitt
committed
Aug 4, 2021
1 parent
20b34a5
commit 9507979
Showing
5 changed files
with
135 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
// Import some modules from this crate inline to generate the build config. | ||
// Allow dead code because not all code in the modules is used in this build script. | ||
|
||
#[path = "src/impl_.rs"] | ||
#[allow(dead_code)] | ||
mod impl_; | ||
|
||
#[path = "src/errors.rs"] | ||
#[allow(dead_code)] | ||
mod errors; | ||
|
||
use std::{env, path::Path}; | ||
|
||
use errors::{Result, Context}; | ||
|
||
fn generate_build_config() -> Result<()> { | ||
// Create new interpreter config and write it to the default location | ||
let interpreter_config = impl_::make_interpreter_config()?; | ||
|
||
let path = Path::new(&env::var_os("OUT_DIR").unwrap()).join("pyo3-build-config.txt"); | ||
interpreter_config | ||
.to_writer(&mut std::fs::File::create(&path).with_context(|| { | ||
format!("failed to create config file at {}", path.display()) | ||
})?) | ||
} | ||
|
||
fn main() { | ||
// Empty build script to force cargo to produce the "OUT_DIR" environment variable. | ||
if let Err(e) = generate_build_config() { | ||
eprintln!("error: {}", e.report()); | ||
std::process::exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters