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

Fix installation on Apple silicon Macs #59809

Closed
wants to merge 11 commits into from

Conversation

hl-tam
Copy link
Contributor

@hl-tam hl-tam commented Mar 15, 2021

What does this PR do?

This PR addresses two issues that blocks Salt from being installed on Apple silicon and a third issue that causes salt to crash on launch.

The first two issues are fixed by updating the version pins for pyobjc and cffi. The crash is fixed by having Salt use the HOMEBREW_PREFIX environment variable instead of assuming that brew always installs to /usr/local (the default on Apple silicon Macs is /opt/homebrew and it's configurable on all platforms).

What issues does this PR fix or reference?

Fixes: #59808

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

I don't think docs or tests are applicable to this PR. I'm not sure if this counts as a notable change for the change log.

Commits signed with GPG?

No

hl-tam added 3 commits March 15, 2021 12:29
Salt fails to install on macOS Big Sur because of this `pyobjc` issue:
    ronaldoussoren/pyobjc#333
On an Apple M1 Mac, `cffi` (required by `cryptography`) won't install due to

    https://foss.heptapod.net/pypy/cffi/-/issues/479

This is fixed in 1.14.4. A similar change was made to Windows dependencies in

    saltstack#59479

This change was tested on an M1 Mac running macOS 11.2.1 against both the
built-in Python 3.8.2 as well as Python 3.9.2 from Homebrew.
When loading `libcrypto`, Salt checks for a Homebrew installation of `openssl`
at Homebrew's default prefix of `/usr/local`. However, on Apple Silicon Macs,
Homebrew's default installation prefix is `/opt/homebrew`. On all platforms,
the prefix is configurable.  If Salt doesn't find one of those `libcrypto`s,
it will fall back on the un-versioned `/usr/lib/libcrypto.dylib`, which will
cause the following crash:

    Application Specific Information:
    /usr/lib/libcrypto.dylib
    abort() called
    Invalid dylib load. Clients should not load the unversioned libcrypto dylib as it does not have a stable ABI.

This commit checks $HOMEBREW_PREFIX instead of hard-coding `/usr/local`.
@hl-tam hl-tam requested a review from a team as a code owner March 15, 2021 20:13
@hl-tam hl-tam requested review from garethgreenaway and removed request for a team March 15, 2021 20:13
@welcome
Copy link

welcome bot commented Mar 15, 2021

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@sagetherage sagetherage requested a review from weswhet March 16, 2021 17:15
@sagetherage sagetherage added MacOS pertains to the OS of fruit Big-Sur Bug broken, incorrect, or confusing behavior Needs-Testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases labels Mar 16, 2021
salt/utils/rsax931.py Outdated Show resolved Hide resolved
if fnmatch.fnmatch(lib_path, i):
passed = True
break
self.assertTrue(passed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: this test looks like it's simply re-implementing the code it's supposed to be testing. That's not very meaningful.

It would be more meaningful to do something like:

def test_when_homebrew_prefix_is_set_on_mac_lib_crypto_should_use_that_path():
    expected_lib_path = "/some/path/to/opt/openssl/lib/libcrypto.dylib"
    # patch getenv to return '/some/path/to'. Also probably need to patch glob
    lib_path = _find_libcrypto()
    assert lib_path == expected_lib_path

I would write a couple of tests - at minimum to cover the two scenarios that add BREW_PREFIX.

It's also preferred to add tests to tests/pytests/. If you need help, you can attend one of the Test Clinics on Twitch and we'll help you get pointed in the right direction.

@Ch3LL
Copy link
Contributor

Ch3LL commented Mar 17, 2021

@hl-tam I ported some of the changes from this PR to here: #59828 so it can be included in the Aluminium release. We are hesitant in including the updated versions of the libraries in Aluminium since we are so close to releasing and this has caused us issues in the past when we update libraries right before a release without giving it enough time for testing. We will keep your changes to update the libraries here in master so it can be included in the next release Silicone, but will not make it into Aluminium. Thanks for the PR!

@twangboy
Copy link
Contributor

Has anyone tried actually building the packages with these changes....? Sometimes the dependencies can be a little tricky.

@twangboy twangboy self-assigned this Mar 17, 2021
hl-tam added 3 commits March 17, 2021 12:23
Right now, if `_find_libcrypto` can't find any externally-managed versions of
libcrypto, it will fall back on the pre-Catalina un-versioned system libcrypto.
This does not exist on Big Sur and it would be better to raise an exception
here rather than crashing later when trying to open it.
This commit simplifies the unit tests for _find_libcrypto by mocking out the
host's filesystem and testing the common libcrypto installations (brew, ports,
etc.) on Big Sur. It simplifies the tests for falling back on system versions
of libcrypto on previous versions of macOS.
@hl-tam
Copy link
Contributor Author

hl-tam commented Mar 18, 2021

I've added change log entry and rewrote the tests for _find_libcrypto on different macOS versions to run without relying on the underlying host filesystem. I didn't move them to pytests since all the other tests for the function are in this file and I don't know enough about the other OS code paths to feel comfortable porting the whole test_rsax931.py file over to the new test architecture.

@hl-tam hl-tam requested review from waynew and Ch3LL March 18, 2021 21:59
Copy link
Contributor

@Ch3LL Ch3LL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a minor request

@patch.object(platform, "mac_ver", lambda: ("10.14.2", (), ""))
@patch.object(glob, "glob", lambda _: [])
def test_find_libcrypto_with_system_and_not_catalina(self):
def test_find_libcrypto_with_system_before_catalina(self):
"""
Test _find_libcrypto on a Catalina-like macOS host, simulate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the comment to reflect this tests before catalina and not on a catalina macos host.

@Ch3LL
Copy link
Contributor

Ch3LL commented Mar 19, 2021

Also it looks like the tests are failing on windows.

@hl-tam
Copy link
Contributor Author

hl-tam commented Mar 19, 2021

Also it looks like the tests are failing on windows.

Ah, I see the issue: sys.platform isn't mocked.

@Ch3LL
Copy link
Contributor

Ch3LL commented Mar 22, 2021

I fixed those tests on the freeze branch PR here: 0dd310d

I can push that unless you had an idea for a different fix?

@hl-tam
Copy link
Contributor Author

hl-tam commented Mar 22, 2021

I can push that unless you had an idea for a different fix?

That's exactly what I was thinking, just didn't get around to it. Thanks!

@Ch3LL
Copy link
Contributor

Ch3LL commented Mar 23, 2021

@twangboy are you good with this PR?

@cdalvaro cdalvaro mentioned this pull request Mar 27, 2021
5 tasks
@Ch3LL
Copy link
Contributor

Ch3LL commented Apr 28, 2021

ping @hl-tam looks like there is a merge conflict, most likely caused by this #60026

I'm guessing the only remaining change would be the cffi upgrade on your end?

@hl-tam
Copy link
Contributor Author

hl-tam commented Aug 30, 2021

@Ch3LL sorry I missed this. With pyobjc upgraded by another PR, that still leaves CFFI as well as the Homebrew environment changes for Apple Silicon.

@hl-tam
Copy link
Contributor Author

hl-tam commented Aug 30, 2021

Oh, never mind, I see that the Homebrew changes and associated tests have already been upstreamed. Installation works for me without issue on top of tree. Thanks for grabbing all of this!

@hl-tam hl-tam closed this Aug 30, 2021
@hl-tam hl-tam deleted the bigsur-arm-install branch August 30, 2021 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Big-Sur Bug broken, incorrect, or confusing behavior MacOS pertains to the OS of fruit Needs-Testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Can't install Salt on Apple Silicon Mac
6 participants