Skip to content

Commit

Permalink
Bump pyo3 from 0.13.2 to 0.15.0 (#227)
Browse files Browse the repository at this point in the history
* Bump pyo3 from 0.13.2 to 0.15.0

Bumps [pyo3](https://github.com/pyo3/pyo3) from 0.13.2 to 0.14.5.
- [Release notes](https://github.com/pyo3/pyo3/releases)
- [Changelog](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md)
- [Commits](PyO3/pyo3@v0.13.2...v0.14.5)

---
updated-dependencies:
- dependency-name: pyo3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* workaround for linking bug in pyo3

The pyo3 build script removes python library link directives if you're
building an extension module.

This is problem if you want to build a binary that links against Python
and an extension module in the same project (like we are).

Rust features are additive, so it leaves the "extension-module" feature
enabled in the "shared" build of pyo3, this causes pyo3 to fail to emit
linking directives when building the console binary.

This only worked before because we were using two different versions of
pyo3.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jason Mobarak <[email protected]>
  • Loading branch information
dependabot[bot] and Jason Mobarak authored Nov 11, 2021
1 parent dcad705 commit d58a1f2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 96 deletions.
96 changes: 12 additions & 84 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["console_backend", "entrypoint"]
resolver = "2"

[profile.release]
lto = true
Expand Down
32 changes: 28 additions & 4 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ if eq ${os} windows
set_env BACKEND_WHEEL console_backend-0.1.0-cp39-cp39-win_amd64.whl
set_env BUILD_TRIPLET "x86_64-pc-windows-msvc"
set_env PYO3_CONFIG_FILE "${WORKSPACE}\\standalone-py\\pyo3_config.txt"
set_env CONSOLE_PYO3_CONFIG_FILE "${WORKSPACE}\\standalone-py\\pyo3_config.txt"
elseif eq ${os} linux
set_env STANDALONE_PY_URL "${STANDALONE_PY_BASE_URL}/cpython-3.9.7-x86_64-unknown-linux-gnu-pgo+lto-20211017T1616.tar.zst"
set_env PYTHON "${WORKSPACE}/py39/bin/python3"
set_env DIST_PYTHON "${WORKSPACE}/py39-dist/bin/python3"
set_env PYSIDE2_RCC "${WORKSPACE}/py39/bin/pyside2-rcc"
set_env BACKEND_WHEEL console_backend-0.1.0-cp39-cp39-linux_x86_64.whl
set_env PYO3_CONFIG_FILE "${WORKSPACE}/standalone-py/pyo3_config.txt"
set_env CONSOLE_PYO3_CONFIG_FILE "${WORKSPACE}/standalone-py/pyo3_config_console.txt"
output = exec --fail-on-error gcc -dumpmachine
triplet = trim ${output.stdout}
set_env BUILD_TRIPLET ${triplet}
Expand All @@ -28,6 +30,7 @@ else
set_env PYSIDE2_RCC "${WORKSPACE}/py39/bin/pyside2-rcc"
set_env BACKEND_WHEEL console_backend-0.1.0-cp39-cp39-macosx_10_15_x86_64.whl
set_env PYO3_CONFIG_FILE "${WORKSPACE}/standalone-py/pyo3_config.txt"
set_env CONSOLE_PYO3_CONFIG_FILE "${WORKSPACE}/standalone-py/pyo3_config_console.txt"
output = exec --fail-on-error gcc -dumpmachine
triplet = trim ${output.stdout}
set_env BUILD_TRIPLET ${triplet}
Expand Down Expand Up @@ -239,28 +242,40 @@ args = ["-m", "flit", "build", "--no-setup-py"]
[tasks.build-backend-wheel]
cwd = "console_backend"
command = "${PYTHON}"
args = ["setup.py", "bdist_wheel"]
args = ["setup.py", "-vv", "bdist_wheel"]

[tasks.get-get-pip]
script_runner = "@duckscript"
script = '''
wget -O ./get-pip.py https://bootstrap.pypa.io/get-pip.py
'''

[tasks.write-pyo3-config-console]
script_runner = "@duckscript"
cwd = "standalone-py"
condition = { files_not_exist = ["${CONSOLE_PYO3_CONFIG_FILE}"] }
script = '''
writefile pyo3_config_console.txt "implementation=CPython\nversion=3.9\nshared=true\nabi3=false\nlib_name=python3.9\nlib_dir=${WORKSPACE}/standalone-py/python/install/lib\nexecutable=${WORKSPACE}/standalone-py/python/install/bin/python3.9\npointer_width=64\nbuild_flags=WITH_THREAD\nsuppress_build_script_link_lines=false\nextra_build_script_line=cargo:rustc-link-lib=python3.9\nextra_build_script_line=cargo:rustc-link-search=${WORKSPACE}/standalone-py/python/install/lib\n"
'''

[tasks.write-pyo3-config-console.windows]
script_runner = "@duckscript"
script = ""

[tasks.write-pyo3-config]
script_runner = "@duckscript"
cwd = "standalone-py"
condition = { files_not_exist = ["${PYO3_CONFIG_FILE}"] }
script = '''
writefile pyo3_config.txt "implementation=CPython\nversion=3.9\nshared=true\nabi3=false\nlib_name=python3.9\nlib_dir=${WORKSPACE}/standalone-py/python/install/lib\nexecutable=${WORKSPACE}/standalone-py/python/install/bin/python3.9\npointer_width=64\nbuild_flags=WITH_THREAD\nsuppress_build_script_link_lines=false\n"
writefile pyo3_config.txt "implementation=CPython\nversion=3.9\nshared=true\nabi3=false\nlib_name=python3.9\nlib_dir=${WORKSPACE}/standalone-py/python/install/lib\nexecutable=${WORKSPACE}/standalone-py/python/install/bin/python3.9\npointer_width=64\nbuild_flags=WITH_THREAD\nsuppress_build_script_link_lines=false\nextra_build_script_line=\n"
'''

[tasks.write-pyo3-config.windows]
script_runner = "@duckscript"
cwd = "standalone-py"
condition = { files_not_exist = ["${PYO3_CONFIG_FILE}"] }
script = '''
writefile pyo3_config.txt "implementation=CPython\nversion=3.9\nshared=true\nabi3=false\nlib_name=python39\nlib_dir=${WORKSPACE}\\standalone-py\\python\\install\\libs\nexecutable=${WORKSPACE}\\standalone-py\\python\\install\\python.exe\npointer_width=64\nbuild_flags=WITH_THREAD\nsuppress_build_script_link_lines=false\n"
writefile pyo3_config.txt "implementation=CPython\nversion=3.9\nshared=true\nabi3=false\nlib_name=python39\nlib_dir=${WORKSPACE}\\standalone-py\\python\\install\\libs\nexecutable=${WORKSPACE}\\standalone-py\\python\\install\\python.exe\npointer_width=64\nbuild_flags=WITH_THREAD\nsuppress_build_script_link_lines=false\nextra_build_script_line=\n"
'''

[tasks.get-standalone-py]
Expand Down Expand Up @@ -305,10 +320,19 @@ cd ../../..
exec --fail-on-error ${DIST_PYTHON} ./get-pip.py
'''

[tasks.build-console]
[tasks.call-build-console-bin]
private = true
command = "cargo"
args = ["build", "--release", "-vv", "--bin", "console"]

[tasks.build-console]
env = { PYO3_CONFIG_FILE = "${CONSOLE_PYO3_CONFIG_FILE}" }
dependencies = ["write-pyo3-config-console"]
run_task = "call-build-console-bin"

[tasks.build-console.windows]
dependencies = ["call-build-console-bin"]

[tasks.build-dist-install-console]
dependencies = ["build-console"]
script_runner = "@duckscript"
Expand Down
5 changes: 4 additions & 1 deletion console_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ capnp = "0.14"
chrono = { version = "0.4", features = ["serde"] }
csv = "1"
paste = "1"
pyo3 = { version = "0.13", features = ["extension-module"], optional = true }
pyo3 = { version = "0.15", features = [
"extension-module",
"macros",
], default-features = false, optional = true }
serde = { version = "1.0.123", features = ["derive"] }
tempfile = "3.2.0"
ordered-float = "2.0"
Expand Down
8 changes: 4 additions & 4 deletions console_backend/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl ServerEndpoint {
ServerEndpoint { server_send: None }
}

#[text_signature = "($self, bytes, /)"]
#[pyo3(text_signature = "($self, bytes, /)")]
pub fn shutdown(&mut self) -> PyResult<()> {
if let Some(server_send) = self.server_send.take() {
drop(server_send);
Expand All @@ -55,7 +55,7 @@ impl ServerEndpoint {
}
}

#[text_signature = "($self, bytes, /)"]
#[pyo3(text_signature = "($self, bytes, /)")]
pub fn send_message(&mut self, bytes: &PyBytes) -> PyResult<()> {
let byte_vec: Vec<u8> = bytes.extract().unwrap();
if let Some(server_send) = &self.server_send {
Expand All @@ -80,7 +80,7 @@ impl Server {
}
}

#[text_signature = "($self, /)"]
#[pyo3(text_signature = "($self, /)")]
pub fn fetch_message(&mut self, py: Python) -> Option<PyObject> {
let result = py.allow_threads(move || loop {
if let Some(client_recv) = &self.client_recv {
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Server {
result.map(|result| PyBytes::new(py, &result).into())
}

#[text_signature = "($self, /)"]
#[pyo3(text_signature = "($self, /)")]
pub fn start(&mut self) -> PyResult<ServerEndpoint> {
attach_console();
let (client_send, client_recv) = channel::unbounded();
Expand Down
5 changes: 3 additions & 2 deletions entrypoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ name = "console"
version = "0.1.0"
description = "Starts the console with the correct python installation"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
pyo3 = { version = "0.14.5", features = ["auto-initialize"] }
pyo3 = { version = "0.15", features = [
"auto-initialize",
], default-features = false }

[[bin]]
name = "console"
Expand Down
2 changes: 1 addition & 1 deletion standalone-py/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.*~
pyo3_config.txt
pyo3_config*.txt
py39.*
python/

0 comments on commit d58a1f2

Please sign in to comment.