Skip to content

cross and native build of python for mingw* hosts #48121

Closed

Description

@rpetrov
mannequin
BPO 3871
Nosy @birkenfeld, @doko42, @amauryfa, @giampaolo, @tarekziade, @merwok, @mingwandroid
Dependencies
  • bpo-3754: cross-compilation support for python build
  • Files
  • py3k_mingwmsys_2_autogen.diff: Building Python with MinGW/MSys v2 (correct)
  • python-py3k-20110520-MINGW.patch
  • python-py3k-20110825-MINGW.patch
  • python-py3k-20120318-MINGW.patch
  • python-py3k-20120318-MINGW-330a2.patch: Patch updated to build against 3.3.0a2
  • python-py3k-20120318-MINGW-FIXES-USE-POSIX-GETPATH-330a2.patch: Fixes for MinGW cross and beginnings of Darwin cross.
  • python-py3k-20120607-MINGW.patch: version for 3.3.0a4
  • python-py3k-20120729-MINGW.patch
  • py3k-20121004-MINGW.patch: extract from repository dated 2012-10-04
  • py3k-20121227-MINGW.patch
  • py3k-20130110-MINGW.patch
  • 0003-MINGW-implement-exec-prefix-i.e.-use-content-of-pybu.patch: MINGW-implement exec prefix, i.e. use content of pybuilddir.txt
  • 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/tarekziade'
    closed_at = <Date 2013-02-06.13:24:26.689>
    created_at = <Date 2008-09-14.23:08:18.683>
    labels = ['type-feature', 'build']
    title = 'cross and native build of python for mingw* hosts'
    updated_at = <Date 2013-10-13.11:15:44.257>
    user = 'https://bugs.python.org/rpetrov'

    bugs.python.org fields:

    activity = <Date 2013-10-13.11:15:44.257>
    actor = 'rpetrov'
    assignee = 'tarek'
    closed = True
    closed_date = <Date 2013-02-06.13:24:26.689>
    closer = 'doko'
    components = ['Cross-Build']
    creation = <Date 2008-09-14.23:08:18.683>
    creator = 'rpetrov'
    dependencies = ['3754']
    files = ['18437', '22037', '23035', '24924', '25761', '25765', '25851', '26572', '27474', '28471', '28701', '28857']
    hgrepos = []
    issue_num = 3871
    keywords = ['patch', 'needs review']
    message_count = 108.0
    messages = ['73239', '73241', '73699', '74090', '76699', '77243', '77246', '77259', '79959', '80019', '80028', '80037', '80347', '80349', '80970', '80997', '81170', '82114', '90819', '98224', '100073', '101008', '101011', '101059', '105860', '107899', '108229', '108745', '110686', '112608', '113214', '113218', '113236', '113263', '113265', '113274', '114777', '114780', '115856', '115863', '121078', '121086', '121087', '121091', '121094', '121095', '121097', '121099', '121133', '121134', '121144', '121242', '121244', '121245', '121246', '121247', '121251', '127144', '128271', '133253', '136339', '136382', '142931', '142973', '142989', '143150', '161973', '161976', '161977', '162422', '162423', '162424', '162465', '164399', '164413', '164415', '164419', '164421', '164448', '164449', '164451', '164453', '164473', '164477', '166741', '172301', '177467', '177533', '178433', '178471', '178631', '179732', '179734', '180595', '180662', '180694', '180695', '180703', '180704', '180705', '180707', '180708', '180742', '181182', '181185', '181518', '181519', '199695']
    nosy_count = 20.0
    nosy_names = ['georg.brandl', 'doko', 'lkcl', 'amaury.forgeotdarc', 'davidfraser', 'giampaolo.rodola', 'schmir', 'scott.tsai', 'tarek', 'eric.araujo', 'rpetrov', 'rschoon.old', 'WhiteTiger', 'BreamoreBoy', 'LRN', 'alesko', 'tshepang', 'kalev', 'Ray.Donnelly', 'jhuntley']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue3871'
    versions = ['Python 3.4']

    Activity

    1. rpetrov commented on Sep 14, 2008

      rpetrovmannequin
      MannequinAuthor

      This is a completely new patch against trunk that try to resolve mingw32
      build. The first version to show problems with current python builds
      system, to propose solutions/work-arounds and to be stating point for
      discussion. Also I prefer some issues to be resolved later when we agree
      on the basic issues.

      The patch is tested in cross-compilation environment and native build
      has to be tested too. Also the patch show how to use cross-compilation
      environment and require patch posted in
      bpo-3754 ("minimal cross-compilation support for configure") to be
      applied first.

      The new patch share many commons with bpo-841454 "Cross building
      python for mingw32" posted by Andreas Ames, on 2003-11-13), but build
      process use distutils instead scons.
      Also some mingw related changes from bpo-1597850 ("Cross compiling
      patches for MINGW" - Han-Wen Nienhuys, from 2006-11-16) are shared too,
      but we differ in concept how to use cross-compilation environment.
      The correct way is to use $host variable (see bpo-3754).

      Also my patch use python installed on build system along with some hacks
      to overcome distutils limitations.

      The main issue "how to select correct compiler" in cross-compilation
      environment isn't resolved at all. The patch is tested with installed
      python version 2.4.
      Usually the cross-compiler is installed in same directories as native
      compiler but tools are prefixed by <CPU>-<VENDOR>- (see meanign of "host
      triplet"). In this environment we can't cross-compile even if we select
      mingw as compiler in arguments for "setup.py":
      The method get_versions() from cygwinccompiler.py call find_executable
      for to find gcc, ld, dllwrap but on build system they point to native
      compiler and that aren't prefixed. Also the expression "result =
      re.search('(\d+\.\d+(\.\d+)*)',out_string)" return as example
      '2.17.50.0.6' and later StrictVersion fail since value is not in format
      N.N{.N{A{N}}}. If we replace '*' with '?" in regular expression we will
      get correct result, but this isn't right solution.
      So the question is 'how to pass compiler to distutils' (as example for
      python 2.4) remain open.

      Work-around: install mingw cross-suite in own directory (MINGW_ROOT) and
      prepend PATH environment variable with both paths:

      • $MINGW_ROOT/bin
      • $MINGW_ROOT/<MINGW_HOST>/bin where <MINGW_HOST> is something like
        i586-pc-mingw32 (depend from you host selected when you build suite).
        In this case find_executable will find mingw ld and since -v option
        return something like "GNU ld version 2.17.50 20060824", regular
        expresion value that make StrictVersion happy.

      Note that in both environment configure script find compiler tools
      prefixed as example by "i586-pc-mingw32-".
      My mingw is build for host "i386-mingw32msvc"(this isn't correct, but is
      acceptable for host. For next version I plan to use for build the
      correct one, i.e i386-pc-mingw32). So in the final Makefile I see:
      CC= i386-mingw32msvc-gcc
      AR= i386-mingw32msvc-ar
      RANLIB= i386-mingw32msvc-ranlib

      Also setup.py set compiler attribute linker_so - for details see
      comments in the patch.

      Another point is to link installed python in top-build directory so that
      on posix system distutils read variables from our makefile instead from
      installed in build system. In this case python_build (an internal to
      distutils flag) is set.

      A, but not common, build issue is that some python 2.4 versions will
      search for pyconfig-32.h instead pyconfig.h.
      Symptoms:
      =======================================
      ....
      running build
      running build_ext
      error: ./pyconfig-32.h: No such file or directory
      ....
      =======================================
      I see this on cent-os (5.0?), but I can't see on slackware 11.0.
      This patch don't address this.
      Just go in top-build directory and create a link, i.e. "ln -s
      ./pyconfig.h pyconfig-32.h".

      If you system support emulation after build you may run python.
      The build python search for modules. After patch modules are with suffix
      same as for native build - .pyd. You may thin them to the top-build
      directory or to follow binary distribution - create directory DLLs,
      enter into it and link pyd-files:
      $ for f in ../build/lib.*/*.pyd; do ln -sf $f; done

      Differences between mingw build python and binary distribution(native
      build):
      Mingw build follow posix rules and will create more modules than native
      build. In the native build they are part from main executable(buildin).
      This is the list:
      array, audioop, binascii, _bisect, _bytesio, cmath, _codecs_cn,
      _codecs_hk, _codecs_iso2022, _codecs_jp, _codecs_kr, _codecs_tw,
      _collections, cPickle, cStringIO, _csv, datetime, _fileio, _functools,
      future_builtins, _heapq, _hotshot, imageop, itertools, _json, _locale,
      _lsprof, math, mmap, msvcrt, _multibytecodec, operator, parser, _random,
      strop, _struct, _subprocess, time, _weakref, _winreg, zlib.
      I think that this inconsistency is problem of native build and for now I
      don't address it.

      Because in my environment I still don't have installed mingw port for
      some externals, build of following modules isn't tested:
      _bsddb.pyd
      _msi.pyd
      _sqlite3.pyd
      _tkinter.pyd

      Known issues:
      The float, math and other related tests fail(under emulation and on nt5.1).
      The reason is that C runtime function strtod() can't parse as example
      numbers with exponent lower than -308, can't parse inf, nan, etc.. The
      python source contain a file Python/strtod.c and my attempt to modify
      and use it didn't succeed.
      Also the configure lack test for "working" strtod and I guess that tests
      fail on posix systems without C99 support.
      The library mingwex from mingw runtime version 3.15 has working
      replacement for stdtod function.
      For now my patch will not address old strtod function.

      In mingw definition of some functions(as example getaddrinfo and
      getnameinfo) depend of value of WINVER. This issue is commented in the
      patch. If user define WINVER geater the 0x0500 to CPPFLAGS at configure
      time the build will use C-runtime function otherwise fake-function from
      getaddrinfo.c and getnameinfo.c. As is commented in the patch if program
      is linked with C-runtime functions I expect to fail to run on w2k.
      I prefer to left selection of C-runtime for future mingw patches.

      The other issue is that I see failure for some tests that use sockets.
      This problem isn't investigated yet.

      We may group some changes in configure but this require to reorder some
      commands as example '--with-pydebug'. Since this isn't mingw issue I
      prefer don't change current order. Another example is LIBM - it is set
      by configure but setup.py use own rule.

    2. added
      build
      type-feature
      on Sep 14, 2008
    3. rpetrov commented on Sep 14, 2008

      rpetrovmannequin
      MannequinAuthor

      P.S.: this patch cover changes in the python C-code proposed in issue
      1412448 as include only necessary modifications.

    4. rpetrov commented on Sep 24, 2008

      rpetrovmannequin
      MannequinAuthor

      For the protocol: bpo-2445 impact proposed patch.
      Also I finish the tests and I will upload soon new patch - I the current
      patch ( rpetrov, 2008-09-15 02:08) "Modules/selectmodule.c" isn't
      ported and this prevent socked and related modules to work.
      Also I understand the one of the reasons python 2.6x to be linked with
      msvcr90 - many of bugs related to math functions are fixed in this
      version of runtime.

    5. rpetrov commented on Sep 30, 2008

      rpetrovmannequin
      MannequinAuthor

      note: updated patch contain unsynchronized with trunk code in
      ./Objects/fileobject.c (after /* EINVAL is returned when an invalid
      filename or ... )

    6. zooko commented on Dec 1, 2008

      zookomannequin
      Mannequin

      I'm interested in this patch so I'm adding myself to the Nosy list.

    7. rpetrov commented on Dec 7, 2008

      rpetrovmannequin
      MannequinAuthor

      The new patch is attached. Now the patch allow native build for mingw*
      host OS. The build id tested in MSYS environment. The issue title is
      updated to reflect this.
      The main changes:

      • native build require four more build-in modules (_functools, operator
        ,_locale, _winreg) otherwise setup.py fail to load;
      • changes in distutils for python 2.6+. The previous patch work on
        python 2.4 run in cross environment;
      • don't build with libintl;
      • use long double functions ldexp() atan2() from mingwex library as
        replacement for buggy msvcrt implementation.

      The new patch don't include changes related to bpo-4288 (see also
      bpo-4279).

    8. changed the title [-]cross building python for mingw32 with distutils[/-] [+]cross and native build of python for mingw32 with distutils[/+] on Dec 7, 2008
    9. rpetrov commented on Dec 7, 2008

      rpetrovmannequin
      MannequinAuthor

      About the regression test results test.
      The result from 2008-11-29 is:
      306 tests OK.
      1 test failed:
      test_sundry
      54 tests skipped:
      ....
      Those skips are all expected on win32.

      To get those results you mingwex library has to contain fixes for two
      issues(see mingw32 bug tracker).

      • 2136252 (fixed in trunk): c99, printf and float zero precision;
      • 2117590 (pending): correction of function asinh - inverse hyperbolic
        sine. For the python regression tests copysign is enough.

      About "test_sundry" depend on _msi module. I don't plan to work on mingw
      build for _msi module. Note that mingw build is with OS system default
      msvcrt so there is no "Assembly Hell".

      The trunk from 2008-12-07 fail in addition on test_anydbm, test_bsddb
      and test_whichdb.
      No idea what is wrong. It seems to that break is related to updates. As
      example dbm module still fail to build on my linux.

    10. rpetrov commented on Dec 7, 2008

      rpetrovmannequin
      MannequinAuthor

      The changes related to bpo-4483 break build on dbm based on "Berkeley
      DB" so I update mingw patch to restore bulld to previous state.

      Now I expect test_anydbm, test_bsddb and test_whichdb to succeed as
      before one week.

    11. lkcl commented on Jan 16, 2009

      lkclmannequin
      Mannequin

      roumen, hi,
      i'm interested in collaborating with you to get python compiled
      under wine (running msys+mingw32 under wine, on linux).
      bpo-4954 incorporates much of your work, and takes a slightly
      different direction for the configure setup - the time taken to
      complete configure under wine is intolerable (3 hours).
      also i have found that by setting PATH=%PATH%;c:/mingw/bin in the
      environment vars, the python.exe that's produced can successfully
      be used to run setup.py build.

    12. rpetrov commented on Jan 17, 2009

      rpetrovmannequin
      MannequinAuthor

      Hi Luke,
      Initially I start build in cross environment. Later I setup a posix
      environment, based on msys and in the last patch is commented which
      module has to be build-in for native build.

      I'm not surprised that you succeed to build in emulated environment and
      I know that born shell work slow in this environment.

    13. lkcl commented on Jan 17, 2009

      lkclmannequin
      Mannequin

      roumen, hi,
      can you add:

         BASECFLAGS="-mthreads $BASECFLAGS"
         LDFLAGS="-mthreads $LDFLAGS"
      

      when compiling with threads, and... a second request: _block_ people
      from compiling without mthreads, because there's a bug in wine's
      msvcrt _filbuf routine where it doesn't perform CRLF (at all)
      and it should.

      http://bugs.winehq.org/show_bug.cgi?id=16970

    14. lkcl commented on Jan 17, 2009

      lkclmannequin
      Mannequin

      roumen, hi,
      can you add:

         BASECFLAGS="-mthreads $BASECFLAGS"
         LDFLAGS="-mthreads $LDFLAGS"
      

      when compiling with threads, and... a second request: _block_ people
      from compiling without mthreads, because there's a bug in wine's
      msvcrt _filbuf routine where it doesn't perform CRLF (at all)
      and it should.

      http://bugs.winehq.org/show_bug.cgi?id=16970

    15. 92 remaining items

    16. giampaolo commented on Jan 26, 2013

      @giampaolo
      Contributor

      This discussion got very long and it's not clear (to me at least) what the status of the patch is and whether it has been accepted for inclusion.
      Maybe it makes sense to bring this up to python-dev mailing list instead of keep stressing this thread?

    17. mingwandroid commented on Jan 26, 2013

      mingwandroidmannequin
      Mannequin

      Roumen, I think it would be really great if you could split py3k-20121004-MINGW.patch up into separate bits.

      The pthread stuff and libffi stuff being two obvious candidates for atomic parts.

    18. rpetrov commented on Jan 26, 2013

      rpetrovmannequin
      MannequinAuthor

      As patch 0005-CROSS-revert-issue13150-i.e.-python-solution-with-_s.patch (CROSS-revert bpo-13150, i.e. python solution with _sysconfigdata.py instead Makefile) from bpo-3754 is now obsolete by bpo-13547, 14774, 16342, 15298 it is save to switch sysconfigdata with proposed changes in PC/getpathp.c .

    19. lkcl commented on Jan 27, 2013

      lkclmannequin
      Mannequin

      the last time this was brought up on python-dev the opinions of the primary python developers was made very very clear: anything that is not written by them is treated with extreme hostile and predudicial contempt.

      what i mean by that is that the view of the primary python developers is that when they make decisions to decrease their workload, other people are *NOT* welcome to question those decisions. [i questioned their decisions; all bugreports were terminated with excuses without good technical justification, and when i questioned those, access to the bugtracker was terminated].

      roumen's work should have been encouraged and welcomed when it was first initiated - FIVE years ago.

      the best bet therefore is to go over the heads of the primary python developers and to approach the Python Software Foundation's Board of Directors. they are required to enact the PSF Charter in the best interests of the Python Programming Language. what the existing primary python developers can or cannot cope with is of secondary consequence for the Board.

      the main concern of the primary python developers was that they would be landed with yet another platform to support, and, as they are struggling to cope with the existing ones, they made - and make - absolutely any excuse that they can, regardless of actual merit, to ensure that no other platforms are added.

      roumen, my opinion is that you have demonstrated over the past five years that you are committed to ensuring that python gets mingw support, and that you yourself are the best person to become the maintainer of python-mingw. you are, already, de-facto, its maintainer.

      answering some other points:

      • python-mingw actually requires an entire new platform (built in to sys and os at a fundamental level). neither the platform rules for cygwin, nor the platform rules for gcc, *nor* the platform rules for win32 correctly apply. the MSVC platform rules should also be obviously understood to be useless. mingw uses gcc, but it is gcc for win32: it therefore falls through *all* the existing platforms and requires its own separate class in distutils.

      • the autoconf-generated pyconfig.h is so insanely slow to generate under mingw (any configure script running under MSYS is insanely slow) that it is virtually impossible to do any development. also, the hard-coded config header file for win32 is also useless: firstly mingw doesn't have all the features of win32 (the headers are reverse-engineered and so are incomplete). secondly, the hard-coded config header file for win32 has MSVC-specific details in it that make it useless.

      • distutils was frozen because several immature developers made improperly tested commits that caused massive disruption. rather than put in proper review procedures, the primary python developers decided to terminate all possibility of ever adding in a new platform - ever - and began distutils2. this situation has to be reversed. mingw *requires* that distutils have support for the mingw compiler. a way to achieve this is to add separate files into distutils (which cannot be questioned as to their effect on existing files in distutils, because they are separate and therefore have zero effect), and then, once those files have been added and accepted, create a *ONE* line patch to distutils which pulls in the new mingw distutils functionality. a one-line patch cannot really be argued with, esp. if it is only an "include".

      roumen and others: i recommend that you approach the Python Software Foundation and ask that this project be sponsored for 3 months and/or until it is completed and the patches are in.

    20. rpetrov commented on Feb 2, 2013

      rpetrovmannequin
      MannequinAuthor

      Please do not post to this thread.
      Follow python bugs list for result of patch-split. I will try to post parts of this patch to already opened issues or to open new one if necessary.

      As basis will be used py3k-20121004-MINGW.patch with following main changes:

      • prefer posix installation scheme
      • use of system libffi

      Lets keep issue open as reference until is reached usable level.

    21. added
      build
      and removed
      build
      on Feb 2, 2013
    22. mingwandroid commented on Feb 2, 2013

      mingwandroidmannequin
      Mannequin

      Great Roumen, please split into new issues then make a new overall tracking issue, then this one can be left for historians and archaeologists.

      For Posix installation scheme I've got:

      https://github.com/niXman/mingw-builds/blob/master/patches/Python-3.3.0/0050-mingw-sysconfig-like-posix.patch

      It needs some changes to allow for normal NT scheme when not using MinGW though.

      For system libffi there's:

      https://github.com/niXman/mingw-builds/blob/master/patches/Python-3.3.0/0035-mingw-system-libffi.patch

      When you make your new patches I will base a new set of patches on them.

    23. doko42 commented on Feb 6, 2013

      @doko42
      Member

      Ray Donnelly added the comment:
      Next time there's a release of Python 3, I'll rebase my patches against that.

      sorry, this is the wrong attitude, if you want mingw support to go upstream. fetch tip/trunk, re-apply your patches, and submit them.

    24. added
      build
      and removed
      build
      on Feb 6, 2013
    25. doko42 commented on Feb 6, 2013

      @doko42
      Member

      now closing/rejecting this issue. See
      http://mail.python.org/pipermail/python-dev/2013-January/123774.html
      for the discussion.

    26. rpetrov commented on Oct 13, 2013

      rpetrovmannequin
      MannequinAuthor

      For protocol - as requested patches attached to this issue are split ans posted as separate issues.

      Please follow those listed below:
      bpo-18654 - modernize mingw&cygwin compiler classes (new)
      bpo-17605 - mingw-meta: build interpreter core
      bpo-18653 - mingw-meta: build core modules
      bpo-19245 - mingw-meta: install (new)

      Test cases are not covered. Patches will be posted later, if above are resolved.

    27. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    buildtype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions