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

bpo-41100: Support macOS 11 and Apple Silicon #22855

Merged

Conversation

@ronaldoussoren
Copy link
Contributor

@ronaldoussoren ronaldoussoren commented Oct 21, 2020

This merges my other two PRs, and improves on the PR that implements support for older macOS versions.

  • Tests pass on macOS 11 (ARM64)
  • Tests pass on macOS 10.9 using 10.10 SDK
  • Add tests for the time module, similar to the tests added for the posix module
  • Build arm64/x86_64 binary ("universal2") and test on:
    • macOS 11 (arm64)
    • macOS 11 (x86_64)
    • macOS 10.15 (x86_64)
    • macOS 10.14 (x86_64)
    • macOS 10.12 (x86_64)
    • macOS 10.9 (x86_64)
  • _osx_support.py changes to strip "-arch arm64" (and possibly related arguments)
    on systems that don't support his.
  • Make sure CI passes on all platforms
  • Add tests for the changes in _osx_support and distutils
  • Write NEWS blurb

https://bugs.python.org/issue41100

We should consider just dropping support for macOS 10.4 here
to simplify the code.
This is support for ctypes on macOS/arm64 based
on PR 21249 by Lawrence D'Anna (Apple).

Changes:
- changed __builtin_available tests from 11.0 to 10.15
- added test to setup.py for ffi_closure_alloc and use
  that in malloc_closure.c
- Minor change in the code path for ffi_prep_closure_var
  (coding style change)
The preprocessor guard in the old version doesn't work, and
isn't really needed (10.4 only supported 32-bit code where
unsigned long is the same as uint32_t).
This also adds an option to stop building after compiling the
3th-party dependencies, as well as a script for archiving those
dependencies. This makes it easier to work on the build.

There are three changes to build-installer.py related to universal2
support:

1. Add 'universal2' information to build-installer.py;
2. Building OpenSSL for arm64 requires a patch at this time;
3. For some reason I had to patch the Tcl build to avoid a build error.
Needed because my previous workaround doesn't work anymore.

This uses a private API, that should be made public later...
- __builtin_available is not present in the compiler, fall
  back to the ancient way of testing if a symbol is usable.
- Logic error code in pytime.c resulted in a compile error.
…oren/cpython into macos11-deploy-earlier-branch
The tests are not entirely done yet, and something
similar needs to be done for the time module.
…on isn't present.

I don't particularly like the code duplication, but this code
should be pretty stable.
@ned-deily
Copy link
Member

@ned-deily ned-deily commented Nov 2, 2020

I used the current state of the PR to build and test some installer variants. Due to time constraints and my currently degraded test environment, I focused first on regressions with currently supported systems. The configurations tested were:

  1. installer built on 10.9 (the current standard python.org variant)
  2. installer built on 10.15 with a deployment target of 10.9 (to exercise the weak-linking code)

I tested the installer 1 on 11.0 developer preview 9. The only unexpected failure was of the modified test_ctypes:

test test_ctypes failed -- Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ctypes/test/test_macholib.py", line 51, in test_find
    self.assertIn(find_lib('pthread'),
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ctypes/test/test_macholib.py", line 43, in find_lib
    raise ValueError("%s not found" % (name,))
ValueError: pthread not found

This also failed when running installer 2 on the same 11.0 system.

I tested the installer 2 on 11.0 developer preview 9, 10.15, and 10.9. Other than the test_ctypes fallure mentioned above, there were no obvious regressions noted on 11.0, 10.15, or 10.9. I did not investigate in more detail whether the expected newer os.* functions and options were indeed available on 10.15 and not on 10.9, relying on the modified test suite to test that.

At this point, I would be comfortable saying that merging the PR as it stands should not cause regressions when building Python from source on 10.9 through 10.15 and when building the current python.org 10.9 variant. It should also allow single architecture builds from source on 11.0, assuming the test_ctypes failure is resolved. More testing is required for universal2 builds and more work is required for installer builds on 11.0 and on 10.15.

Copy link
Member

@ned-deily ned-deily left a comment

See comment in the discussion about current testing results.

@ronaldoussoren
Copy link
Contributor Author

@ronaldoussoren ronaldoussoren commented Nov 2, 2020

Great.

The test failure with installer 1 on macOS 11 is expected due to the shared library cache. It is possible to ignore that failure by detecting that we're on 11.0 (or later) and _dyld_shared_cache_contains_path is not available.

@ronaldoussoren
Copy link
Contributor Author

@ronaldoussoren ronaldoussoren commented Nov 5, 2020

FYI: My current plan is to merge next Saturday (Nov 7th), when I'll have time to react quickly to buildbot errors.

@ronaldoussoren
Copy link
Contributor Author

@ronaldoussoren ronaldoussoren commented Nov 7, 2020

I'm researching a crash that I get on a arm 11.0.1 rc1 when running test test suit (seems to be in the concurrent.future tests).

@ronaldoussoren
Copy link
Contributor Author

@ronaldoussoren ronaldoussoren commented Nov 7, 2020

I'm researching a crash that I get on a arm 11.0.1 rc1 when running test test suit (seems to be in the concurrent.future tests).

I noticed this crash because I got popups from the system, even though test test suite itself does not report test failures. This was with an installed framework install, I don't get these pop ups with a unix install.

These crashes are likely related to tests using the _crash function in test_concurrent_futures. This is not related to this PR and as such can be investigated more full later.

@ronaldoussoren ronaldoussoren merged commit 4176193 into python:master Nov 8, 2020
8 of 10 checks passed
8 of 10 checks passed
Docs
Details
Check for source changes
Details
Windows (x86)
Details
Windows (x64)
Details
macOS
Details
Ubuntu
Details
Azure Pipelines PR #20201101.25 failed
Details
Travis CI - Pull Request Build Failed
Details
bedevere/issue-number Issue number 41100 found
Details
bedevere/news News entry found in Misc/NEWS.d
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 8, 2020

Thanks @ronaldoussoren for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒🤖 I'm not a witch! I'm not a witch!

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 8, 2020

Sorry, @ronaldoussoren, I could not cleanly backport this to 3.9 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 41761933c1c30bb6003b65eef1ba23a83db4eae4 3.9

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 8, 2020

Thanks @ronaldoussoren for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒🤖

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 8, 2020

Sorry @ronaldoussoren, I had trouble checking out the 3.9 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 41761933c1c30bb6003b65eef1ba23a83db4eae4 3.9

@jibaku jibaku mentioned this pull request Nov 11, 2020
sjmulder added a commit to sjmulder/cpython that referenced this pull request Nov 11, 2020
Co-authored-by:  Lawrence D’Anna <lawrence_danna@apple.com>

* Add support for macOS 11 and Apple Silicon (aka arm64)

  As a side effect of this work use the system copy of libffi on macOS, and remove the vendored copy

* Support building on recent versions of macOS while deploying to older versions

  This allows building installers on macOS 11 while still supporting macOS 10.9.
sjmulder added a commit to sjmulder/cpython that referenced this pull request Nov 11, 2020
Backport of commit 4176193 to 3.9:
___

Co-authored-by:  Lawrence D’Anna <lawrence_danna@apple.com>

* Add support for macOS 11 and Apple Silicon (aka arm64)

  As a side effect of this work use the system copy of libffi on macOS,
  and remove the vendored copy

* Support building on recent versions of macOS while deploying to older
  versions

  This allows building installers on macOS 11 while still supporting
  macOS 10.9.
sjmulder added a commit to sjmulder/cpython that referenced this pull request Nov 12, 2020
Backport of commit 4176193 to 3.9:
___

Co-authored-by:  Lawrence D’Anna <lawrence_danna@apple.com>

* Add support for macOS 11 and Apple Silicon (aka arm64)

  As a side effect of this work use the system copy of libffi on macOS,
  and remove the vendored copy

* Support building on recent versions of macOS while deploying to older
  versions

  This allows building installers on macOS 11 while still supporting
  macOS 10.9.
sjmulder added a commit to sjmulder/cpython that referenced this pull request Nov 12, 2020
Backport of commit 4176193 to 3.9:
___

Co-authored-by:  Lawrence D’Anna <lawrence_danna@apple.com>

* Add support for macOS 11 and Apple Silicon (aka arm64)

  As a side effect of this work use the system copy of libffi on macOS,
  and remove the vendored copy

* Support building on recent versions of macOS while deploying to older
  versions

  This allows building installers on macOS 11 while still supporting
  macOS 10.9.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Nov 12, 2020
(Apple Silicon being their aarch64 platform.)

Patches consist of:
 - Upstream work: python/cpython#22855
 - Fix for setup.py to find libbz2.tbd and libz.tbd now that with the
   shared library cache there's nothing in /usr/lib.
   See: https://bugs.python.org/issue41116
 - Addition of __arch64__ case to fix _decimal module. A very similar fix
   has since been committed upstream.
@maxbelanger
Copy link
Contributor

@maxbelanger maxbelanger commented Nov 12, 2020

Is the plan still to backport this (or a part of this) to Python 3.8? We are not yet planning to migrate to Python 3.9 and the ability to build for Apple Silicon being merged thus available downlevel would be helpful (I also wouldn't expect any guarantee of support, I'm thinking of this as a "you can build for this configuration but you're on your own" situation).

@dimaqq
Copy link
Contributor

@dimaqq dimaqq commented Nov 13, 2020

@maxbelanger, sorry being out of the loop, though I hope this clarification may be useful to others who land on this ticket.
Who is "we" in your case?

@maxbelanger
Copy link
Contributor

@maxbelanger maxbelanger commented Nov 13, 2020

@dimaqq sorry, that wasn't clear. I was referring to Dropbox; we ship Python as part of our client application on macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

You can’t perform that action at this time.