Skip to content

Add z/OS (s390x-ibm-zos) cross-compilation support - #6314

Open
IgorTodorovskiIBM wants to merge 1 commit into
PyO3:mainfrom
IgorTodorovskiIBM:itodorov/zos-support
Open

Add z/OS (s390x-ibm-zos) cross-compilation support#6314
IgorTodorovskiIBM wants to merge 1 commit into
PyO3:mainfrom
IgorTodorovskiIBM:itodorov/zos-support

Conversation

@IgorTodorovskiIBM

Copy link
Copy Markdown

Summary

Add z/OS (s390x-ibm-zos) support to pyo3-build-config.

z/OS (IBM Z Operating System) is supported by the Rust compiler as the s390x-ibm-zos target. IBM Open Enterprise Python provides Python 3.11/3.12 on z/OS, and pyo3-based extension modules need two build-system fixes to work:

Changes

pyo3-build-config/src/impl_.rs — add OperatingSystem::Zos to is_linking_libpython_for_target()

z/OS uses XPLINK (cross-language platform linkage) for shared libraries. Extension modules (.so files / cdylib crates) must link libpython3.x explicitly, for the same reason AIX does (#4068).

pyo3-build-config/src/lib.rs — skip -Wl,-rpath for z/OS in print_libpython_rpath_link_args()

z/OS uses LIBPATH for runtime library discovery rather than ELF-style rpath. Emitting -Wl,-rpath for z/OS causes a linker error. The caller sets LIBPATH at runtime instead.

Cross-compilation

Cross-compilation from a Linux host is driven via PYO3_CONFIG_FILE:

implementation=CPython
version=3.11
shared=true
lib_name=python3.11
lib_dir=/usr/lpp/IBM/cyp/v3r11/pyz/lib
suppress_build_script_link_lines=false

Testing

Tested by cross-compiling pydantic-core and watchfiles for z/OS from a Linux LoP machine, with cargo check --target s390x-ibm-zos passing. Full link test pending z/OS server availability.

Note on target-lexicon

OperatingSystem::Zos is present in target-lexicon main but not yet in the 0.13.x release. This PR includes a Cargo.toml patch pointing to target-lexicon main; once target-lexicon cuts a release with Zos, the patch can be removed.

z/OS uses XPLINK linkage for shared libraries. Extension modules must
link libpython explicitly (same reason as AIX), and runtime library
discovery uses LIBPATH rather than ELF rpath.

Changes:
- is_linking_libpython_for_target: add OperatingSystem::Zos so that
  pyo3-based cdylib crates emit -lpython3.X when targeting z/OS
- print_libpython_rpath_link_args: skip -Wl,-rpath for z/OS; callers
  should set LIBPATH in the runtime environment instead

Cross-compilation is driven via PYO3_CONFIG_FILE pointing to a config
file generated from the target z/OS Python installation:

  implementation=CPython
  version=3.11
  shared=true
  lib_name=python3.11
  lib_dir=/usr/lpp/IBM/cyp/v3r11/pyz/lib
  suppress_build_script_link_lines=false

Tested against IBM Open Enterprise Python 3.11 on z/OS 3.1.
@alex

alex commented Aug 9, 2026

Copy link
Copy Markdown
Member

This seems reasonable, but we can't merge this until there's a target-lexicon release.

@davidhewitt davidhewitt left a comment

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.

Thanks, please add newsfragments/6314.fixed.md with something like "fix linkage on z/OS" as the content.

We will have to wait until target-lexicon release before merging here as the patch only applies locally not downstream; at that time we can revert the patch, bump the dependency and move forward 👍

Comment thread Cargo.toml
[patch.crates-io]
# target-lexicon 0.13.5 does not yet include OperatingSystem::Zos;
# use the main branch until the next release.
target-lexicon = { git = "https://github.com/bytecodealliance/target-lexicon", branch = "main" }

This comment was marked as outdated.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants