Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide pure-Python implementation of Programs/_freeze_module for cross building #90107

Closed
tiran opened this issue Dec 1, 2021 · 8 comments
Closed
Assignees
Labels
3.11 only security fixes build The build process and cross-build type-feature A feature request or enhancement

Comments

@tiran
Copy link
Member

tiran commented Dec 1, 2021

BPO 45949
Nosy @gvanrossum, @tiran, @ericsnowcurrently, @moreati
PRs
  • bpo-45949: Pure Python freeze module for cross builds (GH-29899) #29899
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/tiran'
    closed_at = <Date 2021-12-13.19:53:06.801>
    created_at = <Date 2021-12-01.15:34:28.428>
    labels = ['type-feature', 'build', '3.11']
    title = 'Provide pure-Python implementation of Programs/_freeze_module for cross building'
    updated_at = <Date 2021-12-13.20:32:52.812>
    user = 'https://github.com/tiran'

    bugs.python.org fields:

    activity = <Date 2021-12-13.20:32:52.812>
    actor = 'eric.snow'
    assignee = 'christian.heimes'
    closed = True
    closed_date = <Date 2021-12-13.19:53:06.801>
    closer = 'christian.heimes'
    components = ['Build', 'Cross-Build']
    creation = <Date 2021-12-01.15:34:28.428>
    creator = 'christian.heimes'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45949
    keywords = ['patch']
    message_count = 8.0
    messages = ['407459', '407465', '407466', '408134', '408315', '408477', '408478', '408481']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'christian.heimes', 'eric.snow', 'Alex.Willmer']
    pr_nums = ['29899']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue45949'
    versions = ['Python 3.11']

    @tiran
    Copy link
    Member Author

    tiran commented Dec 1, 2021

    As of today 3.11-dev requires Programs/_freeze_module to compile Python code to byte code. The dependency on an extra and special tool makes cross building more complicated. The _freeze_module is trivial and can be easily implemented in pure Python code. The re-introduction of _bootstrap_python helper would allow us to use a pure Python freeze_module for all modules except two importlib bootstrap modules. I have a proof of concept implementation that works for me.

    Proposal for standard builds:

    Proposal for cross builds:

    • use user-provider Python interpreter (./configure --with-build-python) to generate all Python/frozen_modules/*.h with new freezemodule.py tool.

    When cross building the user must already provide a Python interpreter with same version and bytecode version as the build target. Users would no longer need to provide a _freeze_module binary with ./configure --with-freeze-module.

    @tiran tiran added the 3.11 only security fixes label Dec 1, 2021
    @tiran tiran self-assigned this Dec 1, 2021
    @tiran tiran added build The build process and cross-build type-feature A feature request or enhancement 3.11 only security fixes labels Dec 1, 2021
    @tiran tiran self-assigned this Dec 1, 2021
    @tiran tiran added build The build process and cross-build type-feature A feature request or enhancement labels Dec 1, 2021
    @ericsnowcurrently
    Copy link
    Member

    IIRC, Programs/_freeze_module.c was originally a C implementation of the basic functionality in Tools/freeze/freeze.py.

    @ericsnowcurrently
    Copy link
    Member

    Ideally we would not have two scripts that do the same thing.

    @tiran
    Copy link
    Member Author

    tiran commented Dec 9, 2021

    Eric, could you review my PR, please? It simplifies cross building to other platforms.

    I took a look at Tools/freeze/freeze.py. The freeze tool creates different output than Program/_freeze_module.c.

    @tiran
    Copy link
    Member Author

    tiran commented Dec 11, 2021

    In his code review Eric made a point that the relationship of variables and their impact on normal and cross builds are not obvious. I'm going to introduce new variables for freezing and freezing dependencies. Bonus: Cross builds no longer build non-functional _bootstrap_python and Programs/_freeze_module.

    Normal build:

    PYTHON_FOR_FREEZE=./_bootstrap_python
    FREEZE_MODULE_BOOTSTRAP=./Programs/_freeze_module
    FREEZE_MODULE_BOOTSTRAP_DEPS=Programs/_freeze_module
    FREEZE_MODULE=$(PYTHON_FOR_FREEZE) $(srcdir)/Programs/_freeze_module.py
    FREEZE_MODULE_DEPS=_bootstrap_python $(srcdir)/Programs/_freeze_module.py

    Cross build:

    PYTHON_FOR_FREEZE=/path/to/build/python
    FREEZE_MODULE_BOOTSTRAP=$(PYTHON_FOR_FREEZE) $(srcdir)/Programs/_freeze_module.py
    FREEZE_MODULE_BOOTSTRAP_DEPS=$(srcdir)/Programs/_freeze_module.py
    FREEZE_MODULE=$(FREEZE_MODULE_BOOTSTRAP)
    FREEZE_MODULE_DEPS=$(FREEZE_MODULE_BOOTSTRAP_DEPS)

    @tiran
    Copy link
    Member Author

    tiran commented Dec 13, 2021

    New changeset eb483c4 by Christian Heimes in branch 'main':
    bpo-45949: Pure Python freeze module for cross builds (GH-29899)
    eb483c4

    @tiran
    Copy link
    Member Author

    tiran commented Dec 13, 2021

    Thanks for your review, Eric!

    @tiran tiran closed this as completed Dec 13, 2021
    @tiran tiran closed this as completed Dec 13, 2021
    @ericsnowcurrently
    Copy link
    Member

    You're welcome! Thanks for doing the work!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes build The build process and cross-build type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants