Skip to content

Proposal: Build system refactor #23

@emmatyping

Description

@emmatyping

This issue is to track a refactor of how we build Rust code, which will also impact how the makefile builds C code:

Static build

The static build for now must build a single static library, to avoid UB from conflicting symbols. To do this I think we can add a cpython-static crate which pulls in all of the other Rust crates which implement each module. So the dependency graph will look like:

cpython-static (becomes libcpython-static.a, which is linked into libpythonX.Y.a)
--> base64
    --> cpython-sys
--> zlib
    --> cpython-sys

cpython-static might need to re-export the initializers from the other Rust modules.

Shared build

Ideally, we'd like to build our own shared libraries directly, so that Rust builds and links _base64.so.

This will require some changes to how the C build works. Today, the configure script sets BLDSHARED to the command prefix to use in extension module linking: https://github.com/python/cpython/blob/5a452793203b47c63f6e849d869fbc3ff843add2/Modules/makesetup#L280

Some platforms set custom linker binaries and custom link flags that we'd like to not have to duplicate in Rust. It'd be nice if we could pass the existing defined link-time arguments to the linker for Rust libraries, and modify the linker executable when necessary (e.g. maybe on AIX?). To do that, we need to split BLDSHARED into the linker program and the arguments to the linker.

Once we have the link arguments we can set CARGO_TARGET_<triple>_LINKER to the linker binary and pass the arguments themselves via cargo:rustc-link-arg.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions