Repository: pytorch
Issue: NNAPI delegate library cannot be built on MacOS
Labels: module: build,triaged,module: macos

## 🐛 Bug

CMake cannot build the NNAPI delegate library on MacOS.
For now, an if was added around the NNAPI library to skip building on Mac.

## To Reproduce

Steps to reproduce the behavior:
1. Checkout https://github.com/pytorch/pytorch/pull/61878
2. Remove the if() here, which prevents the library from building on Mac https://github.com/pytorch/pytorch/commit/9c8029bde222fcbdd27b64f253d77ecfe60d91ab#diff-be66263b345a09046360dd9b72163a4674b436f135608f0b32b716c60d6bafc2R367
2. CI: When running CI tests, pytorch_macos_10_13_py3_build fails, among others
    Locally: Install Pytorch from source on a Mac (https://github.com/pytorch/pytorch#from-source) and build with cmake by running `python setup.py`

Error message:
```
Jul 20 18:28:45 [5991/6005] Linking CXX shared library lib/libnnapi_backend.dylib
Jul 20 18:28:45 FAILED: lib/libnnapi_backend.dylib 
Jul 20 18:28:45 : && /Users/distiller/workspace/clang++ -Wno-deprecated -fvisibility-inlines-hidden -Wno-deprecated-declarations -DUSE_PTHREADPOOL -Xpreprocessor -fopenmp -I/usr/local/include -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -Wno-invalid-partial-specialization -Wno-typedef-redefinition -Wno-unknown-warning-option -Wno-unused-private-field -Wno-inconsistent-missing-override -Wno-aligned-allocation-unavailable -Wno-c++14-extensions -Wno-constexpr-not-const -Wno-missing-braces -Qunused-arguments -fcolor-diagnostics -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-unused-private-field -Wno-missing-braces -Wno-c++14-extensions -Wno-constexpr-not-const -DHAVE_AVX_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3 -DNDEBUG -DNDEBUG -isysroot /Applications/Xcode-12.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.9 -dynamiclib -Wl,-headerpad_max_install_names -rdynamic -o lib/libnnapi_backend.dylib -install_name @rpath/libnnapi_backend.dylib caffe2/torch/CMakeFiles/nnapi_backend.dir/csrc/jit/backends/nnapi/nnapi_backend_lib.cpp.o caffe2/torch/CMakeFiles/nnapi_backend.dir/csrc/jit/backends/nnapi/nnapi_backend_preprocess.cpp.o  -Wl,-rpath,/Users/distiller/project/build/lib -Wl,-rpath,/Users/distiller/workspace/miniconda3/lib lib/libtorch_python.dylib lib/libshm.dylib lib/libtorch.dylib lib/libtorch_cpu.dylib lib/libprotobuf.a /Users/distiller/workspace/miniconda3/lib/libmkl_intel_lp64.dylib /Users/distiller/workspace/miniconda3/lib/libmkl_intel_thread.dylib /Users/distiller/workspace/miniconda3/lib/libmkl_core.dylib /Users/distiller/workspace/miniconda3/lib/libiomp5.dylib /usr/lib/libpthread.dylib /usr/lib/libm.dylib lib/libdnnl.a lib/libc10.dylib && :
Jul 20 18:28:45 ld: warning: dylib (/Users/distiller/workspace/miniconda3/lib/libmkl_intel_lp64.dylib) was built for newer macOS version (10.14) than being linked (10.9)
Jul 20 18:28:45 ld: warning: dylib (/Users/distiller/workspace/miniconda3/lib/libmkl_intel_thread.dylib) was built for newer macOS version (10.14) than being linked (10.9)
Jul 20 18:28:45 ld: warning: dylib (/Users/distiller/workspace/miniconda3/lib/libmkl_core.dylib) was built for newer macOS version (10.14) than being linked (10.9)
Jul 20 18:28:45 ld: warning: dylib (/Users/distiller/workspace/miniconda3/lib/libiomp5.dylib) was built for newer macOS version (10.11) than being linked (10.9)
Jul 20 18:28:45 Undefined symbols for architecture x86_64:
Jul 20 18:28:45   "_PyBaseObject_Type", referenced from:
Jul 20 18:28:45       pybind11::detail::make_object_base_type(_typeobject*) in nnapi_backend_preprocess.cpp.o
Jul 20 18:28:45   "_PyBytes_AsString", referenced from:
Jul 20 18:28:45       pybind11::detail::string_caster<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, false>::load(pybind11::handle, bool) in nnapi_backend_preprocess.cpp.o
Jul 20 18:28:45       bool pybind11::detail::string_caster<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, false>::load_bytes<char>(std::__1::enable_if<std::is_same<char, char>::value, pybind11::handle>::type) in nnapi_backend_preprocess.cpp.o
Jul 20 18:28:45   "_PyBytes_AsStringAndSize", referenced from:
Jul 20 18:28:45       pybind11::str::operator std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >() const in nnapi_backend_preprocess.cpp.o
...
```

## Expected behavior
CMake runs successfully without errors related to `lib/libnnapi_backend.dylib`.

## Environment

 - PyTorch Version (e.g., 1.0):
 - OS (e.g., Linux): MacOS
 - How you installed PyTorch (`conda`, `pip`, source): source
 - Build command you used (if compiling from source): `python setup.py`
 - Python version:
 - CUDA/cuDNN version:
 - GPU models and configuration:
 - Any other relevant information:

## Additional context
PR where the issue came up https://github.com/pytorch/pytorch/pull/61878


cc @malfet @seemethere @walterddr @albanD