-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS] Remove cmake build dependency for library mode (#89869)
This change removes cmake as a build dependency and instead uses clang directly when building for iOS/tvOS/Macatalyst library mode.
- Loading branch information
Showing
14 changed files
with
775 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(%ProjectName%) | ||
enable_language(OBJC ASM) | ||
|
||
set(APP_RESOURCES | ||
%AppResources% | ||
lib%ProjectName%.dylib | ||
) | ||
|
||
add_executable( | ||
%ProjectName% | ||
%MainSource% | ||
${APP_RESOURCES} | ||
) | ||
|
||
if(NOT %UseNativeAOTRuntime%) | ||
target_sources( | ||
%ProjectName% | ||
PRIVATE | ||
runtime.m) | ||
endif() | ||
|
||
%Defines% | ||
|
||
if(NOT %UseNativeAOTRuntime%) | ||
include_directories("%MonoInclude%") | ||
endif() | ||
|
||
#set_target_properties(%ProjectName% %AotTargetsList% PROPERTIES | ||
# XCODE_ATTRIBUTE_SUPPORTS_MACCATALYST "YES" | ||
#) | ||
|
||
set_target_properties(%ProjectName% PROPERTIES | ||
MACOSX_BUNDLE TRUE | ||
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist | ||
XCODE_ATTRIBUTE_ENABLE_BITCODE "NO" | ||
XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING "NO" | ||
XCODE_EMIT_EFFECTIVE_PLATFORM_NAME "YES" | ||
XCODE_EMBED_FRAMEWORKS "%DYLIB_PATH%" | ||
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks" | ||
RESOURCE "${APP_RESOURCES}" | ||
) | ||
|
||
set(HARDENED_RUNTIME | ||
%HardenedRuntime% | ||
) | ||
|
||
set(HARDENED_RUNTIME_USE_ENTITLEMENTS_FILE | ||
%HardenedRuntimeUseEntitlementsFile% | ||
) | ||
|
||
if("${HARDENED_RUNTIME}") | ||
set_target_properties(%ProjectName% PROPERTIES XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES") | ||
if("${HARDENED_RUNTIME_USE_ENTITLEMENTS_FILE}") | ||
set_target_properties(%ProjectName% PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "app.entitlements") | ||
add_custom_command( | ||
TARGET %ProjectName% POST_BUILD | ||
COMMAND if test \"$CODE_SIGN_IDENTITY\"\; then codesign -fs \"$CODE_SIGN_IDENTITY\" $CODESIGNING_FOLDER_PATH/Contents/Resources/*.dylib\; fi | ||
) | ||
endif() | ||
endif() | ||
|
||
# FIXME: `XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING` should not be NO | ||
|
||
target_link_libraries( | ||
%ProjectName% | ||
PRIVATE | ||
"-framework Foundation" | ||
"-framework Security" | ||
"-framework UIKit" | ||
"-lz" | ||
"-lc++" | ||
"-liconv" | ||
%NativeLibrariesToLink% | ||
%APP_LINK_LIBRARIES% | ||
) | ||
|
||
set_target_properties( | ||
%ProjectName% | ||
PROPERTIES LINK_FLAGS | ||
%EXTRA_LINKER_ARGS% | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#import <Foundation/Foundation.h> | ||
#include <mono/utils/mono-publib.h> | ||
#include <mono/utils/mono-logger.h> | ||
#include <mono/metadata/assembly.h> | ||
#include <mono/metadata/appdomain.h> | ||
#include <mono/metadata/class.h> | ||
#include <mono/metadata/mono-debug.h> | ||
#include <mono/metadata/mono-gc.h> | ||
#include <mono/metadata/exception.h> | ||
#include <mono/metadata/object.h> | ||
#include <mono/jit/jit.h> | ||
#include <mono/jit/mono-private-unstable.h> | ||
#include <TargetConditionals.h> | ||
#import <os/log.h> | ||
#include <sys/stat.h> | ||
#include <sys/mman.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
#import "util.h" | ||
|
||
static char *bundle_path; | ||
|
||
int SayHello (void); | ||
|
||
int invoke_netlibrary_entrypoints (void) | ||
{ | ||
return SayHello (); | ||
} | ||
|
||
const char * | ||
get_bundle_path (void) | ||
{ | ||
if (bundle_path) | ||
return bundle_path; | ||
NSBundle* main_bundle = [NSBundle mainBundle]; | ||
NSString* path = [main_bundle bundlePath]; | ||
|
||
#if TARGET_OS_MACCATALYST | ||
path = [path stringByAppendingString:@"/Contents/Resources"]; | ||
#endif | ||
|
||
bundle_path = strdup ([path UTF8String]); | ||
|
||
return bundle_path; | ||
} | ||
|
||
void | ||
mono_ios_runtime_init (void) | ||
{ | ||
#if INVARIANT_GLOBALIZATION | ||
setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); | ||
#endif | ||
|
||
#if HYBRID_GLOBALIZATION | ||
setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE); | ||
#endif | ||
|
||
#if ENABLE_RUNTIME_LOGGING | ||
setenv ("MONO_LOG_LEVEL", "debug", TRUE); | ||
setenv ("MONO_LOG_MASK", "all", TRUE); | ||
#endif | ||
|
||
// build using DiagnosticPorts property in AppleAppBuilder | ||
// or set DOTNET_DiagnosticPorts env via mlaunch, xharness when undefined. | ||
// NOTE, using DOTNET_DiagnosticPorts requires app build using AppleAppBuilder and RuntimeComponents=diagnostics_tracing | ||
#ifdef DIAGNOSTIC_PORTS | ||
setenv ("DOTNET_DiagnosticPorts", DIAGNOSTIC_PORTS, true); | ||
#endif | ||
|
||
// When not bundling, this will make sure the runtime can access all the assemblies | ||
const char* bundle = get_bundle_path (); | ||
chdir (bundle); | ||
|
||
int res = invoke_netlibrary_entrypoints (); | ||
|
||
exit (res); | ||
} |
Oops, something went wrong.