forked from pyodide/pyodide
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for rust stat64 abi mismatch
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
Showing
8 changed files
with
74 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package: | ||
name: rust-abi-test | ||
version: "1.0" | ||
source: | ||
path: src | ||
requirements: | ||
executable: | ||
- rustup | ||
about: | ||
license: MPL-2.0 |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel", "setuptools-rust"] | ||
build-backend = "setuptools.build_meta" |
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 |
---|---|---|
@@ -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, | ||
) |
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 |
---|---|---|
@@ -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(()) | ||
} |
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 |
---|---|---|
@@ -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) | ||
|
This file was deleted.
Oops, something went wrong.