Skip to content

Commit

Permalink
Add test for rust stat64 abi mismatch
Browse files Browse the repository at this point in the history
This tests the fix for rust-lang/rust#131467 in pyodide/pyodide-build#40.
The problem is that rust cannot correctly read file metadata because the ABI of
fstat64 changed between the version of emscripten that the rust compiler built
the standard library against and our version of the rust compiler.

By passing `-Zbuild-std` we rebuild the rust standard library with the correct
abi. I also added a test that works only if we pass `-Zbuild-std`.
  • Loading branch information
hoodmane committed Oct 11, 2024
1 parent 92d6e22 commit d110c7f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile.envs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export PYTHON_ARCHIVE_SHA256=d01ec6a33bc10009b09c17da95cc2759af5a580a7316b3a446e
# to your fork to test the changes are working as expected.

# v0.27.3
export PYODIDE_BUILD_COMMIT=fac0109aa2acf14469320b049d710dd42639bf94
export PYODIDE_BUILD_REPO=https://github.com/pyodide/pyodide-build
export PYODIDE_BUILD_COMMIT=e6928ea61533989063f4ca97138a5dc684144b3d
export PYODIDE_BUILD_REPO=https://github.com/hoodmane/pyodide-build

ifdef CPYTHON_DEBUG
export CPYTHON_ABI_FLAGS=d
Expand Down
10 changes: 10 additions & 0 deletions packages/rust-abi-test/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package:
name: rust-abi-test
version: "1.0"
source:
path: src
requirements:
executable:
- rustup
about:
license: MPL-2.0
19 changes: 19 additions & 0 deletions packages/rust-abi-test/src/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "rust-abi-test"
version = "0.1.0"
edition = "2018"
publish = false

[dependencies]
pyo3 = { version = "0.22.3" }

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]

[lib]
crate-type = ["cdylib"]

[profile.release]
lto = "thin"
overflow-checks = true
3 changes: 3 additions & 0 deletions packages/rust-abi-test/src/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
build-backend = "setuptools.build_meta"
12 changes: 12 additions & 0 deletions packages/rust-abi-test/src/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import setup
from setuptools_rust import Binding, RustExtension

setup(
name="rust_abi_test",
version="1.0",
rust_extensions=[
RustExtension("rust_abi_test", "Cargo.toml", binding=Binding.PyO3)
],
# rust extensions are not zip safe, just like C-extensions.
zip_safe=False,
)
17 changes: 17 additions & 0 deletions packages/rust-abi-test/src/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::fs;
use pyo3::prelude::*;


#[pyfunction]
fn get_file_length(data: &str) -> PyResult<u64> {
let metadata = fs::metadata(data)?;
Ok(metadata.len())
}



#[pymodule]
fn rust_abi_test(m: &Bound<'_, PyModule>) -> pyo3::PyResult<()> {
m.add_function(wrap_pyfunction!(get_file_length, m)?)?;
Ok(())
}
11 changes: 11 additions & 0 deletions packages/rust-abi-test/test_rust_abi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pytest_pyodide import run_in_pyodide

@run_in_pyodide(packages=["rust-abi-test"])
def test_rust_abi(selenium):
from pathlib import Path
from rust_abi_test import get_file_length

contents = "this is the contents of the file\n" * 4
Path("/test.txt").write_text(contents)
assert get_file_length("/test.txt") == len(contents)

7 changes: 0 additions & 7 deletions packages/rust-panic-test/src/Cargo.lock

This file was deleted.

0 comments on commit d110c7f

Please sign in to comment.