-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize Objective-C bindings (#709)
This PR contains Objective-C wrapper code, podspec generation infras and the accompanying test code. Internal workitem: https://task.ms/aii/35199 --------- Co-authored-by: Edward Chen <[email protected]>
- Loading branch information
1 parent
e16da04
commit 8e171c7
Showing
35 changed files
with
2,579 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
parameters: | ||
- name: ort_version | ||
displayName: 'OnnxRuntime version' | ||
type: string | ||
default: '1.18.0' | ||
|
||
- name: build_config | ||
displayName: 'Build Configuration' | ||
type: string | ||
default: 'Release' | ||
values: | ||
- 'Debug' | ||
- 'RelWithDebInfo' | ||
- 'Release' | ||
- 'MinSizeRel' | ||
|
||
trigger: none | ||
stages: | ||
- template: stages/macos-ios-cocoapods-packaging-stage.yml | ||
parameters: | ||
ort_version: ${{ parameters.ort_version }} | ||
build_config: ${{ parameters.build_config }} |
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
40 changes: 40 additions & 0 deletions
40
.pipelines/stages/jobs/macos-ios-cocoapods-packaging-job.yml
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,40 @@ | ||
parameters: | ||
- name: build_config | ||
type: string | ||
- name: ort_version | ||
type: string | ||
|
||
jobs: | ||
- job: macos_ios_cocoapods_packaging | ||
pool: | ||
vmImage: 'macOS-latest' | ||
variables: | ||
buildSettingsFile: "tools/ci_build/github/apple/default_full_apple_framework_build_settings.json" | ||
|
||
workspace: | ||
clean: all | ||
steps: | ||
- checkout: self | ||
clean: true | ||
submodules: none | ||
|
||
- template: steps/utils/set-genai-version.yml | ||
- template: steps/utils/set-cmake-build-type.yml | ||
parameters: | ||
build_config: ${{parameters.build_config}} | ||
|
||
|
||
- task: CmdLine@2 | ||
displayName: Build MacOS & iOS CocoaPods Packages | ||
inputs: | ||
script: | | ||
set -e -x | ||
python tools/ci_build/github/apple/build_and_assemble_apple_pods.py \ | ||
--build-dir "$(Build.BinariesDirectory)/apple_framework" \ | ||
--staging-dir "$(Build.BinariesDirectory)/staging" \ | ||
--pod-version "$(genai_version)" \ | ||
--test \ | ||
--variant Full \ | ||
--build-settings-file "${{ variables.buildSettingsFile }}" \ | ||
--build-apple-framework-args==--config=$(cmake_build_type) \ | ||
--ort-version ${{parameters.ort_version}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
parameters: | ||
- name: ort_version | ||
type: string | ||
|
||
- name: build_config | ||
type: string | ||
default: 'Release' | ||
|
||
stages: | ||
- stage: Build_MacOS_iOS_CocoaPods_Archive | ||
jobs: | ||
- template: jobs/macos-ios-cocoapods-packaging-job.yml | ||
parameters: | ||
ort_version: ${{ parameters.ort_version }} | ||
build_config: ${{ parameters.build_config }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
// wrapper for ORT GenAI C/C++ API headers | ||
|
||
#if defined(__clang__) | ||
#pragma clang diagnostic push | ||
// ignore clang documentation-related warnings | ||
// instead, we will rely on Doxygen warnings for the C/C++ API headers | ||
#pragma clang diagnostic ignored "-Wdocumentation" | ||
#endif // defined(__clang__) | ||
|
||
#include "ort_genai.h" | ||
|
||
#if defined(__clang__) | ||
#pragma clang diagnostic pop | ||
#endif // defined(__clang__) |
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,29 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#include <exception> | ||
|
||
#import "cxx_api.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
extern NSString* const kOgaErrorDomain; | ||
|
||
void OGASaveCodeAndDescriptionToError(int code, const char* description, NSError** error); | ||
void OGASaveCodeAndDescriptionToError(int code, NSString* description, NSError** error); | ||
void OGASaveExceptionToError(const std::exception& e, NSError** error); | ||
|
||
// helper macros to catch and handle C++ exceptions | ||
#define OGA_OBJC_API_IMPL_CATCH(error, failure_return_value) \ | ||
catch (const std::exception& e) { \ | ||
OGASaveExceptionToError(e, (error)); \ | ||
return (failure_return_value); \ | ||
} | ||
|
||
#define OGA_OBJC_API_IMPL_CATCH_RETURNING_BOOL(error) OGA_OBJC_API_IMPL_CATCH(error, NO) | ||
|
||
#define OGA_OBJC_API_IMPL_CATCH_RETURNING_NULLABLE(error) OGA_OBJC_API_IMPL_CATCH(error, nil) | ||
|
||
NS_ASSUME_NONNULL_END |
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,34 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#import "error_utils.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
NSString* const kOgaErrorDomain = @"onnxruntime-genai"; | ||
const int kOgaErrorCode = 0x0A; | ||
|
||
void OGASaveCodeAndDescriptionToError(int code, const char* descriptionCstr, NSError** error) { | ||
if (!error) return; | ||
|
||
NSString* description = [NSString stringWithCString:descriptionCstr | ||
encoding:NSUTF8StringEncoding]; | ||
|
||
*error = [NSError errorWithDomain:kOgaErrorDomain | ||
code:code | ||
userInfo:@{NSLocalizedDescriptionKey : description}]; | ||
} | ||
|
||
void OGASaveCodeAndDescriptionToError(int code, NSString* description, NSError** error) { | ||
if (!error) return; | ||
|
||
*error = [NSError errorWithDomain:kOgaErrorDomain | ||
code:code | ||
userInfo:@{NSLocalizedDescriptionKey : description}]; | ||
} | ||
|
||
void OGASaveExceptionToError(const std::exception& e, NSError** error) { | ||
OGASaveCodeAndDescriptionToError(kOgaErrorCode, e.what(), error); | ||
} | ||
|
||
NS_ASSUME_NONNULL_END |
Oops, something went wrong.