[MacOS] Cross compile stub when building for M1 on x86 (#54046)

Summary:
Also rename `CROSS_COMPILE_ARM` to `CROSS_COMPILE_ARM64`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/54046

Reviewed By: walterddr

Differential Revision: D27071928

Pulled By: malfet

fbshipit-source-id: 9143cd5d110ed67f0609f0a4bbb20922012ee665
This commit is contained in:
Nikita Shulga
2021-03-16 00:21:55 -07:00
committed by Facebook GitHub Bot
parent 2ecb2c7931
commit e8e570e9c5
4 changed files with 15 additions and 3 deletions

View File

@ -1326,7 +1326,7 @@ jobs:
command: |
set -e
export IN_CI=1
export CROSS_COMPILE_ARM=1
export CROSS_COMPILE_ARM64=1
# Install sccache
sudo curl --retry 3 https://s3.amazonaws.com/ossci-macos/sccache_v2.15 --output /usr/local/bin/sccache

View File

@ -125,7 +125,7 @@
command: |
set -e
export IN_CI=1
export CROSS_COMPILE_ARM=1
export CROSS_COMPILE_ARM64=1
# Install sccache
sudo curl --retry 3 https://s3.amazonaws.com/ossci-macos/sccache_v2.15 --output /usr/local/bin/sccache

View File

@ -26,7 +26,7 @@ if which sccache > /dev/null; then
export PATH="${WORKSPACE_DIR}:$PATH"
fi
if [ -z "${CROSS_COMPILE_ARM}" ]; then
if [ -z "${CROSS_COMPILE_ARM64}" ]; then
USE_DISTRIBUTED=1 python setup.py install
else
export MACOSX_DEPLOYMENT_TARGET=11.0

View File

@ -758,6 +758,18 @@ def configure_extension_build():
extra_compile_args += ['-g']
extra_link_args += ['-g']
# Cross-compile for M1
if IS_DARWIN:
macos_target_arch = os.getenv('CMAKE_OSX_ARCHITECTURES', '')
if macos_target_arch in ['arm64', 'x86_64']:
macos_sysroot_path = os.getenv('CMAKE_OSX_SYSROOT')
if macos_sysroot_path is None:
macos_sysroot_path = subprocess.check_output([
'xcrun', '--show-sdk-path', '--sdk', 'macosx'
]).decode('utf-8').strip()
extra_compile_args += ['-arch', macos_target_arch, '-isysroot', macos_sysroot_path]
extra_link_args += ['-arch', macos_target_arch]
def make_relative_rpath_args(path):
if IS_DARWIN: