Skip to content

internal: [codex] try fix mingw libname#6164

Open
chirizxc wants to merge 18 commits into
PyO3:mainfrom
chirizxc:fix-mingw-libname
Open

internal: [codex] try fix mingw libname#6164
chirizxc wants to merge 18 commits into
PyO3:mainfrom
chirizxc:fix-mingw-libname

Conversation

@chirizxc

Copy link
Copy Markdown
Contributor

No description provided.

ognevny and others added 2 commits June 26, 2026 10:13
usually mingw version of python are shipped with `lib` prefix, so we need to add it for proper
linking
@chirizxc

Copy link
Copy Markdown
Contributor Author

@ognevny can you try in this Git branch?

@chirizxc chirizxc changed the title [codex] try fix mingw libname internal: [codex] try fix mingw libname Jun 26, 2026
@ognevny

ognevny commented Jun 26, 2026

Copy link
Copy Markdown

IIUC you just let the agent fix the things? I'll try to cherry-pick some good changes if I find them

@chirizxc

Copy link
Copy Markdown
Contributor Author

IIUC you just let the agent fix the things?

yes

@ognevny

ognevny commented Jun 26, 2026

Copy link
Copy Markdown

this time ai was smarter than me. I just forgot about dot separating major and minor version! that could be an issue...

@ognevny

ognevny commented Jun 26, 2026

Copy link
Copy Markdown

@chirizxc

Copy link
Copy Markdown
Contributor Author

maybe this?

@chirizxc

Copy link
Copy Markdown
Contributor Author

сodex went a bit overboard, but I hope it will help clarify the problem itself

Comment thread pyo3-ffi/build.rs Outdated
@ognevny

ognevny commented Jun 26, 2026

Copy link
Copy Markdown

it worked!

/ucrt64/lib/python3.14/site-packages/cryptography/hazmat/bindings/_rust.pyd:
  	libpython3.dll => D:\M\msys64\ucrt64\bin\libpython3.dll (0x00000211316c0000)
  	libcrypto-3-x64.dll => D:\M\msys64\ucrt64\bin\libcrypto-3-x64.dll (0x0000021132040000)
  	libssl-3-x64.dll => D:\M\msys64\ucrt64\bin\libssl-3-x64.dll (0x00000211316c0000)

but the latest change seem to be a workaround... anyway I'll give up with my branch

@chirizxc

Copy link
Copy Markdown
Contributor Author

it worked!

/ucrt64/lib/python3.14/site-packages/cryptography/hazmat/bindings/_rust.pyd:
  	libpython3.dll => D:\M\msys64\ucrt64\bin\libpython3.dll (0x00000211316c0000)
  	libcrypto-3-x64.dll => D:\M\msys64\ucrt64\bin\libcrypto-3-x64.dll (0x0000021132040000)
  	libssl-3-x64.dll => D:\M\msys64\ucrt64\bin\libssl-3-x64.dll (0x00000211316c0000)

but the latest change seem to be a workaround... anyway I'll give up with my branch

You can add fix to your branch; the main issue is that we need to test these builds in CI

Comment thread pyo3-build-config/src/lib.rs Outdated
@ognevny

ognevny commented Jun 26, 2026

Copy link
Copy Markdown

You can add fix to your branch; the main issue is that we need to test these builds in CI

I closed my PR. anyway my was different only in a kind of style, so I'll let maintainers review your change

Comment thread pyo3-ffi/src/impl_/macros.rs Outdated
Comment thread pyo3-build-config/src/lib.rs Outdated
Comment thread pyo3-ffi/src/impl_/macros.rs Outdated
@ognevny

ognevny commented Jun 26, 2026

Copy link
Copy Markdown

oh I didn't see you wrote comments on the same lines 😅

@chirizxc chirizxc closed this Jun 26, 2026
@chirizxc chirizxc reopened this Jun 26, 2026
Comment thread noxfile.py Outdated
@chirizxc

Copy link
Copy Markdown
Contributor Author

@ognevny сould you take another look? I'm not sure about some of comments, since I haven't worked with MINGW

Comment thread pyo3-ffi/build.rs Outdated
@ognevny

ognevny commented Jun 26, 2026

Copy link
Copy Markdown

fine with the comments, but you seem to duplicate them in one place

Comment thread pyo3-ffi/build.rs Outdated
@chirizxc chirizxc closed this Jun 26, 2026
@chirizxc chirizxc reopened this Jun 26, 2026
@chirizxc

Copy link
Copy Markdown
Contributor Author

I saw this PR, If anyone would like to help add MSYS2 to CI, please submit a PR to branch linked in this PR

Comment thread pyo3-ffi/build.rs Outdated
Comment on lines +228 to +230
// GNU-family Windows targets still need an import library for any non-Rust
// objects participating in the final link, such as CFFI-generated C code.
println!("cargo:rustc-link-lib={import_lib_name}");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there some test / CI evidence to this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I asked Codex to create a test in the test repository that checks whether this branch of code is present or not; it seems that MINGW32 doesn't work without it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So far, I've only found this:

@ognevny ognevny Jul 3, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

wait, but it didn't work for any arch, not only i686

oh I see that's different kind of workaround

@codspeed-hq

codspeed-hq Bot commented Jul 3, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 12.61%

❌ 1 regressed benchmark
✅ 139 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_empty_class_init 14.3 µs 16.4 µs -12.61%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing chirizxc:fix-mingw-libname (74b7f0d) with main (87dc97c)

Open in CodSpeed

Comment thread pyo3-ffi/build.rs
Ensure that the target Python library directory is \
in the rustc native library search path."
);
}

@chirizxc chirizxc Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe we could use target-lexicon as a build-dependency for pyo3-ffi as well; I think that would make the code a little more readable:

fn emit_link_config(build_config: &BuildConfig) -> Result<()> {
    let interpreter_config = &build_config.interpreter_config;
    let target = target_triple_from_env();

    let lib_name = interpreter_config
        .lib_name()
        .ok_or("attempted to link to Python shared library but config does not contain lib_name")?;

    if target.operating_system == target_lexicon::OperatingSystem::Windows {
        // Use raw-dylib linking: emit a cfg so that `extern_libpython!` picks the
        // right `#[link(name = "...", kind = "raw-dylib")]` attribute at compile time.
        // This eliminates the need for import libraries (.lib files) entirely.
        //
        // Note: raw-dylib is inherently dynamic linking. Static embedding of the
        // Python interpreter on Windows is not supported by this path (and is not
        // officially supported by CPython on Windows).
        println!("cargo:rustc-cfg=pyo3_dll=\"{lib_name}\"");
        let is_i686_pc_windows_gnu = target.environment == target_lexicon::Environment::Gnu
            && matches!(target.architecture, target_lexicon::Architecture::X86_32(_));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants