Skip to content

Commit

Permalink
Use Conan v2
Browse files Browse the repository at this point in the history
Contribute to CURA-11622
  • Loading branch information
jellespijker committed Feb 12, 2024
1 parent a1ac15d commit 3d7705f
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 176 deletions.
226 changes: 73 additions & 153 deletions .github/workflows/conan-package.yml
Original file line number Diff line number Diff line change
@@ -1,158 +1,78 @@
---
name: conan-package

# Exports the recipe, sources and binaries for Mac, Windows and Linux and upload these to the server such that these can
# be used downstream.
#
# It should run on pushes against main or CURA-* branches, but it will only create the binaries for main and release branches

on:
workflow_dispatch:
inputs:
# FIXME: Not yet implemented
conan_id:
required: false
type: string
description: 'The full conan package ID, e.g. "libnest2d/1.2.3@ultimaker/stable"'
create_latest_alias:
required: true
default: false
type: boolean
description: 'Create latest alias'
create_binaries_windows:
required: true
default: false
type: boolean
description: 'create binaries Windows'
create_binaries_linux:
required: true
default: false
type: boolean
description: 'create binaries Linux'
create_binaries_macos:
required: true
default: false
type: boolean
description: 'create binaries Macos'

push:
paths:
- 'src/**'
- 'include/**'
- 'test_package/**'
- 'tests/**'
- 'cmake/**'
- 'conanfile.py'
- 'conandata.yml'
- 'CMakeLists.txt'
- '.github/workflows/conan-package.yml'
- '.github/workflows/requirements*'
branches:
- main
- master
- 'CURA-*'
- '[0-9].[0-9]'
- '[0-9].[0-9][0-9]'
tags:
- '[0-9].[0-9].[0-9]*'
- '[0-9].[0-9][0-9].[0-9]*'
push:
paths:
- 'src/**'
- 'include/**'
- 'test_package/**'
- 'tests/**'
- 'conanfile.py'
- 'conandata.yml'
- 'CMakeLists.txt'
- '.github/workflows/conan-package.yml'
- '.github/workflows/requirements*'
branches:
- main
- 'CURA-*'
- 'PP-*'
- '[0-9].[0-9]*'
- '[0-9].[0-9][0-9]*'

jobs:
conan-recipe-version:
uses: ultimaker/cura/.github/workflows/conan-recipe-version.yml@main
with:
project_name: savitar

conan-package-export:
needs: [ conan-recipe-version ]
uses: ultimaker/cura/.github/workflows/conan-recipe-export.yml@main
with:
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
recipe_id_latest: ${{ needs.conan-recipe-version.outputs.recipe_id_latest }}
runs_on: 'ubuntu-20.04'
python_version: '3.10.x'
conan_logging_level: 'info'
secrets: inherit

conan-package-create-windows:
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true' )) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_windows) }}
needs: [ conan-recipe-version, conan-package-export ]

uses: ultimaker/cura/.github/workflows/conan-package-create.yml@main
with:
project_name: ${{ needs.conan-recipe-version.outputs.project_name }}
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
build_id: 4
runs_on: 'windows-2022'
python_version: '3.10.x'
conan_config_branch: ''
conan_logging_level: 'info'
secrets: inherit

conan-package-create-macos:
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_macos) }}
needs: [ conan-recipe-version, conan-package-export ]

uses: ultimaker/cura/.github/workflows/conan-package-create.yml@main
with:
project_name: ${{ needs.conan-recipe-version.outputs.project_name }}
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
build_id: 3
runs_on: 'macos-11'
python_version: '3.10.x'
conan_logging_level: 'info'
secrets: inherit

conan-package-create-linux-modern:
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_linux) }}
needs: [ conan-recipe-version, conan-package-export ]

uses: ultimaker/cura/.github/workflows/conan-package-create.yml@main
with:
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
project_name: ${{ needs.conan-recipe-version.outputs.project_name }}
build_id: 2
runs_on: 'ubuntu-22.04'
python_version: '3.10.x'
conan_logging_level: 'info'
secrets: inherit

conan-package-create-linux:
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_linux) }}
needs: [ conan-recipe-version, conan-package-export ]

uses: ultimaker/cura/.github/workflows/conan-package-create.yml@main
with:
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
project_name: ${{ needs.conan-recipe-version.outputs.project_name }}
build_id: 1
runs_on: 'ubuntu-20.04'
python_version: '3.10.x'
conan_logging_level: 'info'
secrets: inherit

notify-export:
if: ${{ always() }}
needs: [ conan-recipe-version, conan-package-export ]

uses: ultimaker/cura/.github/workflows/notify.yml@main
with:
success: ${{ contains(join(needs.*.result, ','), 'success') }}
success_title: "New Conan recipe exported in ${{ github.repository }}"
success_body: "Exported ${{ needs.conan-recipe-version.outputs.recipe_id_full }}"
failure_title: "Failed to export Conan Export in ${{ github.repository }}"
failure_body: "Failed to exported ${{ needs.conan-recipe-version.outputs.recipe_id_full }}"
secrets: inherit

notify-create:
if: ${{ always() && ((github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) || (github.event_name == 'workflow_dispatch' && inputs.create_binaries_linux)) }}
needs: [ conan-recipe-version, conan-package-create-macos, conan-package-create-windows, conan-package-create-linux, conan-package-create-linux-modern ]

uses: ultimaker/cura/.github/workflows/notify.yml@main
with:
success: ${{ contains(join(needs.*.result, ','), 'success') }}
success_title: "New binaries created in ${{ github.repository }}"
success_body: "Created binaries for ${{ needs.conan-recipe-version.outputs.recipe_id_full }}"
failure_title: "Failed to create binaries in ${{ github.repository }}"
failure_body: "Failed to created binaries for ${{ needs.conan-recipe-version.outputs.recipe_id_full }}"
secrets: inherit
# FIXME: Use main once merged
conan-recipe-version:
uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-version.yml@CURA-11622_conan_v2
with:
project_name: savitar

# FIXME: Use main once merged
conan-package-export:
needs: [ conan-recipe-version ]
uses: ultimaker/cura-workflows/.github/workflows/conan-recipe-export.yml@CURA-11622_conan_v2
with:
recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }}
recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }}
recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }}
recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }}
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
secrets: inherit

# FIXME: Use main once merged
conan-package-create-macos:
needs: [ conan-recipe-version, conan-package-export ]
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }}
uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-macos.yml@CURA-11622_conan_v2
with:
recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }}
recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }}
recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }}
recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }}
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
secrets: inherit

# FIXME: Use main once merged
conan-package-create-windows:
needs: [ conan-recipe-version, conan-package-export ]
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }}
uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-windows.yml@CURA-11622_conan_v2
with:
recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }}
recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }}
recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }}
recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }}
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
secrets: inherit

# FIXME: Use main once merged
conan-package-create-linux:
needs: [ conan-recipe-version, conan-package-export ]
if: ${{ (github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || needs.conan-recipe-version.outputs.is_release_branch == 'true')) }}
uses: ultimaker/cura-workflows/.github/workflows/conan-package-create-linux.yml@CURA-11622_conan_v2
with:
recipe_id_name: ${{ needs.conan-recipe-version.outputs.project_name }}
recipe_id_version: ${{ needs.conan-recipe-version.outputs.recipe_semver_full }}
recipe_id_user: ${{ needs.conan-recipe-version.outputs.user }}
recipe_id_channel: ${{ needs.conan-recipe-version.outputs.channel }}
recipe_id_full: ${{ needs.conan-recipe-version.outputs.recipe_id_full }}
secrets: inherit
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,33 @@ CMakeUserPresets.json
/conaninfo.txt
build/
test_package/build
/test_package/savitar-config.cmake
/test_package/pugixml-config.cmake
/test_package/CMakeFiles/
/test_package/CMakePresets.json
/test_package/test
/test_package/metadata/
/test_package/pugixml-config-version.cmake
/test_package/conanrunenv-release-x86_64.sh
/test_package/deactivate_conanrunenv-release-x86_64.sh
/test_package/deactivate_conanbuildenv-release-x86_64.sh
/test_package/deactivate_conanrun.sh
/test_package/savitar-config-version.cmake
/test_package/deactivate_conanbuild.sh
/test_package/.ninja_log
/test_package/build.ninja
/test_package/cmakedeps_macros.cmake
/test_package/savitarTargets.cmake
/test_package/pugixml-release-x86_64-data.cmake
/test_package/conandeps_legacy.cmake
/test_package/savitar-Target-release.cmake
/test_package/pugixml-Target-release.cmake
/test_package/conanbuild.sh
/test_package/conan_toolchain.cmake
/test_package/conanrun.sh
/test_package/pugixmlTargets.cmake
/test_package/CMakeCache.txt
/test_package/conanbuildenv-release-x86_64.sh
/test_package/cmake_install.cmake
/test_package/.ninja_deps
/test_package/savitar-release-x86_64-data.cmake
1 change: 1 addition & 0 deletions conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: "5.4.0-alpha.0"
34 changes: 18 additions & 16 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from os import path

import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import AutoPackager, copy
from conan.tools.files import AutoPackager, copy, update_conandata
from conan.tools.build import check_min_cppstd
from conan.tools.microsoft import check_min_vs, is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version

from conan.tools.scm import Version, Git

required_conan_version = ">=1.56.0"
required_conan_version = ">=1.58.0"


class SavitarConan(ConanFile):
Expand All @@ -22,9 +20,9 @@ class SavitarConan(ConanFile):
description = "libSavitar is a c++ implementation of 3mf loading with SIP python bindings"
topics = ("conan", "cura", "3mf", "c++")
settings = "os", "compiler", "build_type", "arch"
revision_mode = "scm"
exports = "LICENSE*"
generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv"
generators = "VirtualRunEnv"
package_type = "library"

options = {
"shared": [True, False],
Expand All @@ -38,8 +36,12 @@ class SavitarConan(ConanFile):
}

def set_version(self):
if self.version is None:
self.version = "5.4.0-alpha"
if not self.version:
self.version = self.conan_data["version"]

def export(self):
git = Git(self)
update_conandata(self, {"version": self.version, "commit": git.get_commit()})

@property
def _min_cppstd(self):
Expand All @@ -57,9 +59,9 @@ def _compilers_minimum_version(self):

def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
copy(self, "*", path.join(self.recipe_folder, "src"), path.join(self.export_sources_folder, "src"))
copy(self, "*", path.join(self.recipe_folder, "include"), path.join(self.export_sources_folder, "include"))
copy(self, "*", path.join(self.recipe_folder, "tests"), path.join(self.export_sources_folder, "tests"))
copy(self, "*", os.path.join(self.recipe_folder, "src"), os.path.join(self.export_sources_folder, "src"))
copy(self, "*", os.path.join(self.recipe_folder, "include"), os.path.join(self.export_sources_folder, "include"))
copy(self, "*", os.path.join(self.recipe_folder, "tests"), os.path.join(self.export_sources_folder, "tests"))

def layout(self):
cmake_layout(self)
Expand All @@ -69,7 +71,7 @@ def layout(self):
self.cpp.package.defines = ["SAVITAR_DEBUG"]

def requirements(self):
self.requires("pugixml/1.12.1", transitive_headers=True)
self.requires("pugixml/1.14", transitive_headers=True)

def validate(self):
if self.settings.compiler.cppstd:
Expand All @@ -83,9 +85,9 @@ def validate(self):
)

def build_requirements(self):
self.test_requires("standardprojectsettings/[>=0.1.0]@ultimaker/stable")
self.test_requires("standardprojectsettings/[>=0.2.0]@ultimaker/cura_11622") # FIXME: use stable after merge
if self.options.enable_testing:
self.test_requires("gtest/1.12.1")
self.test_requires("gtest/1.14.0")

def config_options(self):
if self.settings.os == "Windows":
Expand Down
4 changes: 1 addition & 3 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ add_executable(test test.cpp)
target_link_libraries(test
PUBLIC
savitar::savitar
)

#target_include_directories(test PRIVATE ${Savitar_INCLUDE_DIRS})
)
6 changes: 2 additions & 4 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class SavitarTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
Expand All @@ -25,16 +24,15 @@ def generate(self):

for dep in self.dependencies.values():
for bin_dir in dep.cpp_info.bindirs:
copy(self, "*.dll", src = bin_dir, dst = self.build_folder)
copy(self, "*.dll", src=bin_dir, dst=self.build_folder)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()


def test(self):
if can_run(self):
ext = ".exe" if self.settings.os == "Windows" else ""
prefix_path = "" if self.settings.os == "Windows" else "./"
self.run(f"{prefix_path}test{ext}", env = "conanrun")
self.run(f"{prefix_path}test{ext}", env="conanrun")

0 comments on commit 3d7705f

Please sign in to comment.