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

Add iOS build configurations #33292

Merged
merged 14 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 13 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 eng/Configurations.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<PropertyGroup>
<__TargetOS Condition="$([MSBuild]::IsOSPlatform('OSX'))">OSX</__TargetOS>
<__TargetOS Condition="'$(__TargetOS)' == '' and $([MSBuild]::IsOSPlatform('OSX'))">OSX</__TargetOS>
<__TargetOS Condition="'$(__TargetOS)' == '' and $([MSBuild]::IsOSPlatform('FREEBSD'))">FreeBSD</__TargetOS>
<__TargetOS Condition="'$(__TargetOS)' == '' and $([MSBuild]::IsOSPlatform('NETBSD'))">NetBSD</__TargetOS>
<__TargetOS Condition="'$(__TargetOS)' == '' and $([MSBuild]::IsOSUnixLike())">Linux</__TargetOS>
Expand Down
7 changes: 7 additions & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

<_subsetCategory Condition="'$(SubsetCategory)' != ''">$(SubsetCategory.ToLowerInvariant())</_subsetCategory>
<_subsetCategory Condition="'$(SubsetCategory)' == ''">$(DefaultSubsetCategories)</_subsetCategory>
<_subsetCategory Condition="'$(SubsetCategory)' == '' and '$(TargetOS)' == 'iOS'">libraries-mono</_subsetCategory>
Copy link
Member

Choose a reason for hiding this comment

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

Should we error if SubsetCategory is not empty and contains either installer or coreclr when TargetOS is iOS?

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel like if you manually override subset category that way you deserve to get the failures :)

Copy link
Member

Choose a reason for hiding this comment

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

I get that, but it is good to help developers get readable failures? Sometimes because of the lack of those validations we get a lot of questions, why this doesn't work, why am I getting this error, etc? We already have a target that does validation for the subset categories, if I remember correctly.

Copy link
Member

@ViktorHofer ViktorHofer Mar 11, 2020

Choose a reason for hiding this comment

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

I think it's ok to set RuntimeFlavor based on the passed in SubsetCategory but I don't think that SubsetCategory should be inferred from TargetOS. The SubsetCategory can also contain values like mono, or mono-coreclr-libraries-installer therefore I think it's necessary to be intentional here and require the category to be passed in.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ViktorHofer why not? coreclr or installer are not valid subset categories when you have TargetOS=iOS so having a default when nothing is set explicitly makes a lot of sense.

Copy link
Member

Choose a reason for hiding this comment

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

I thought about this more. I'm fine with providing a default value for the subset categories when a configuration is passed in that isn't supported on one of those categories but I would not want to exclude installer which brings me back to my question: Why did you choose mono-libraries and not mono-libraries-installer?

Copy link
Member Author

@akoeplinger akoeplinger Mar 11, 2020

Choose a reason for hiding this comment

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

@ViktorHofer installer doesn't make sense at all, there won't be an installer for the iOS bits (nuget only). The default of mono-libraries is everything that we want to build by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can move the change to set DefaultSubsetCategories for TargetOS==iOS instead if that helps making it clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

I discussed this with Viktor offline and there was some misunderstanding. installer is not just for building the .deb/.msi/.pkg installers but also does other things like creating runtime packs and ref packs. So we might eventually need it for iOS too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Regarding the subset validation: Viktor and me took a look and it seems a little more complicated to add than expected. We'll do it in a separate PR.

<_subset Condition="'$(Subset)' != ''">$(Subset.ToLowerInvariant())</_subset>
<_subset Condition="'$(Subset)' == '' and $(_subsetCategory.Contains('installer'))">$(DefaultInstallerSubsets)</_subset>
<_subset Condition="'$(Subset)' == '' and $(_subsetCategory.Contains('libraries'))">$(_subset)-$(DefaultLibrariesSubsets)</_subset>
Expand All @@ -76,6 +77,12 @@
<_subset>-$(_subset)-</_subset>
</PropertyGroup>

<PropertyGroup>
<RuntimeFlavor Condition="'$(TargetOS)' == 'iOS'">Mono</RuntimeFlavor>
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == '' and $(_subsetCategory.Contains('mono')) and !$(_subsetCategory.Contains('coreclr'))">Mono</RuntimeFlavor>
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == ''">CoreCLR</RuntimeFlavor>
</PropertyGroup>
akoeplinger marked this conversation as resolved.
Show resolved Hide resolved

<ItemGroup>
<!-- Global -->
<SubsetName Include="RegenerateReadmeTable" Category="" OnDemand="true" Description="Regenerates the table of asset links in the README.md file." />
Expand Down
13 changes: 12 additions & 1 deletion eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ usage()
echo ""
echo "Common Options:"
echo ""
echo "BuildArch can be: -arm, -armel, -arm64, -armel, x64, x86, -wasm"
echo "BuildArch can be: -arm, -armel, -arm64, x64, x86, -wasm"
echo "BuildType can be: -debug, -checked, -release"
echo "-os: target OS (defaults to running OS)"
echo "-bindir: output directory (defaults to $__ProjectRoot/artifacts)"
echo "-ci: indicates if this is a CI build."
echo "-clang: optional argument to build using clang in PATH (default)."
Expand Down Expand Up @@ -355,6 +356,16 @@ while :; do
__BuildArch=wasm
;;

os|-os)
if [[ -n "$2" ]]; then
__TargetOS="$2"
shift
else
echo "ERROR: 'os' requires a non-empty option argument"
exit 1
fi
;;

*)
handle_arguments "$1" "$2"
if [[ "$__ShiftArgs" == 1 ]]; then
Expand Down
21 changes: 21 additions & 0 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ if(CLR_CMAKE_HOST_OS STREQUAL Darwin)
set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> <INCLUDES> -o <OBJECT> -c <SOURCE>")
endif(CLR_CMAKE_HOST_OS STREQUAL Darwin)

if(CLR_CMAKE_HOST_OS STREQUAL iOS)
set(CLR_CMAKE_HOST_UNIX 1)
set(CLR_CMAKE_HOST_IOS 1)
if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "armv7")
set(CLR_CMAKE_HOST_UNIX_ARM 1)
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
set(CLR_CMAKE_HOST_UNIX_ARM64 1)
else()
clr_unknown_arch()
endif()
endif(CLR_CMAKE_HOST_OS STREQUAL iOS)

if(CLR_CMAKE_HOST_OS STREQUAL FreeBSD)
set(CLR_CMAKE_HOST_UNIX 1)
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
Expand Down Expand Up @@ -230,6 +244,11 @@ if(CLR_CMAKE_TARGET_OS STREQUAL Darwin)
set(CLR_CMAKE_TARGET_DARWIN 1)
endif(CLR_CMAKE_TARGET_OS STREQUAL Darwin)

if(CLR_CMAKE_TARGET_OS STREQUAL iOS)
set(CLR_CMAKE_TARGET_UNIX 1)
set(CLR_CMAKE_TARGET_IOS 1)
endif(CLR_CMAKE_TARGET_OS STREQUAL iOS)
Copy link
Member

Choose a reason for hiding this comment

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

I'd expect iOS to set CLR_CMAKE_TARGET_DARWIN too. Not sure whether it would make the rest of the diff with if conditions smaller or larger though.

Copy link
Member

Choose a reason for hiding this comment

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

Yes please, at least on cmake side, we are consistent with Darwin naming. It's only the code and RIDs where the (obsolete) osx name is used. 😁

Copy link
Member Author

@akoeplinger akoeplinger Mar 6, 2020

Choose a reason for hiding this comment

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

This was a conscious decision because CLR_CMAKE_TARGET_DARWIN really means macOS in the rest of the build scripts. We could rename it to CLR_CMAKE_TARGET_OSX?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll do the renaming in a follow-up PR.


if(CLR_CMAKE_TARGET_OS STREQUAL FreeBSD)
set(CLR_CMAKE_TARGET_UNIX 1)
set(CLR_CMAKE_TARGET_FREEBSD 1)
Expand Down Expand Up @@ -302,3 +321,5 @@ if(NOT CLR_CMAKE_HOST_ARCH_WASM)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif(NOT CLR_CMAKE_HOST_ARCH_WASM)

set(CLR_CMAKE_CONFIGURE_PLATFORM_INCLUDED 1)
6 changes: 5 additions & 1 deletion eng/native/configuretools.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if(NOT CLR_CMAKE_CONFIGURE_PLATFORM_INCLUDED)
message(FATAL_ERROR "configuretools.cmake needs to be included after configureplatform.cmake")
endif()

# Get the version of the compiler that is in the file name for tool location.
set (CLR_CMAKE_COMPILER_FILE_NAME_VERSION "")
if (CMAKE_C_COMPILER MATCHES "-?[0-9]+(\.[0-9]+)?$")
Expand Down Expand Up @@ -45,7 +49,7 @@ if(NOT WIN32)
locate_toolchain_exec(ranlib CMAKE_RANLIB)
endif()

if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(NOT CLR_CMAKE_TARGET_DARWIN AND NOT CLR_CMAKE_TARGET_IOS)
locate_toolchain_exec(objdump CMAKE_OBJDUMP)

if(CMAKE_CROSSCOMPILING AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD AND (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR
Expand Down
2 changes: 2 additions & 0 deletions eng/native/init-distro-rid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ initDistroRidGlobal()
distroRid="linux-$buildArch"
elif [ "$targetOs" = "OSX" ]; then
distroRid="osx-$buildArch"
elif [ "$targetOs" = "iOS" ]; then
distroRid="ios-$buildArch"
elif [ "$targetOs" = "FreeBSD" ]; then
distroRid="freebsd-$buildArch"
fi
Expand Down
2 changes: 1 addition & 1 deletion eng/native/naming.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<SymbolFileExtension>.pdb</SymbolFileExtension>
</PropertyGroup>
</When>
<When Condition=" '$(_runtimeOSFamily)' == 'osx' OR $(RuntimeIdentifier.StartsWith('osx')) ">
<When Condition=" '$(_runtimeOSFamily)' == 'osx' OR $(RuntimeIdentifier.StartsWith('osx')) OR '$(_runtimeOSFamily)' == 'ios' OR $(RuntimeIdentifier.StartsWith('ios'))">
akoeplinger marked this conversation as resolved.
Show resolved Hide resolved
<PropertyGroup>
<LibraryFilePrefix Condition=" '$(SkipLibraryPrefixFromUnix)' == '' ">lib</LibraryFilePrefix>
<LibraryFileExtension>.dylib</LibraryFileExtension>
Expand Down
2 changes: 1 addition & 1 deletion src/installer/corehost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.14.2)

project(corehost)

include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake)
include(${CLR_ENG_NATIVE_DIR}/configureplatform.cmake)
include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake)
include(../settings.cmake)
include(../functions.cmake)
add_subdirectory(cli)
17 changes: 15 additions & 2 deletions src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
<ArchGroup Condition="'$(ArchGroup)' == '' and '$(HostArch)' == 'arm'">arm</ArchGroup>
<ArchGroup Condition="'$(ArchGroup)' == '' and '$(HostArch)' == 'arm64'">arm64</ArchGroup>
<ArchGroup Condition="'$(ArchGroup)' == '' and '$(TargetOS)' == 'WebAssembly'">wasm</ArchGroup>
<ArchGroup Condition="'$(ArchGroup)' == '' and '$(TargetOS)' == 'iOS'">x64</ArchGroup>
<ArchGroup Condition="'$(ArchGroup)' == ''">x64</ArchGroup>

<!-- RuntimeOS is calculated based on the build system OS, however if building for WebAssembly we need to let
the build system to use webassembly as the RuntimeOS for produced package RIDs. -->
<!-- RuntimeOS is calculated based on the build system OS, however if building for WebAssembly or iOS we need to let
the build system to use webassembly/ios as the RuntimeOS for produced package RIDs. -->
<RuntimeOS Condition="'$(TargetOS)' == 'WebAssembly'">$(TargetOS.ToLowerInvariant())</RuntimeOS>
<RuntimeOS Condition="'$(TargetOS)' == 'iOS'">$(TargetOS.ToLowerInvariant())</RuntimeOS>

<!-- Initialize BuildSettings from the individual properties if it wasn't already explicitly set -->
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
Expand Down Expand Up @@ -79,6 +81,13 @@
<PackageTargetRuntime>osx</PackageTargetRuntime>
</PropertyGroup>
</When>
<When Condition="'$(TargetFrameworkSuffix)' == 'iOS'">
<PropertyGroup>
<TargetsUnix>true</TargetsUnix>
<TargetsiOS>true</TargetsiOS>
akoeplinger marked this conversation as resolved.
Show resolved Hide resolved
<PackageTargetRuntime>ios</PackageTargetRuntime>
</PropertyGroup>
</When>
<When Condition="'$(TargetFrameworkSuffix)' == 'FreeBSD'">
<PropertyGroup>
<TargetsUnix>true</TargetsUnix>
Expand Down Expand Up @@ -155,6 +164,7 @@
<_portableOS Condition="'$(_runtimeOSFamily)' == 'osx'">osx</_portableOS>
<_portableOS Condition="'$(_runtimeOSFamily)' == 'FreeBSD'">freebsd</_portableOS>
<_portableOS Condition="'$(RuntimeOS)' == 'WebAssembly'">webassembly</_portableOS>
<_portableOS Condition="'$(RuntimeOS)' == 'ios'">ios</_portableOS>

<_runtimeOS>$(RuntimeOS)</_runtimeOS>
<_runtimeOS Condition="'$(_runtimeOS)' == 'tizen.4.0.0'">linux</_runtimeOS>
Expand All @@ -171,6 +181,9 @@
<ToolRuntimeRID Condition="'$(RuntimeOS)' == 'webassembly' and '$(TargetOS)' != 'Windows_NT' and $(_buildingInOSX)">osx-x64</ToolRuntimeRID>
<ToolRuntimeRID Condition="'$(RuntimeOS)' == 'webassembly' and '$(TargetOS)' != 'Windows_NT' and !$(_buildingInOSX)">linux-x64</ToolRuntimeRID>

<!-- There are no iOS tools and it can be built on OSX only, so use that -->
<ToolRuntimeRID Condition="'$(RuntimeOS)' == 'ios'">osx-x64</ToolRuntimeRID>

<!-- support cross-targeting by choosing a RID to restore when running on a different machine that what we're build for -->
<_portableOS Condition="'$(TargetOS)' == 'Unix' and '$(_runtimeOSFamily)' != 'osx' and '$(_runtimeOSFamily)' != 'FreeBSD' and '$(_runtimeOS)' != 'linux-musl'">linux</_portableOS>

Expand Down
18 changes: 16 additions & 2 deletions src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ project(CoreFX C)

include(${CLR_ENG_NATIVE_DIR}/configureplatform.cmake)

if(CLR_CMAKE_TARGET_IOS)
cmake_minimum_required(VERSION 3.14.5)
endif()

if(NOT CLR_CMAKE_TARGET_ARCH_WASM)
cmake_policy(SET CMP0083 NEW)
endif(NOT CLR_CMAKE_TARGET_ARCH_WASM)
Expand Down Expand Up @@ -118,7 +122,7 @@ else ()
endif ()

if(CLR_CMAKE_TARGET_ARCH_WASM)
elseif (CLR_CMAKE_TARGET_DARWIN)
elseif (CLR_CMAKE_TARGET_DARWIN OR CLR_CMAKE_TARGET_IOS)
add_definitions(-D__APPLE_USE_RFC_3542)

# We cannot enable "stack-protector-strong" on OS X due to a bug in clang compiler (current version 7.0.2)
Expand Down Expand Up @@ -156,6 +160,8 @@ if(CLR_CMAKE_TARGET_UNIX)
if (STRIP STREQUAL "STRIP-NOTFOUND")
message(FATAL_ERROR "strip not found")
endif()
elseif (CLR_CMAKE_TARGET_IOS)
# No object stripping for iOS
elseif (CLR_CMAKE_TARGET_ARCH_WASM)
# No object stripping for WASM
else (CLR_CMAKE_TARGET_DARWIN)
Expand Down Expand Up @@ -194,8 +200,10 @@ include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake)
add_subdirectory(System.IO.Compression.Native)

if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
if (NOT CLR_CMAKE_TARGET_IOS) # TODO: reenable
add_subdirectory(System.IO.Ports.Native)
endif()
endif()

if(CMAKE_C_COMPILER_ID STREQUAL Clang)
add_compile_options(-Weverything)
Expand All @@ -204,11 +212,17 @@ endif()
add_subdirectory(System.Native)

if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
if (NOT CLR_CMAKE_TARGET_IOS) # TODO: reenable
add_subdirectory(System.Globalization.Native)
add_subdirectory(System.Net.Security.Native)
endif()
if (NOT CLR_CMAKE_TARGET_IOS)
# disable System.Security.Cryptography.Native build on iOS,
# only used for interacting with OpenSSL which isn't useful there
add_subdirectory(System.Security.Cryptography.Native)
endif()
endif()

if(CLR_CMAKE_TARGET_DARWIN)
if(CLR_CMAKE_TARGET_DARWIN OR CLR_CMAKE_TARGET_IOS)
add_subdirectory(System.Security.Cryptography.Native.Apple)
endif()
6 changes: 5 additions & 1 deletion src/libraries/Native/Unix/Common/pal_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
#cmakedefine01 HAVE_TCSANOW
#cmakedefine01 HAVE_IN_PKTINFO
#cmakedefine01 HAVE_IP_MREQN
#cmakedefine01 HAVE_TCP_VAR_H
#cmakedefine01 HAVE_NETINET_TCP_VAR_H
#cmakedefine01 HAVE_NETINET_UDP_VAR_H
#cmakedefine01 HAVE_NETINET_IP_VAR_H
#cmakedefine01 HAVE_NETINET_ICMP_VAR_H
#cmakedefine01 HAVE_IOS_NET_ROUTE_H
#cmakedefine01 HAVE_RT_MSGHDR
#cmakedefine01 HAVE_RT_MSGHDR2
#cmakedefine01 HAVE_IF_MSGHDR2
Expand Down
Loading