steps:
- task: CMake@1
  displayName: 'CMake SEAL'
  inputs:
    workingDirectory: '$(Build.SourcesDirectory)'
    cmakeArgs: '-GXcode -DSEAL_BUILD_SEAL_C=ON -DSEAL_BUILD_STATIC_SEAL_C=ON -DCMAKE_SYSTEM_NAME=iOS "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" -C cmake/functions.iOS.cmake .'

- script: |
      cd $BUILD_SOURCESDIRECTORY
      xcodebuild -project SEAL.xcodeproj -sdk iphonesimulator -arch x86_64 -configuration ${{ parameters.configuration }} clean build
      mkdir -p $BUILD_SOURCESDIRECTORY/lib/x86_64
      cp $BUILD_SOURCESDIRECTORY/lib/${{ parameters.configuration }}/libseal*.a $BUILD_SOURCESDIRECTORY/lib/x86_64

      xcodebuild -project SEAL.xcodeproj -sdk iphoneos -arch arm64 -configuration ${{ parameters.configuration }} clean build
      mkdir -p $BUILD_SOURCESDIRECTORY/lib/arm64
      cp $BUILD_SOURCESDIRECTORY/lib/${{ parameters.configuration }}/libseal*.a $BUILD_SOURCESDIRECTORY/lib/arm64

      cd $BUILD_SOURCESDIRECTORY/lib
      echo Creating fat libraries
      lipo -create -output libseal.a x86_64/libseal-*.a arm64/libseal-*.a
      lipo -create -output libsealc.a x86_64/libsealc-*.a arm64/libsealc-*.a

      echo Architectures for libseal.a
      lipo -info libseal.a

      echo Architectures for libsealc.a
      lipo -info libsealc.a
  displayName: 'Build SEAL'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
  inputs:
      SourceFolder: '$(Build.SourcesDirectory)/lib'
      Contents: 'libseal*'
      TargetFolder: '$(Build.ArtifactStagingDirectory)/lib'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      artifactName: ${{ parameters.artifactName }}
