Skip to content

Commit 4366476

Browse files
committed
test: fix snapshot test of macro expansion to a specific OS
We have to specify a specific OS target because until PyO3 v0.22, PyO3 transitively depends on the [rust-ctor](https://crates.io/crates/ctor) crate, which generates different output on different OSes. Once we're doing *that*, we have to specify a specific Python ABI so that PyO3 doesn't get alarmed about cross-compilation. This is all a minor headache. One concern about this is that everyone testing locally has to run `rustup target add x864_64-unknown-linuxgnu`. CI doesn't, because I deliberately picked the triple that was running on CI, but any local development that isn't on that OS does. Is this worth it?
1 parent 098a5ec commit 4366476

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

tests/tests.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,28 @@ assert TestUnionEnum.new_unit().is_unit()
3939

4040
#[test]
4141
fn test_macro_expansion() {
42-
// To regenerate the snapshot, delete the generated
43-
// `tests/wrapper_tests/mod.expanded.rs` file and rerun the test.
44-
macrotest::expand("tests/wrapper_tests/mod.rs")
42+
// To regenerate the snapshot, run this test with the environment variable
43+
// `MACROTEST=overwrite`, or alternatively delete the generated
44+
// `tests/wrapper_tests/mod.expanded.rs` file and rerun this test.
45+
macrotest::expand_args(
46+
"tests/wrapper_tests/mod.rs",
47+
// We have to specify a specific OS target because until PyO3 v0.22,
48+
// PyO3 transitively depends on the
49+
// [rust-ctor](https://crates.io/crates/ctor) crate, which generates
50+
// different output on different OSes. Once we're doing *that*, we have
51+
// to specify a specific Python ABI so that PyO3 doesn't get alarmed
52+
// about cross-compilation. This is all a minor headache.
53+
//
54+
// In particular, this means that if you are running these tests on a
55+
// different OS, you will need to install the specified target. The
56+
// target is specifically chosen to be the one we use on CI, so CI does
57+
// not need an extra `rustup target add`, but some developers will.
58+
&[
59+
"--target",
60+
"x86_64-unknown-linux-gnu",
61+
"--no-default-features",
62+
"--features",
63+
"pyo3/abi3-py311",
64+
],
65+
)
4566
}

tests/wrapper_tests/mod.expanded.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,14 @@ pub mod python {
370370
::inventory::core::option::Option::None,
371371
),
372372
};
373+
#[link_section = ".text.startup"]
373374
unsafe extern "C" fn __ctor() {
374375
unsafe {
375376
::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY)
376377
}
377378
}
378379
#[used]
379-
#[link_section = "__DATA,__mod_init_func"]
380+
#[link_section = ".init_array"]
380381
static __CTOR: unsafe extern "C" fn() = __ctor;
381382
};
382383
#[doc(hidden)]
@@ -415,20 +416,18 @@ pub mod python {
415416
Inventory::new(_pyo3::impl_::pyclass::PyClassItems {
416417
methods: &[
417418
_pyo3::class::PyMethodDefType::Static(
418-
_pyo3::impl_::pymethods::PyMethodDef::fastcall_cfunction_with_keywords(
419+
_pyo3::impl_::pymethods::PyMethodDef::cfunction_with_keywords(
419420
"from_string\0",
420-
_pyo3::impl_::pymethods::PyCFunctionFastWithKeywords({
421+
_pyo3::impl_::pymethods::PyCFunctionWithKeywords({
421422
unsafe extern "C" fn trampoline(
422423
_slf: *mut _pyo3::ffi::PyObject,
423-
_args: *const *mut _pyo3::ffi::PyObject,
424-
_nargs: _pyo3::ffi::Py_ssize_t,
425-
_kwnames: *mut _pyo3::ffi::PyObject,
424+
_args: *mut _pyo3::ffi::PyObject,
425+
_kwargs: *mut _pyo3::ffi::PyObject,
426426
) -> *mut _pyo3::ffi::PyObject {
427-
_pyo3::impl_::trampoline::fastcall_with_keywords(
427+
_pyo3::impl_::trampoline::cfunction_with_keywords(
428428
_slf,
429429
_args,
430-
_nargs,
431-
_kwnames,
430+
_kwargs,
432431
PyTestUnionEnum::__pymethod_from_string__,
433432
)
434433
}
@@ -446,13 +445,14 @@ pub mod python {
446445
::inventory::core::option::Option::None,
447446
),
448447
};
448+
#[link_section = ".text.startup"]
449449
unsafe extern "C" fn __ctor() {
450450
unsafe {
451451
::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY)
452452
}
453453
}
454454
#[used]
455-
#[link_section = "__DATA,__mod_init_func"]
455+
#[link_section = ".init_array"]
456456
static __CTOR: unsafe extern "C" fn() = __ctor;
457457
};
458458
#[doc(hidden)]
@@ -461,9 +461,8 @@ pub mod python {
461461
unsafe fn __pymethod_from_string__<'py>(
462462
py: _pyo3::Python<'py>,
463463
_slf: *mut _pyo3::ffi::PyObject,
464-
_args: *const *mut _pyo3::ffi::PyObject,
465-
_nargs: _pyo3::ffi::Py_ssize_t,
466-
_kwnames: *mut _pyo3::ffi::PyObject,
464+
_args: *mut _pyo3::ffi::PyObject,
465+
_kwargs: *mut _pyo3::ffi::PyObject,
467466
) -> _pyo3::PyResult<*mut _pyo3::ffi::PyObject> {
468467
let function = PyTestUnionEnum::from_string;
469468
const DESCRIPTION: _pyo3::impl_::extract_argument::FunctionDescription = _pyo3::impl_::extract_argument::FunctionDescription {
@@ -478,10 +477,10 @@ pub mod python {
478477
};
479478
let mut output = [::std::option::Option::None; 1usize];
480479
let (_args, _kwargs) = DESCRIPTION
481-
.extract_arguments_fastcall::<
480+
.extract_arguments_tuple_dict::<
482481
_pyo3::impl_::extract_argument::NoVarargs,
483482
_pyo3::impl_::extract_argument::NoVarkeywords,
484-
>(py, _args, _nargs, _kwnames, &mut output)?;
483+
>(py, _args, _kwargs, &mut output)?;
485484
_pyo3::impl_::wrap::OkWrap::wrap(
486485
function(
487486
py,
@@ -745,13 +744,14 @@ pub mod python {
745744
::inventory::core::option::Option::None,
746745
),
747746
};
747+
#[link_section = ".text.startup"]
748748
unsafe extern "C" fn __ctor() {
749749
unsafe {
750750
::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY)
751751
}
752752
}
753753
#[used]
754-
#[link_section = "__DATA,__mod_init_func"]
754+
#[link_section = ".init_array"]
755755
static __CTOR: unsafe extern "C" fn() = __ctor;
756756
};
757757
#[doc(hidden)]
@@ -2175,13 +2175,14 @@ pub mod python {
21752175
::inventory::core::option::Option::None,
21762176
),
21772177
};
2178+
#[link_section = ".text.startup"]
21782179
unsafe extern "C" fn __ctor() {
21792180
unsafe {
21802181
::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY)
21812182
}
21822183
}
21832184
#[used]
2184-
#[link_section = "__DATA,__mod_init_func"]
2185+
#[link_section = ".init_array"]
21852186
static __CTOR: unsafe extern "C" fn() = __ctor;
21862187
};
21872188
#[doc(hidden)]
@@ -2338,13 +2339,14 @@ pub mod python {
23382339
::inventory::core::option::Option::None,
23392340
),
23402341
};
2342+
#[link_section = ".text.startup"]
23412343
unsafe extern "C" fn __ctor() {
23422344
unsafe {
23432345
::inventory::ErasedNode::submit(__INVENTORY.value, &__INVENTORY)
23442346
}
23452347
}
23462348
#[used]
2347-
#[link_section = "__DATA,__mod_init_func"]
2349+
#[link_section = ".init_array"]
23482350
static __CTOR: unsafe extern "C" fn() = __ctor;
23492351
};
23502352
#[doc(hidden)]

0 commit comments

Comments
 (0)