onnxruntime/tools/ci_build/github/azure-pipelines/templates/mac-cpu-packaging-steps.yml
Yi Zhang c5f5e3ec5e
Improve 2 cache tasks in one pipeline yaml (#15267)
### Description
1. Make 2 cache tasks in one pipeline really works
2. Each building step has its own environment variable CCACHE_DIR
instead of job variables.
3. Extenal Protobuf compilation cache only updates with deps.txt. It
doesn't generate new cache in every commit.


### Motivation and Context
The simple workflow is as below
```
--------build with ccache-------             
         |                       
        cache                    
         |                       
      {CCACHE_DIR}-----cache stat.
```

```
-------Cache@2------
           |
    download cache           
           |                         
          {path}--------upload cache
```

1. {XXX} means environment variable or task input.
2. {CCACHE_DIR} must be consistent with {path}. Ccache produces caches
in {CCACHE_DIR} and Cache@2 download cache into {path} and tar {path}
and upload it.
3. Protobuf changes with deps.txt so that it would reduce the storage
size.
4. Next step, we may split the compilation into 2 steps, one for
external dependencies and another for ORT.
2023-03-30 23:22:11 +08:00

93 lines
3.4 KiB
YAML

parameters:
- name: MacosArch
type: string
values:
- 'x86_64'
- 'arm64'
- 'universal2'
default: 'x86_64'
- name: AdditionalBuildFlags
displayName: Additional build flags for build.py
type: string
default: ''
- name: BuildJava
displayName: Build with Java
type: boolean
default: true
- name: BuildNodejs
displayName: Build with Nodejs
type: boolean
default: false
- name: WithCache
displayName: Build with Cache
type: boolean
default: false
- name: CacheDir
displayName: Cache Directory
type: string
default: ''
steps:
- script: |
rm -rf $(Build.BinariesDirectory)/Release
python3 $(Build.SourcesDirectory)/tools/ci_build/build.py --update --build ${{ parameters.AdditionalBuildFlags }} --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --parallel --build_shared_lib --config Release
displayName: 'Build ${{ parameters.MacosArch }}'
${{ if eq(parameters.WithCache, true) }}:
env:
CCACHE_DIR: ${{ parameters.CacheDir }}
- ${{ if eq(parameters.MacosArch, 'x86_64') }}:
- script: |
python3 $(Build.SourcesDirectory)/tools/ci_build/build.py --test ${{ parameters.AdditionalBuildFlags }} --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --parallel --build_shared_lib --config Release
displayName: 'Running Tests'
- task: ShellScript@2
displayName: 'Copy build artifacts for zipping'
inputs:
scriptPath: 'tools/ci_build/github/linux/copy_strip_binary.sh'
args: '-r $(Build.BinariesDirectory) -a onnxruntime-osx-${{ parameters.MacosArch }}-$(OnnxRuntimeVersion) -l libonnxruntime.$(OnnxRuntimeVersion).dylib -c Release -s $(Build.SourcesDirectory) -t $(Build.SourceVersion)'
workingDirectory: '$(Build.BinariesDirectory)/Release'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)/onnxruntime-osx-${{ parameters.MacosArch }}-$(OnnxRuntimeVersion)'
includeRootFolder: true
archiveType: 'tar' # Options: zip, 7z, tar, wim
tarCompression: 'gz'
archiveFile: '$(Build.ArtifactStagingDirectory)/onnxruntime-osx-${{ parameters.MacosArch }}-$(OnnxRuntimeVersion).tgz'
replaceExistingArchive: true
- script: |
set -e -x
mkdir -p $(Build.ArtifactStagingDirectory)/testdata
cp $(Build.BinariesDirectory)/Release/libcustom_op_library.dylib $(Build.ArtifactStagingDirectory)/testdata
displayName: 'Copy libcustom_op_library.dylib to ArtifactStagingDirectory'
condition: and(succeeded(), eq('${{ parameters.MacosArch }}', 'x86_64'))
- publish: '$(Build.ArtifactStagingDirectory)'
artifact: 'onnxruntime-osx-${{ parameters.MacosArch }}'
- ${{ if eq(parameters.BuildJava, true) }}:
- template: java-api-artifacts-package-and-publish-steps-posix.yml
parameters:
arch: 'osx-${{ parameters.MacosArch }}'
buildConfig: 'Release'
artifactName: 'onnxruntime-java-osx-${{ parameters.MacosArch }}'
version: '$(OnnxRuntimeVersion)'
libraryName: 'libonnxruntime.dylib'
nativeLibraryName: 'libonnxruntime4j_jni.dylib'
- ${{ if eq(parameters.BuildNodejs, true) }}:
- template: nodejs-artifacts-package-and-publish-steps-posix.yml
parameters:
${{ if eq(parameters.MacosArch, 'x86_64') }}:
arch: x64
${{ if eq(parameters.MacosArch, 'arm64') }}:
arch: arm64
os: 'darwin'
artifactName: 'drop-onnxruntime-nodejs-osx-${{ parameters.MacosArch }}'