# How to avoid rebuilding ITK by azure CI at the GitHub of another project (elastix)?

**URL:** <https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002>\
**Category:** Engineering\
**Created:** [June 28, 2019, 11:13am UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002 "2019-06-28T11:13:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)\
**Post date:** [June 28, 2019, 11:13am UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/1 "2019-06-28T11:13:16Z")

</div>

Our image registration toolkit [elastix](https://github.com/SuperElastix/elastix) is being built with a specific tagged version of ITK5 (actually v5.0.0), at [https://dev.azure.com/kaspermarstal/Elastix/\_build/results?buildId=458](https://dev.azure.com/kaspermarstal/Elastix/_build/results?buildId=458)

As you see, a Windows build of elastix takes more than an hour, and more that 20 minutes thereof comes from generating (by CMake) and building ITK.

Do you have a suggestion how to avoid rebuilding ITK with each elastix build at the CI?

I did have a look at [https://github.com/microsoft/azure-pipelines-artifact-caching-tasks](https://github.com/microsoft/azure-pipelines-artifact-caching-tasks) but I don’t yet fully understand how to adjust [our azure-pipeline yml file](https://github.com/SuperElastix/elastix/blob/95e527a6e074732f8c31703cb7b7085926e5ae34/Testing/CI/Azure/ci.yml) to get it working! Do you?

Another option could be to use prebuilt ITK binaries. Are these available already somewhere, at a location where accessible by azure CI?

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [June 29, 2019, 6:01pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/2 "2019-06-29T18:01:13Z")

</div>

> [@Niels\_Dekker](#):
>
> Our image registration toolkit [elastix](https://github.com/SuperElastix/elastix) is being built with a specific tagged version of ITK5 (actually v5.0.0), at [https://dev.azure.com/kaspermarstal/Elastix/\_build/results?buildId=458](https://dev.azure.com/kaspermarstal/Elastix/_build/results?buildId=458)

Woohoo! 🎉 💚

> [@Niels\_Dekker](#):
>
> I did have a look at [GitHub - microsoft/azure-pipelines-artifact-caching-tasks: Azure Pipelines Tasks to cache intermediate artifacts from build (e.g. resolved node packages)](https://github.com/microsoft/azure-pipelines-artifact-caching-tasks) but I don’t yet fully understand how to adjust [our azure-pipeline yml file](https://github.com/SuperElastix/elastix/blob/95e527a6e074732f8c31703cb7b7085926e5ae34/Testing/CI/Azure/ci.yml) to get it working! Do you?

In addition, the Azure Pipelines team is in the process of rolling out a feature called [Pipeline Caching](https://devblogs.microsoft.com/devops/adding-caching-to-azure-pipelines/). The are [just starting to roll it out](https://github.com/Microsoft/azure-pipelines-yaml/pull/113), so it may be an option, soon.

Another approach is be to use Azure Pipelines Artifacts with an ITK vcpkg (@dzenanz has contributed to this package configuration) generated binary. [This example may help](https://github.com/GenericMappingTools/gmt/pull/731/files).

---

<div class="post-metadata">

**Author:** ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)\
**Post date:** [July 2, 2019, 4:43pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/3 "2019-07-02T16:43:28Z")

</div>

Thanks for your help so far @matt.mccormick I do like the option to use generated binaries for VS2017 (64-bit Release) but I still don’t really understand how. Currently we build ITK as follows, at [elastix/Testing/CI/Azure/ci.yml](https://github.com/SuperElastix/elastix/blob/95e527a6e074732f8c31703cb7b7085926e5ae34/Testing/CI/Azure/ci.yml#L21):

```
- script: |
    git clone https://github.com/InsightSoftwareConsortium/ITK "$(ITK_SOURCE_DIR)"
    pushd "$(ITK_SOURCE_DIR)"
    git checkout $(itk.version)
    popd
  displayName: Clone ITK
- script: |
    mkdir "$(ITK_BINARY_DIR)"
    mkdir "$(ELASTIX_BINARY_DIR)"
  displayName: Make build directories
- task: CMake@1
  displayName: 'CMake Generate ITK'
  inputs:
    cmakeArgs: -G "Visual Studio 15 2017 Win64" -T host=x64 -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=OFF "$(ITK_SOURCE_DIR)"
    workingDirectory: "$(ITK_BINARY_DIR)"
- task: CMake@1
  displayName: 'CMake Build ITK'
  inputs:
    cmakeArgs: --build . --config Release -j 2
    workingDirectory: "$(ITK_BINARY_DIR)"

```

How could this be replaced by using generated ITK 5.0.0 binaries from vcpkg?

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [July 2, 2019, 6:38pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/4 "2019-07-02T18:38:59Z")

</div>

vcpkg has the ability to export a built package:

- [https://devblogs.microsoft.com/cppblog/vcpkg-introducing-export-command/](https://devblogs.microsoft.com/cppblog/vcpkg-introducing-export-command/)
- [https://vcpkg.readthedocs.io/en/latest/specifications/export-command/](https://vcpkg.readthedocs.io/en/latest/specifications/export-command/)

The package comes with a [`CMAKE_TOOLCHAIN_FILE`](https://cmake.org/cmake/help/v3.15/variable/CMAKE_TOOLCHAIN_FILE.html?highlight=cmake_toolchain_file). We need to use this file for the elastix build so the compiler, toolchain, and relevant build settings are used to ensure the binaries are compatible. Set `ITK_DIR` to the vcpkg _ITKConfig.cmake_ file path and _CMAKE\_TOOLCHAIN\_FILE_ to the vcpkg file. A related section of the example:

> <https://github.com/GenericMappingTools/gmt/pull/731/files#diff-a20b398b655fb4414db6f43c3aa3be29R57>

---

<div class="post-metadata">

**Author:** ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)\
**Post date:** [July 8, 2019, 6:08pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/5 "2019-07-08T18:08:22Z")

</div>

Thanks Matt! I’m still studying vcpkg, but I’m making some progress! I’ll let you know when I got it working!

---

<div class="post-metadata">

**Author:** ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)\
**Post date:** [July 11, 2019, 3:22pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/6 "2019-07-11T15:22:21Z")

</div>

The current version of [elastix](https://github.com/SuperElastix/elastix) (git develop branch) still depends on the legacy interface of ITK 5. Unfortunately, [the ITK portfile at github.com/microsoft/vcpkg](https://github.com/microsoft/vcpkg/blob/47d206e149e88201333b5ca8fe55c30e2b1a8177/ports/itk/portfile.cmake) removes the legacy support (`ITK_LEGACY_REMOVE=ON`):

Does this mean that currently, elastix cannot yet use vcpkg, on github azure CI?

Here is the azure-pipelines yml file I adapted in order to use vcpkg ([elastix PR 161](https://github.com/SuperElastix/elastix/pull/161)):

> <https://github.com/SuperElastix/elastix/blob/63fd73e07d9a34cd72c4d6a4a6ec0b1140a39ae9/Testing/CI/Azure/ci.yml>

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [July 11, 2019, 3:32pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/7 "2019-07-11T15:32:29Z")

</div>

ITK port is far from set in stone. Make a PR which flips the legacy [on](https://github.com/microsoft/vcpkg/blob/47d206e149e88201333b5ca8fe55c30e2b1a8177/ports/itk/portfile.cmake#L38).

The legacy there is off because I like to turn it off in order to avoid new features depending on legacy stuff. But for general use including legacy stuff should be beneficial.

---

<div class="post-metadata">

**Author:** ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)\
**Post date:** [July 11, 2019, 3:45pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/8 "2019-07-11T15:45:35Z")

</div>

@dzenanz Instead of explicitly turning the flag on or off, at [https://github.com/microsoft/vcpkg/ports/itk/portfile.cmake](https://github.com/microsoft/vcpkg/ports/itk/portfile.cmake) what do you think of leaving it to its default? (In practice that does mean legacy support for ITK 5.0.0.)

In general I would expect ITK from vcpkg to behave very much as if it was configured with default settings. What do you think?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [July 11, 2019, 4:42pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/9 "2019-07-11T16:42:46Z")

</div>

> [@Niels\_Dekker](#):
>
> … leaving it to its default

Sounds even better!

---

<div class="post-metadata">

**Author:** ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)\
**Post date:** [July 11, 2019, 6:53pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/10 "2019-07-11T18:53:22Z")

</div>

> [@dzenanz](#):
>
> Sounds even better!

Thanks @dzenanz! Please check:

> <https://github.com/microsoft/vcpkg/pull/7241>
>
> No longer specify \`ITK\_LEGACY\_REMOVE\` and \`ITK\_FUTURE\_LEGACY\_REMOVE\`
> options fo…r \`vcpkg\_configure\_cmake\`. By default, these two flags are
> \`OFF\`, for ITK 5.0.0:
> https://github.com/InsightSoftwareConsortium/ITK/blob/v5.0.0/CMakeLists.txt#L261
> 
> This commit will allow legacy ITK user code to build with vcpkg, and it
> will ease adding vcpkg support to https://github.com/SuperElastix/elastix
> 
> Dženan Zukić @dzenanz suggested this change:
> https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/7
> 
> CONTROL version bumped as requested by Phil Christensen @Rastaban

---

<div class="post-metadata">

**Author:** ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)\
**Post date:** [July 12, 2019, 2:05pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/11 "2019-07-12T14:05:50Z")

</div>

Suppose one would need ITK built with different CMake options than another? (For example, suppose you would really need to have `ITK_LEGACY_REMOVE=ON`, while elastix needs to have the option `OFF`.) Could that possibly be supported by vcpkg?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [July 12, 2019, 2:13pm UTC](https://discourse.itk.org/t/how-to-avoid-rebuilding-itk-by-azure-ci-at-the-github-of-another-project-elastix/2002/12 "2019-07-12T14:13:44Z")

</div>

I don’t think so, but this question is probably better for `vcpkg` people.
