Skip to content

Commit

Permalink
conan
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Jan 29, 2025
1 parent 0538fa7 commit 4fa1abd
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 0 deletions.
155 changes: 155 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,158 @@ jobs:
api-key: ${{ secrets.NUGET_DOT_ORG_API_KEY }}
if: startsWith(github.ref, 'refs/tags/')

##### conan - linux #####
conan-linux:
strategy:
fail-fast: false
matrix:
include:
- {os: debian, codename: bookworm, image_owner: }
# - {os: debian, codename: bookworm, image_owner: i386/, labels: [i386,docker]}
- {os: debian, codename: bookworm, image_owner: , labels: [arm32,docker]}
- {os: debian, codename: bookworm, image_owner: , labels: [arm64,docker]}
runs-on: ${{ (matrix.labels == '' && 'ubuntu-latest') || matrix.labels }}
container: ${{ matrix.image_owner }}${{ matrix.os }}:${{ matrix.codename }}
name: conan - linux | ${{ matrix.labels[0] }}
steps:
- name: add llvm repo (for clang-format)
uses: myci-actions/add-deb-repo@main
with:
repo: deb http://apt.llvm.org/${{ matrix.codename }} llvm-toolchain-${{ matrix.codename }} main
repo-name: llvm
keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key
install: clang-format clang-tidy
- name: add cppfw deb repo
uses: myci-actions/add-deb-repo@main
with:
repo: deb https://gagis.hopto.org/repo/cppfw/${{ matrix.os }} ${{ matrix.codename }} main
repo-name: cppfw
keys-asc: https://gagis.hopto.org/repo/cppfw/pubkey.gpg
install: devscripts equivs myci pipx cmake git
- name: add ~/.local/bin to PATH
uses: myci-actions/export-env-var@main
with: {name: PATH, value: "$PATH:$HOME/.local/bin"}
- name: install conan
run: pipx install conan
- name: create default conan profile
run: |
conan profile detect --name default
sed -i -E "s/compiler.cppstd=.*$/compiler.cppstd=17/g" ~/.conan2/profiles/default
- name: git clone
uses: myci-actions/checkout@main
- name: set PACKAGE_VERSION
uses: myci-actions/export-env-var@main
with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh debian/changelog)}
if: startsWith(github.ref, 'refs/tags/')
- name: build
run: |
conan remote add cppfw $MYCI_CONAN_REMOTE
conan create conan --build=missing --user $MYCI_CONAN_USER --channel main --version $PACKAGE_VERSION
- name: deploy conan package
run: |
conan remote login --password $MYCI_CONAN_PASSWORD cppfw $MYCI_CONAN_USER
conan upload --check --remote cppfw $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main
if: startsWith(github.ref, 'refs/tags/')
##### conan - macosx #####
conan-macosx:
strategy:
fail-fast: false
matrix:
os:
# - macos-10.15
# - macos-11
# - macos-12
- macos-latest
name: conan - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: workaround python2 and python3 issue when upgrading python
run : |
rm -rf /usr/local/bin/2to3*
rm -rf /usr/local/bin/idle3*
rm -rf /usr/local/bin/pydoc3*
rm -rf /usr/local/bin/python3
rm -rf /usr/local/bin/python3-config
rm -rf /usr/local/bin/python3*
rm -rf /usr/local/bin/python3*-config
- name: install clang-tidy and clang-format
run: |
brew install llvm
ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format"
ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
ln -s "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements"
- name: git clone
uses: myci-actions/checkout@main
- name: add cppfw tap
run: |
brew tap cppfw/tap
brew update
- name: install ci tools
run: brew install myci conan
- name: create default conan profile
run: |
conan profile detect --name default
sed -i -E "s/compiler.cppstd=.*$/compiler.cppstd=17/g" ~/.conan2/profiles/default
- name: set PACKAGE_VERSION
uses: myci-actions/export-env-var@main
with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh debian/changelog)}
if: startsWith(github.ref, 'refs/tags/')
- name: build
run: |
conan remote add cppfw $MYCI_CONAN_REMOTE
conan create conan --build=missing --user $MYCI_CONAN_USER --channel main --version $PACKAGE_VERSION
- name: deploy conan package
run: |
conan remote login --password $MYCI_CONAN_PASSWORD cppfw $MYCI_CONAN_USER
conan upload --check --remote cppfw $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main
if: startsWith(github.ref, 'refs/tags/')

##### conan - emscripten #####
conan-emscripten:
strategy:
fail-fast: false
matrix:
include:
# - {os: ubuntu, codename: noble, image_owner: }
- {os: debian, codename: bookworm, image_owner: }
# - {os: debian, codename: bookworm, image_owner: i386/, labels: [i386,docker]}
# - {os: debian, codename: bookworm, image_owner: , labels: [arm32,docker]}
# - {os: debian, codename: bookworm, image_owner: , labels: [arm64,docker]}
runs-on: ${{ (matrix.labels == '' && 'ubuntu-latest') || matrix.labels }}
container: ${{ matrix.image_owner }}${{ matrix.os }}:${{ matrix.codename }}
name: conan - emscripten | ${{ matrix.labels[0] }}
steps:
- name: add cppfw deb repo
uses: myci-actions/add-deb-repo@main
with:
repo: deb https://gagis.hopto.org/repo/cppfw/${{ matrix.os }} ${{ matrix.codename }} main
repo-name: cppfw
keys-asc: https://gagis.hopto.org/repo/cppfw/pubkey.gpg
install: devscripts equivs myci pipx cmake git nodejs
- name: add ~/.local/bin to PATH
uses: myci-actions/export-env-var@main
with: {name: PATH, value: "$PATH:$HOME/.local/bin"}
- name: install conan
run: pipx install conan
- name: create default conan profile
run: |
conan profile detect --name default
sed -i -E "s/compiler.cppstd=.*$/compiler.cppstd=17/g" ~/.conan2/profiles/default
- name: git clone
uses: myci-actions/checkout@main
with:
submodules: false
- name: set PACKAGE_VERSION
uses: myci-actions/export-env-var@main
with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh debian/changelog)}
if: startsWith(github.ref, 'refs/tags/')
- name: build
run: |
conan remote add cppfw $MYCI_CONAN_REMOTE
# NOTE: specifying empty test folder to skip the test stage
conan create conan --profile:build default --profile:host emscripten/conan.profile --build=missing --user $MYCI_CONAN_USER --channel main --version $PACKAGE_VERSION --test-folder ""
- name: deploy conan package
run: |
conan remote login --password $MYCI_CONAN_PASSWORD cppfw $MYCI_CONAN_USER
conan upload --check --remote cppfw $PACKAGE_NAME/$PACKAGE_VERSION@$MYCI_CONAN_USER/main
if: startsWith(github.ref, 'refs/tags/')
92 changes: 92 additions & 0 deletions conan/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import os
from conan import ConanFile
from conan.tools.scm import Git
from conan.tools.files import load, update_conandata, copy
from conan.tools.layout import basic_layout

class RuisConan(ConanFile):
name = "ruis"
license = "MIT"
author = "Ivan Gagis <igagis@gmail.com>"
url = "http://github.com/cppfw/" + name
description = "cross-platform GUI C++ library"
topics = ("C++", "cross-platform")
settings = "os", "compiler", "build_type", "arch"
package_type = "library"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
generators = "AutotoolsDeps" # this will set CXXFLAGS etc. env vars

def requirements(self):
self.requires("utki/[>=1.1.202]@cppfw/main", transitive_headers=True, transitive_libs=True)
self.requires("papki/[>=0.0.0]@cppfw/main", transitive_headers=True, transitive_libs=True)
self.requires("svgren/[>=0.0.0]@cppfw/main", transitive_headers=False, transitive_libs=True)
self.requires("rasterimage/[>=0.1.3]@cppfw/main", transitive_headers=True, transitive_libs=True)
self.requires("tml/[>=0.0.0]@cppfw/main", transitive_headers=True, transitive_libs=True)
self.requires("freetype/[>=0.0.0]", transitive_headers=False, transitive_libs=True)

def build_requirements(self):
if self.settings.os != "Emscripten":
self.requires("tst/[>=0.3.29]@cppfw/main", visible=False)
self.tool_requires("prorab/[>=2.0.27]@cppfw/main")
self.tool_requires("prorab-extra/[>=0.2.57]@cppfw/main")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

# save commit and remote URL to conandata.yml for packaging
def export(self):
git = Git(self)
scm_url = git.get_remote_url()
# NOTE: Git.get_commit() doesn't work properly,
# it gets latest commit of the folder in which conanfile.py resides.
# So, we use "git rev-parse HEAD" instead as it gets the actual HEAD
# commit regardless of the current working directory within the repo.
scm_commit = git.run("rev-parse HEAD") # get current commit
update_conandata(self, {"sources": {"commit": scm_commit, "url": scm_url}})

def source(self):
git = Git(self)
sources = self.conan_data["sources"]
# shallow fetch commit
git.fetch_commit(url=sources["url"], commit=sources['commit'])
# shallow clone submodules
git.run("submodule update --init --remote --depth 1")

def build(self):
if self.settings.os == "Emscripten":
self.run("make $MAKE_INCLUDE_DIRS_ARG config=wasm --directory=src")
else:
self.run("make $MAKE_INCLUDE_DIRS_ARG lint=off")
self.run("make $MAKE_INCLUDE_DIRS_ARG lint=off test")

def package(self):
if self.settings.os == "Emscripten":
src_rel_dir = os.path.join(self.build_folder, "src/out/wasm")
else:
src_rel_dir = os.path.join(self.build_folder, "src/out/rel")

src_dir = os.path.join(self.build_folder, "src")
dst_include_dir = os.path.join(self.package_folder, "include")
dst_lib_dir = os.path.join(self.package_folder, "lib")
dst_bin_dir = os.path.join(self.package_folder, "bin")
copy(conanfile=self, pattern="*.h", dst=dst_include_dir, src=src_dir, keep_path=True)
copy(conanfile=self, pattern="*.hpp", dst=dst_include_dir, src=src_dir, keep_path=True)

if self.options.shared:
copy(conanfile=self, pattern="*" + self.name + ".lib", dst=dst_lib_dir, src="", keep_path=False)
copy(conanfile=self, pattern="*.dll", dst=dst_bin_dir, src=src_rel_dir, keep_path=False)
copy(conanfile=self, pattern="*.so", dst=dst_lib_dir, src=src_rel_dir, keep_path=False)
copy(conanfile=self, pattern="*.so.*", dst=dst_lib_dir, src=src_rel_dir, keep_path=False)
copy(conanfile=self, pattern="*.dylib", dst=dst_lib_dir, src=src_rel_dir, keep_path=False)
else:
copy(conanfile=self, pattern="*" + self.name + ".lib", dst=dst_lib_dir, src="", keep_path=False)
copy(conanfile=self, pattern="*.a", dst=dst_lib_dir, src=src_rel_dir, keep_path=False)

def package_info(self):
self.cpp_info.libs = [self.name]

def package_id(self):
# change package id only when minor or major version changes, i.e. when ABI breaks
self.info.requires.minor_mode()
9 changes: 9 additions & 0 deletions conan/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

# set(CMAKE_VERBOSE_MAKEFILE on)

find_package(ruis CONFIG REQUIRED)

add_executable(example example.cpp)
target_link_libraries(example ruis::ruis)
22 changes: 22 additions & 0 deletions conan/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

from conan import ConanFile, tools
from conan.tools.cmake import CMake, cmake_layout

class TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps"

def requirements(self):
self.requires(self.tested_reference_str)

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

def layout(self):
cmake_layout(self)

def test(self):
self.run(".%sexample" % os.sep, env="conanrun") # env sets LD_LIBRARY_PATH etc. to find dependency libs
9 changes: 9 additions & 0 deletions conan/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <ruis/util/length.hpp>

int main(int argc, const char** argv){
ruis::length len(13);

std::cout << "hello ruis! len.is_undefined() = " << (len.is_undefined() ? "true" : "false") << std::endl;

return 0;
}
19 changes: 19 additions & 0 deletions config/wasm.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include $(config_dir)base/base.mk

this_cxxflags += -O3

this_cxx := em++
this_cc := emcc
this_ar := emar

this_static_lib_only = : true

# TODO: remove the warning suppression when the PR is merged
# Suppress version-check warning due to https://github.com/conan-io/conan-center-index/pull/26247
this_cxxflags += -Wno-version-check

this_cxxflags += -fwasm-exceptions
this_ldflags += -fwasm-exceptions

this_cxxflags += -pthread
this_ldflags += -pthread
10 changes: 10 additions & 0 deletions emscripten/conan.profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[settings]
os=Emscripten
arch=wasm
compiler=clang
compiler.version=15
compiler.libcxx=libc++
build_type=Release

[tool_requires]
emsdk/[>=3.1.72]

0 comments on commit 4fa1abd

Please sign in to comment.