Skip to content

Commit

Permalink
Merge pull request #1405 from davidhewitt/build-script-encoding
Browse files Browse the repository at this point in the history
build: fix support for non-utf8 systems
  • Loading branch information
davidhewitt authored Jan 27, 2021
2 parents 3a62758 + 59dac57 commit faf4095
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Fix support for using `r#raw_idents` as argument names in pyfunctions. [#1383](https://github.com/PyO3/pyo3/pull/1383)
- Fix unqualified `Result` usage in `pyobject_native_type_base`. [#1402](https://github.com/PyO3/pyo3/pull/1402)
- Fix build on systems where the default Python encoding is not UTF-8. [#1405](https://github.com/PyO3/pyo3/pull/1405)

## [0.13.1] - 2021-01-10
### Added
Expand Down
17 changes: 14 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,20 @@ fn load_cross_compile_info(
/// Run a python script using the specified interpreter binary.
fn run_python_script(interpreter: &Path, script: &str) -> Result<String> {
let out = Command::new(interpreter)
.args(&["-c", script])
.env("PYTHONIOENCODING", "utf-8")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.output();
.spawn()
.and_then(|mut child| {
use std::io::Write;
child
.stdin
.as_mut()
.expect("piped stdin")
.write_all(script.as_bytes())?;
child.wait_with_output()
});

match out {
Err(err) => {
Expand All @@ -580,7 +591,7 @@ fn run_python_script(interpreter: &Path, script: &str) -> Result<String> {
);
}
}
Ok(ok) if !ok.status.success() => bail!("Python script failed: {}"),
Ok(ok) if !ok.status.success() => bail!("Python script failed"),
Ok(ok) => Ok(String::from_utf8(ok.stdout)?),
}
}
Expand Down

0 comments on commit faf4095

Please sign in to comment.