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

Move _decimal build setup into configure #89956

Closed
tiran opened this issue Nov 13, 2021 · 8 comments
Closed

Move _decimal build setup into configure #89956

tiran opened this issue Nov 13, 2021 · 8 comments
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 Nov 13, 2021

BPO 45798
Nosy @mdickinson, @pitrou, @tiran, @ned-deily
PRs
  • bpo-45798: Move _decimal build setup into configure (GH-29541) #29541
  • bpo-45798: Let libmpdec decide which archs to build on macOS as done previously #29949
  • 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-07.02:43:44.501>
    created_at = <Date 2021-11-13.09:15:19.037>
    labels = ['type-feature', 'build', '3.11']
    title = 'Move _decimal build setup into configure'
    updated_at = <Date 2021-12-07.02:43:44.500>
    user = 'https://github.com/tiran'

    bugs.python.org fields:

    activity = <Date 2021-12-07.02:43:44.500>
    actor = 'ned.deily'
    assignee = 'christian.heimes'
    closed = True
    closed_date = <Date 2021-12-07.02:43:44.501>
    closer = 'ned.deily'
    components = ['Build']
    creation = <Date 2021-11-13.09:15:19.037>
    creator = 'christian.heimes'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45798
    keywords = ['patch']
    message_count = 8.0
    messages = ['406271', '406272', '406275', '406276', '406278', '407874', '407890', '407891']
    nosy_count = 4.0
    nosy_names = ['mark.dickinson', 'pitrou', 'christian.heimes', 'ned.deily']
    pr_nums = ['29541', '29949']
    priority = None
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue45798'
    versions = ['Python 3.11']

    @tiran
    Copy link
    Member Author

    tiran commented Nov 13, 2021

    Compiler and linker flags for _decimal and internal libmpdec are currently handled by a mix of configure checks and if/else chains in setup.py. The split makes it harder to build _decimal correctly from Modules/Setup. The Modules/Setup file also does not handle --with-system-mpdec.

    I have a working PR that moves all logic into configure.ac. The new system:

    • sets LIBMPDEC_CFLAGS and LIBMPDEC_LDFLAGS based on --with-system-libmpdec value.

    • detects libmpdec_machine by looking at ac_sys_system, MACOSX_DEFAULT_ARCH, ac_cv_sizeof_size_t, ac_cv_gcc_asm_for_x64, ac_cv_type___uint128_t, and ac_cv_gcc_asm_for_x87.

    • sets libmpdec compiler args based on libmpdec_machine, have_ipa_pure_const_bug, and have_glibc_memmove_bug.

    • if --with-system-libmpdec is not given, then our Makefile compiles libmpdec objects and puts them into a libmpdec.a archive.

    • finally it either links _decimal with our libmpdec.a or with system's libmpdec shared library.

    I went for libmpdec.a because it makes the logic for the internal path look similar to the logic with linking with an external shared library.

    Modules/Setup

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

    tiran commented Nov 13, 2021

    PS: I had to add an explicit make rule for each object file. "%.o: %c" templates are not portable.

    @tiran
    Copy link
    Member Author

    tiran commented Nov 13, 2021

    New changeset 0486570 by Christian Heimes in branch 'main':
    bpo-45798: Move _decimal build setup into configure (GH-29541)
    0486570

    @tiran
    Copy link
    Member Author

    tiran commented Nov 13, 2021

    Thanks for the quick review, Mark!

    @tiran
    Copy link
    Member Author

    tiran commented Nov 13, 2021

    I tested the --with-system-libmpdec successfully on my system. Most vendors are using the internal copy of libmpdec any way. AFAIK only Debian-based systems use their own system libmpdec.

    $ ./configure -C --with-system-libmpdec
    $ make
    ...
    building '_decimal' extension
    gcc -pthread -fPIC -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I./Include -I. -I/usr/local/include -I/home/heimes/dev/python/cpython/Include -I/home/heimes/dev/python/cpython -c /home/heimes/dev/python/cpython/Modules/_decimal/_decimal.c -o build/temp.linux-x86_64-3.11/home/heimes/dev/python/cpython/Modules/_decimal/_decimal.o -DCONFIG_64=1 -DASM=1
    gcc -pthread -shared build/temp.linux-x86_64-3.11/home/heimes/dev/python/cpython/Modules/_decimal/_decimal.o -L/usr/local/lib -o build/lib.linux-x86_64-3.11/_decimal.cpython-311-x86_64-linux-gnu.so -lmpdec
    ...
    $ ldd build/lib.linux-x86_64-3.11/_decimal.cpython-311-x86_64-linux-gnu.so 
            linux-vdso.so.1 (0x00007ffde21e1000)
            libmpdec.so.3 => /lib64/libmpdec.so.3 (0x00007f4f3b4cf000)
            libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4f3b4ae000)
            libc.so.6 => /lib64/libc.so.6 (0x00007f4f3b2df000)
            libm.so.6 => /lib64/libm.so.6 (0x00007f4f3b19b000)
            /lib64/ld-linux-x86-64.so.2 (0x00007f4f3b554000)

    @tiran tiran closed this as completed Nov 13, 2021
    @ned-deily
    Copy link
    Member

    It looks like this change broke macOS universal2 builds of libmpdec. I'm looking at it now but wanted to flag it as a "release blocker" for tagging 3.11.0a3.

    @ned-deily
    Copy link
    Member

    New changeset ddbab69 by Ned Deily in branch 'main':
    bpo-45798: Let libmpdec decide which archs to build on macOS as done previously. (GH-29949)
    ddbab69

    @ned-deily
    Copy link
    Member

    The issue here turned out to be that the architecture selection code for libmpdec builds on macOS had been scrambled a bit on the move from setup.py to configure. To support universal builds correctly, libmpdec has code to decide itself which arch(s) to build with on macOS. PR 29949 restores that behavior and macOS universal2 builds (builds which have both native arm64 and x86_64 binaries in each executable or library file) now work again for 3.11.

    @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