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

Initialize Objective-C bindings #709

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
b339911
Init objc bindings
skyline75489 Jul 9, 2024
718e8d1
Merge branch 'main' into jialli/objc-bindings
skyline75489 Jul 12, 2024
1e14fa7
More objc
skyline75489 Jul 16, 2024
683daf5
Fix
skyline75489 Jul 16, 2024
e77fb60
OGASpan
skyline75489 Jul 16, 2024
ad1c9e8
More objc bindings
skyline75489 Jul 17, 2024
83d1273
license header
skyline75489 Jul 17, 2024
d635d63
Update
skyline75489 Jul 17, 2024
f4772b6
Merge branch 'main' into jialli/objc-bindings
skyline75489 Jul 18, 2024
6099236
Update folder structure
skyline75489 Jul 18, 2024
fda89e8
format
skyline75489 Jul 18, 2024
844e7d5
Rm podspec for now
skyline75489 Jul 18, 2024
891ec8c
header
skyline75489 Jul 18, 2024
a4af1b5
more header
skyline75489 Jul 18, 2024
fef5a1a
catch
skyline75489 Jul 18, 2024
cda7411
Lint
skyline75489 Jul 18, 2024
edd86f6
Lint
skyline75489 Jul 18, 2024
2eeb42c
Lint
skyline75489 Jul 18, 2024
27d5494
Lint
skyline75489 Jul 18, 2024
b904daf
Merge branch 'main' into jialli/objc-bindings
skyline75489 Aug 5, 2024
616c1c5
Merge branch 'main' into jialli/objc-bindings
skyline75489 Aug 22, 2024
0da29a6
Merge branch 'main' into jialli/objc-bindings
skyline75489 Aug 22, 2024
808398a
save
skyline75489 Sep 5, 2024
ab6b20f
Merge branch 'main' into jialli/objc-bindings
skyline75489 Sep 26, 2024
cda2e39
Update interface
skyline75489 Sep 26, 2024
01c0416
init pipeline
skyline75489 Oct 15, 2024
2fd95d5
Merge branch 'main' into jialli/objc-bindings
skyline75489 Oct 15, 2024
318cce1
cocoapods pipeline
skyline75489 Oct 15, 2024
d501750
tools and YAMLs
skyline75489 Oct 15, 2024
bb44854
[skip ci] assemble pod
skyline75489 Oct 15, 2024
65d8240
[skip ci] podspec templat
skyline75489 Oct 15, 2024
d17fa47
[skip ci] fix pod file copying
skyline75489 Oct 15, 2024
5ff6fb9
[skip ci] yml
skyline75489 Oct 15, 2024
8939e46
[skip ci] fix pipeline
skyline75489 Oct 15, 2024
242dd2a
nuget authenticate
skyline75489 Oct 16, 2024
732415c
[skip ci] pod lint
skyline75489 Oct 16, 2024
15f503d
[skip ci] pod testing infra
skyline75489 Oct 16, 2024
dee8bd2
[skip ci] Init objc testing
skyline75489 Oct 16, 2024
b3c4868
Fix
skyline75489 Oct 17, 2024
6e3c975
Update
skyline75489 Oct 17, 2024
6af7c27
getoutput
skyline75489 Oct 17, 2024
f759b1a
UPdate
skyline75489 Oct 17, 2024
6206498
script
skyline75489 Oct 18, 2024
6b6a839
[skip ci] model test
skyline75489 Oct 18, 2024
cf227f9
[skip ci] beam search
skyline75489 Oct 18, 2024
fed0ba1
[skip ci] fix tests
skyline75489 Oct 21, 2024
0156a16
Update
skyline75489 Oct 21, 2024
8133c36
reviews
skyline75489 Oct 22, 2024
565aad1
reviews
skyline75489 Oct 22, 2024
c4f389c
update
skyline75489 Oct 22, 2024
5b1e1ef
getOutput
skyline75489 Oct 23, 2024
c9c31e3
reviews
skyline75489 Oct 24, 2024
8d41739
review
skyline75489 Oct 28, 2024
7b068e8
clang-format
skyline75489 Oct 28, 2024
9ac3518
Merge branch 'main' into jialli/objc-bindings
skyline75489 Oct 28, 2024
094fb41
reviews
skyline75489 Oct 29, 2024
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
22 changes: 22 additions & 0 deletions .pipelines/macos-ios-cocoapods-publishing.yml
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 }}
1 change: 1 addition & 0 deletions .pipelines/stages/jobs/capi-packaging-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@ jobs:
- template: steps/capi-appleframework-step.yml
parameters:
build_config: ${{ parameters.build_config }}
build_settings_file: "tools/ci_build/github/apple/default_full_ios_framework_build_settings.json"

- template: steps/compliant-and-cleanup-step.yml
41 changes: 41 additions & 0 deletions .pipelines/stages/jobs/macos-ios-cocoapods-packaging-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
parameters:
- name: build_config
type: string
default: 'release'
- 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 \
skyline75489 marked this conversation as resolved.
Show resolved Hide resolved
--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}}
2 changes: 2 additions & 0 deletions .pipelines/stages/jobs/nuget-packaging-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ jobs:

- template: steps/utils/set-genai-version.yml

- task: NuGetAuthenticate@1

- powershell: |
dotnet --info
dotnet build Microsoft.ML.OnnxRuntimeGenAI.csproj -p:Configuration="$(buildConfig)" -p:IncludeMobileTargets=true --verbosity normal
Expand Down
9 changes: 7 additions & 2 deletions .pipelines/stages/jobs/steps/capi-appleframework-step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ parameters:
- name: build_config
type: string
default: 'release'

- name: build_settings_file
type: string
steps:

- checkout: self
Expand All @@ -11,6 +12,9 @@ steps:
submodules: recursive

- template: utils/set-genai-version.yml
- template: utils/set-cmake-build-type.yml
parameters:
build_config: ${{parameters.build_config}}

- template: utils/set-nightly-build-option-variable.yml

Expand All @@ -19,7 +23,8 @@ steps:
python3 -m pip install requests
python3 tools/ci_build/github/apple/build_apple_framework.py \
--build_dir "$(Build.BinariesDirectory)/apple_framework" \
tools/ci_build/github/apple/default_full_ios_framework_build_settings.json
--config $(cmake_build_type) \
${{ parameters.build_settings_file }}

mkdir $(Build.BinariesDirectory)/artifacts
mkdir -p $(Build.BinariesDirectory)/artifacts_staging/onnxruntime-genai.xcframework
Expand Down
15 changes: 15 additions & 0 deletions .pipelines/stages/macos-ios-cocoapods-packaging-stage.yml
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 }}
1 change: 1 addition & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ def update(args: argparse.Namespace, env: dict[str, str]):
"-DENABLE_PYTHON=OFF",
"-DENABLE_TESTS=OFF",
"-DENABLE_MODEL_BENCHMARK=OFF",
"-DCMAKE_OSX_DEPLOYMENT_TARGET=" + args.apple_deploy_target,
f"-DBUILD_APPLE_FRAMEWORK={'ON' if args.build_apple_framework else 'OFF'}",
"-DPLATFORM_NAME=" + platform_name,
]
Expand Down
17 changes: 17 additions & 0 deletions src/objectivec/cxx_api.h
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__)

#import "ort_genai.h"

#if defined(__clang__)
#pragma clang diagnostic pop
#endif // defined(__clang__)
29 changes: 29 additions & 0 deletions src/objectivec/error_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
skyline75489 marked this conversation as resolved.
Show resolved Hide resolved
// 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
34 changes: 34 additions & 0 deletions src/objectivec/error_utils.mm
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:NSASCIIStringEncoding];

*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
Loading
Loading