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

[internal] Upgrade PyO3 to 14.1 #12405

Merged
merged 4 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
68 changes: 17 additions & 51 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/rust/engine/engine_pyo3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ default = []
hashing = { path = "../hashing" }
nailgun = { path = "../nailgun" }
parking_lot = "0.11"
# We must disable the `auto-initialize` feature because we do not enable `extension-module` normally
# (see above comment in `features`), so `auto-initialize` would try to link to a static Python interpreter during
# tests, which may fail. However, we need to then re-activate the `macros` feature. See
# https://pyo3.rs/v0.13.2/features.html
pyo3 = { version = "0.13", default-features = false, features = ["macros"] }
pyo3 = "0.14"
task_executor = { path = "../task_executor" }
testutil_mock = { package = "mock", path = "../testutil/mock" }
11 changes: 0 additions & 11 deletions src/rust/engine/engine_pyo3/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,4 @@ fn main() {
// NB: The native extension only works with the Python interpreter version it was built with
// (e.g. Python 3.7 vs 3.8).
println!("cargo:rerun-if-env-changed=PY");

if cfg!(target_os = "macos") {
// N.B. On OSX, we force weak linking by passing the param `-undefined dynamic_lookup` to
// the underlying linker. This avoids "missing symbol" errors for Python symbols
// (e.g. `_PyImport_ImportModule`) at build time when bundling the PyO3 sources.
// The missing symbols will instead by dynamically resolved in the address space of the parent
// binary (e.g. `python`) at runtime. We do this to avoid needing to link to libpython
// (which would constrain us to specific versions of Python).
println!("cargo:rustc-cdylib-link-arg=-undefined");
println!("cargo:rustc-cdylib-link-arg=dynamic_lookup");
}
Comment on lines -35 to -44

Choose a reason for hiding this comment

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

You might want to keep this bit around - unfortunately it looks like I'll have to revert this for PyO3 0.14.2: PyO3/pyo3#1719

(I'll probably add something to the pyo3-build-config crate to do essentially what you've written here.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, thanks! I'll pin to 14.1 for now. FYI I have an M1 machine also and I'm happy to help test things with that issue.

}
6 changes: 2 additions & 4 deletions src/rust/engine/engine_pyo3/src/externs/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ fn native_engine_pyo3(py: Python, m: &PyModule) -> PyResult<()> {

#[pyclass]
#[derive(Debug, Clone)]
struct PyExecutor {
executor: task_executor::Executor,
}
struct PyExecutor(task_executor::Executor);

#[pymethods]
impl PyExecutor {
#[new]
fn __new__(core_threads: usize, max_threads: usize) -> PyResult<Self> {
task_executor::Executor::global(core_threads, max_threads)
.map(|executor| PyExecutor { executor })
.map(|executor| PyExecutor(executor))
.map_err(PyException::new_err)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl PyNailgunClient {
fn __new__(port: u16, py_executor: PyExecutor) -> Self {
Self {
port,
executor: py_executor.executor,
executor: py_executor.0,
}
}

Expand Down
28 changes: 10 additions & 18 deletions src/rust/engine/engine_pyo3/src/externs/interface/testutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,44 @@ pub(crate) fn register(m: &PyModule) -> PyResult<()> {
}

#[pyclass]
struct PyStubCASBuilder {
builder: Arc<Mutex<Option<StubCASBuilder>>>,
}
struct PyStubCASBuilder(Arc<Mutex<Option<StubCASBuilder>>>);

#[pymethods]
impl PyStubCASBuilder {
fn always_errors(&mut self) -> PyResult<PyStubCASBuilder> {
let mut builder_opt = self.builder.lock();
let mut builder_opt = self.0.lock();
let builder = builder_opt
.take()
.ok_or_else(|| PyAssertionError::new_err("Unable to unwrap StubCASBuilder"))?;
*builder_opt = Some(builder.always_errors());
Ok(PyStubCASBuilder {
builder: self.builder.clone(),
})
Ok(PyStubCASBuilder(self.0.clone()))
}

fn build(&mut self, py_executor: PyExecutor) -> PyResult<PyStubCAS> {
let mut builder_opt = self.builder.lock();
let mut builder_opt = self.0.lock();
let builder = builder_opt
.take()
.ok_or_else(|| PyAssertionError::new_err("Unable to unwrap StubCASBuilder"))?;
// NB: A Tokio runtime must be used when building StubCAS.
py_executor.executor.enter(|| {
Ok(PyStubCAS {
stub_cas: builder.build(),
})
})
py_executor
.0
.enter(|| Ok(PyStubCAS(builder.build())))
}
}

#[pyclass]
struct PyStubCAS {
stub_cas: StubCAS,
}
struct PyStubCAS(StubCAS);

#[pymethods]
impl PyStubCAS {
#[classmethod]
fn builder(_cls: &PyType) -> PyStubCASBuilder {
let builder = Arc::new(Mutex::new(Some(StubCAS::builder())));
PyStubCASBuilder { builder }
PyStubCASBuilder(builder)
}

#[getter]
fn address(&self) -> String {
self.stub_cas.address()
self.0.address()
}
}