Skip to content

update build_host_protoc command for macos cross compilation#50922

Closed
janeyx99 wants to merge 1 commit intopytorch:masterfrom
janeyx99:improve-cross-compile-macos-command
Closed

update build_host_protoc command for macos cross compilation#50922
janeyx99 wants to merge 1 commit intopytorch:masterfrom
janeyx99:improve-cross-compile-macos-command

Conversation

@janeyx99
Copy link
Copy Markdown
Contributor

@janeyx99 janeyx99 commented Jan 22, 2021

Currently, adding a cross compile build is failing on CI due to a cmake builtin compiler check that does not pass due to cross compiling the host protoc library. This PR edits the cmake config to make it work. Tested in #49751, specifically with https://app.circleci.com/pipelines/github/pytorch/pytorch/272514/workflows/82c6a000-75fd-4a03-a9ad-dcc834927af9/jobs/10841449.

Setting the CMAKE_TRY_COMPILE_TARGET_TYPE flag should fix it. (Based on this SOF answer.) This didn't fix it completely, and so I disabled the compiler checks entirely.

To test that this works, please run: CMAKE_OSX_ARCHITECTURES=arm64 USE_MKLDNN=OFF USE_NNPACK=OFF USE_QNNPACK=OFF USE_PYTORCH_QNNPACK=OFF BUILD_TEST=OFF python setup.py install from a Mac x86_64 machine with Xcode12.3 (anything with MacOS 11 SDK).

Then, you can check that things were compiled for arm by running lipo -info <file> for any file in the build/lib directory.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Jan 22, 2021

💊 CI failures summary and remediations

As of commit 0f426b1e26 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 22, 2021

Codecov Report

Merging #50922 (581b7ce) into master (fcf8b71) will increase coverage by 0.18%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master   #50922      +/-   ##
==========================================
+ Coverage   80.81%   81.00%   +0.18%     
==========================================
  Files        1948     1916      -32     
  Lines      213213   209481    -3732     
==========================================
- Hits       172309   169686    -2623     
+ Misses      40904    39795    -1109     

@janeyx99 janeyx99 force-pushed the improve-cross-compile-macos-command branch from 5bbda74 to 581b7ce Compare January 22, 2021 20:41
Comment thread CMakeLists.txt Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For more context, it'd be really nice to just have:

execute_process(COMMAND ./scripts/build_host_protoc.sh --other-flags -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
...

But this causes a CMake error because it cannot parse the double quotes correctly. Out of the many alternatives I've tried, writing to a temp file was the only one that worked, but I am glad to switch to anything cleaner that also works.

@janeyx99 janeyx99 force-pushed the improve-cross-compile-macos-command branch from 581b7ce to 0f426b1 Compare February 9, 2021 23:53
@janeyx99 janeyx99 marked this pull request as ready for review February 10, 2021 00:04
Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@janeyx99 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@janeyx99 janeyx99 force-pushed the improve-cross-compile-macos-command branch from 0f426b1 to 751755c Compare February 10, 2021 20:08
@janeyx99 janeyx99 requested review from a team and malfet February 11, 2021 00:14
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@janeyx99 merged this pull request in ac2bdf5.

facebook-github-bot pushed a commit that referenced this pull request Feb 12, 2021
Summary:
Tests cross-compilation of ARM64 architecture in MacOS CI.

This should be merged after PR #50243 and #50922 (adding a fix).

The reason we pin the wheel to be version 0.36.2 is because lower versions cannot handle c38 as a tag for the wheel.

Pull Request resolved: #49751

Reviewed By: albanD

Differential Revision: D26411133

Pulled By: janeyx99

fbshipit-source-id: 00a5cf597aee10adea1547579270cb3b38732563
xsacha pushed a commit to xsacha/pytorch that referenced this pull request Mar 31, 2021
…#50922)

Summary:
Currently, adding a cross compile build is failing on CI due to a cmake builtin compiler check that does not pass due to cross compiling the host protoc library.

Setting the CMAKE_TRY_COMPILE_TARGET_TYPE flag should fix it. (Based on this [SOF answer](https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program).)

To test that this works, please run: `CMAKE_OSX_ARCHITECTURES=arm64 USE_MKLDNN=OFF USE_NNPACK=OFF USE_QNNPACK=OFF USE_PYTORCH_QNNPACK=OFF BUILD_TEST=OFF python setup.py install` from a Mac x86_64 machine with Xcode12.3 (anything with MacOS 11 SDK).

Then, you can check that things were compiled for arm by running `lipo -info <file>` for any file in the `build/lib` directory.

Pull Request resolved: pytorch#50922

Reviewed By: malfet

Differential Revision: D26355054

Pulled By: janeyx99

fbshipit-source-id: 919f3f9bd95d7c7bba6ab3a95428d3ca309f8ead
xsacha pushed a commit to xsacha/pytorch that referenced this pull request Mar 31, 2021
Summary:
Tests cross-compilation of ARM64 architecture in MacOS CI.

This should be merged after PR pytorch#50243 and pytorch#50922 (adding a fix).

The reason we pin the wheel to be version 0.36.2 is because lower versions cannot handle c38 as a tag for the wheel.

Pull Request resolved: pytorch#49751

Reviewed By: albanD

Differential Revision: D26411133

Pulled By: janeyx99

fbshipit-source-id: 00a5cf597aee10adea1547579270cb3b38732563
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…#50922)

Summary:
Currently, adding a cross compile build is failing on CI due to a cmake builtin compiler check that does not pass due to cross compiling the host protoc library.

Setting the CMAKE_TRY_COMPILE_TARGET_TYPE flag should fix it. (Based on this [SOF answer](https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program).)

To test that this works, please run: `CMAKE_OSX_ARCHITECTURES=arm64 USE_MKLDNN=OFF USE_NNPACK=OFF USE_QNNPACK=OFF USE_PYTORCH_QNNPACK=OFF BUILD_TEST=OFF python setup.py install` from a Mac x86_64 machine with Xcode12.3 (anything with MacOS 11 SDK).

Then, you can check that things were compiled for arm by running `lipo -info <file>` for any file in the `build/lib` directory.

Pull Request resolved: pytorch#50922

Reviewed By: malfet

Differential Revision: D26355054

Pulled By: janeyx99

fbshipit-source-id: 919f3f9bd95d7c7bba6ab3a95428d3ca309f8ead
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Tests cross-compilation of ARM64 architecture in MacOS CI.

This should be merged after PR pytorch#50243 and pytorch#50922 (adding a fix).

The reason we pin the wheel to be version 0.36.2 is because lower versions cannot handle c38 as a tag for the wheel.

Pull Request resolved: pytorch#49751

Reviewed By: albanD

Differential Revision: D26411133

Pulled By: janeyx99

fbshipit-source-id: 00a5cf597aee10adea1547579270cb3b38732563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants