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

[boost-modular-build-helper] Bugfix/boost arm64 ios #18124

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ports/boost-modular-build-helper/boost-modular-build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function(boost_modular_build)
vcpkg_install_cmake()
endfunction()

if(VCPKG_CMAKE_SYSTEM_NAME AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
if(VCPKG_CMAKE_SYSTEM_NAME AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND NOT (VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64" AND (VCPKG_CMAKE_SYSTEM_NAME STREQUAL "iOS" OR VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Darwin")))
set(build_flag 0)
if(NOT DEFINED VCPKG_BUILD_TYPE)
set(build_flag 1)
Expand Down
30 changes: 29 additions & 1 deletion ports/boost-modular-build-helper/user-config.jam
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,37 @@ if "@VCPKG_PLATFORM_TOOLSET@" != "external"
@TOOLSET_OPTIONS@
;
}
else if "@VCPKG_TARGET_ARCHITECTURE@" = "arm64" && "@VCPKG_CMAKE_SYSTEM_NAME@" = "iOS"
{
using gcc : 12.0.0 : @CMAKE_CXX_COMPILER@
:
<ranlib>@CMAKE_RANLIB@
<archiver>@CMAKE_AR@
@CXXFLAGS@
@CFLAGS@
@LDFLAGS@
# MINGW here causes b2 to not run cygpath
<flavor>mingw
<compileflags>"-std=c++14 -stdlib=libc++ -DNDEBUG -arch arm64 -fembed-bitcode -Wno-unused-local-typedef -Wno-nullability-completeness -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
;
Copy link
Author

Choose a reason for hiding this comment

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

This compilerflag is needed to compile arm64 for iOS

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a way to specify the iOS target via the CMakeLists.txt file, which could remove the need to change the user-config.jam. Specifically the line that specifies the target-os option:

if(APPLE)
    list(APPEND B2_OPTIONS target-os=darwin toolset=clang)
elseif(WIN32)
    list(APPEND B2_OPTIONS target-os=windows toolset=gcc)
elseif(ANDROID)

For iOS, that would be target-os=iphone docs

It would also be nice to make this work for both arm64 iOS and macOS builds, i.e. the arm64-ios and arm64-osx triplets:

set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CMAKE_SYSTEM_NAME iOS)

and

set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CMAKE_SYSTEM_NAME Darwin)

Boosts's b2 doesn't natively support arm64, so the extra -arch arm64 can be added to the CMakeLists.txt config like so:

if(APPLE AND VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
  set(CFLAGS "${CFLAGS} <compileflags>-arch <compileflags>arm64")
  set(CXXFLAGS "${CXXFLAGS} <compileflags>-arch <compileflags>arm64")
  set(LDFLAGS "${LDFLAGS} <linkflags>-arch <linkflags>arm64")  
endif()

Copy link
Author

@StefAviator StefAviator May 31, 2021

Choose a reason for hiding this comment

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

I have tried adding these compilerflags to CMakeLists.txt but it keeps outputting x86-64 library files so unfortunately it does not work. I tried this change using both unix_build and the second builder. If you know how to get this to work to cross-compile on an Apple PC/laptop with Intel chip to arm64 by adjusting the CMakeLists file, please share.

}
else if "@VCPKG_TARGET_ARCHITECTURE@" = "arm64" && "@VCPKG_CMAKE_SYSTEM_NAME@" = "Darwin"
{
using gcc : 12.0.0 : @CMAKE_CXX_COMPILER@
:
<ranlib>@CMAKE_RANLIB@
<archiver>@CMAKE_AR@
@CXXFLAGS@
@CFLAGS@
@LDFLAGS@
# MINGW here causes b2 to not run cygpath
<flavor>mingw
<compileflags>"-std=c++14 -stdlib=libc++ -DNDEBUG -arch arm64 -fembed-bitcode -Wno-unused-local-typedef -Wno-nullability-completeness -mmacosx-version-min=10.12 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
Copy link
Author

Choose a reason for hiding this comment

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

Here we are using the default MacOS sdk on the system. "Darwin" above is used in the triplet for unix / osx / MacOS.

;
}
else
{
using gcc : 5.4.1 : @CMAKE_CXX_COMPILER@
using gcc : 12.0.0 : @CMAKE_CXX_COMPILER@
Copy link
Author

Choose a reason for hiding this comment

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

Updating to the latest gcc.

:
<ranlib>@CMAKE_RANLIB@
<archiver>@CMAKE_AR@
Expand Down