From fcaf3e60f7be6d4aaa5a6931435749066e5da83e Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Thu, 17 Jul 2025 21:30:09 +0200 Subject: [PATCH 01/13] Added a Conanfile for installation with Conan --- CMakeLists.txt | 14 ++++-- CMakeUserPresets.json | 9 ++++ README.md | 21 +++++++- conanfile.py | 110 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 CMakeUserPresets.json create mode 100644 conanfile.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 85237ce6..db34e93c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,10 +69,18 @@ endif() if (SQLGEN_SQLITE3) list(APPEND SQLGEN_SOURCES src/sqlgen_sqlite.cpp) - if (NOT TARGET unofficial-sqlite3) - find_package(unofficial-sqlite3 CONFIG REQUIRED) + + if (SQLGEN_USE_VCPKG) + if (NOT TARGET unofficial-sqlite3) + find_package(unofficial-sqlite3 CONFIG REQUIRED) + endif() + target_link_libraries(sqlgen PUBLIC unofficial::sqlite3::sqlite3) + else() + if (NOT TARGET unofficial-sqlite3) + find_package(SQLite3 CONFIG REQUIRED) + endif() + target_link_libraries(sqlgen PUBLIC SQLite::SQLite3) endif() - target_link_libraries(sqlgen PUBLIC unofficial::sqlite3::sqlite3) endif() find_package(reflectcpp CONFIG REQUIRED) diff --git a/CMakeUserPresets.json b/CMakeUserPresets.json new file mode 100644 index 00000000..71aeacec --- /dev/null +++ b/CMakeUserPresets.json @@ -0,0 +1,9 @@ +{ + "version": 4, + "vendor": { + "conan": {} + }, + "include": [ + "build/Release/generators/CMakePresets.json" + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 1e69519d..8f872df3 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Together, reflect-cpp and sqlgen enable reliable and efficient ETL pipelines. ## Quick Start -### Installation +### Installation using vcpkg 1. Make sure you have the required dependencies installed (skip this step on Windows): ```bash @@ -53,6 +53,25 @@ find_package(sqlgen REQUIRED) target_link_libraries(your_target PRIVATE sqlgen::sqlgen) ``` +### Installation using Conan + +1. Install Conan (assuming you have Python and pipx installed): + +```bash +pipx install conan +conan profile detect +``` + +For older versions of pip, you can also use `pip` instead of `pipx`. + +2. Install Conan (assuming you have Python and pipx installed): + +```bash +conan build . --build=missing -s compiler.cppstd=gnu20 +``` + +You can call `conan inspect .` to get an overview of the supported options. + ## Usage Examples ### Hello World diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 00000000..e49da652 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,110 @@ +from conan import ConanFile +from conan.tools.files import get, copy, rmdir +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps + + +from conan.tools.env import VirtualBuildEnv +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +from conan.errors import ConanInvalidConfiguration + +import os + +required_conan_version = ">=2.18.1" + + +class SQLGenConan(ConanFile): + name = "sqlgen" + description = "" + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/getml/sqlgen" + topics = ("postgres", "sqlite", "orm") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_postgres": [True, False], + "with_sqlite3": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "with_postgres": True, + "with_sqlite3": True, + } + + def config_options(self): + if self.settings.os == "Windows": + self.options.rm_safe("fPIC") + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def requirements(self): + self.requires("reflect-cpp/0.19.0") + if self.options.with_postgres: + self.requires("libpq/17.5", transitive_headers=True) + if self.options.with_sqlite3: + self.requires("sqlite3/3.49.1", transitive_headers=True) + + def build_requirements(self): + self.tool_requires("cmake/[>=3.23 <4]") + + def validate(self): + if self.settings.get_safe("compiler.cppstd"): + check_min_cppstd(self, self._min_cppstd) + + def layout(self): + cmake_layout(self, src_folder=".") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + env = VirtualBuildEnv(self) + env.generate() + deps = CMakeDeps(self) + deps.generate() + tc = CMakeToolchain(self) + tc.cache_variables["SQLGEN_BUILD_SHARED"] = self.options.shared + tc.cache_variables["SQLGEN_POSTGRES"] = self.options.with_postgres + tc.cache_variables["SQLGEN_SQLITE3"] = self.options.with_sqlite3 + tc.cache_variables["SQLGEN_USE_VCPKG"] = False + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy( + self, + pattern="LICENSE", + dst=os.path.join(self.package_folder, "licenses"), + src=self.source_folder, + ) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + + def package_info(self): + self.cpp_info.libs = ["sqlgen"] + + @property + def _min_cppstd(self): + return 20 + + @property + def _compilers_minimum_version(self): + return { + "Visual Studio": "17", + "msvc": "1938", + "gcc": "11", + "clang": "13", + "apple-clang": "15", + } From 3783a12ea2deeb78894cba48f706b57d67a82ed9 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Thu, 17 Jul 2025 21:44:06 +0200 Subject: [PATCH 02/13] Added the first pipeline for Conan --- .github/workflows/linux-cxx20-conan.yaml | 42 +++++++++++++++++++ ...inux-cxx20.yaml => linux-cxx20-vcpkg.yaml} | 2 +- ...acos-cxx20.yaml => macos-cxx20-vcpkg.yaml} | 2 +- ...ws-cxx20.yaml => windows-cxx20-vcpkg.yaml} | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/linux-cxx20-conan.yaml rename .github/workflows/{linux-cxx20.yaml => linux-cxx20-vcpkg.yaml} (99%) rename .github/workflows/{macos-cxx20.yaml => macos-cxx20-vcpkg.yaml} (99%) rename .github/workflows/{windows-cxx20.yaml => windows-cxx20-vcpkg.yaml} (98%) diff --git a/.github/workflows/linux-cxx20-conan.yaml b/.github/workflows/linux-cxx20-conan.yaml new file mode 100644 index 00000000..372d4138 --- /dev/null +++ b/.github/workflows/linux-cxx20-conan.yaml @@ -0,0 +1,42 @@ +name: linux-cxx20-conan + +on: [push] + +jobs: + linux: + strategy: + fail-fast: false + matrix: + include: + - compiler: llvm + compiler-version: 16 + - compiler: llvm + compiler-version: 18 + - compiler: gcc + compiler-version: 11 + additional-dep: "g++-11" + - compiler: gcc + compiler-version: 12 + - compiler: gcc + compiler-version: 14 + - compiler: llvm + compiler-version: 16 + - compiler: llvm + compiler-version: 18 + - compiler: gcc + compiler-version: 11 + additional-dep: "g++-11" + - compiler: gcc + compiler-version: 12 + - compiler: gcc + compiler-version: 14 + name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }}-${{ matrix.db }})" + runs-on: ubuntu-latest + steps: + - name: Install Conan + run: | + pipx install conan + conan profile detect + - name: Compile + run: | + conan build . --build=missing -s compiler.cppstd=gnu20 diff --git a/.github/workflows/linux-cxx20.yaml b/.github/workflows/linux-cxx20-vcpkg.yaml similarity index 99% rename from .github/workflows/linux-cxx20.yaml rename to .github/workflows/linux-cxx20-vcpkg.yaml index 558b2977..cf68a693 100644 --- a/.github/workflows/linux-cxx20.yaml +++ b/.github/workflows/linux-cxx20-vcpkg.yaml @@ -1,4 +1,4 @@ -name: linux-cxx20 +name: linux-cxx20-vcpkg on: [push] diff --git a/.github/workflows/macos-cxx20.yaml b/.github/workflows/macos-cxx20-vcpkg.yaml similarity index 99% rename from .github/workflows/macos-cxx20.yaml rename to .github/workflows/macos-cxx20-vcpkg.yaml index e62496a9..7b9e86a1 100644 --- a/.github/workflows/macos-cxx20.yaml +++ b/.github/workflows/macos-cxx20-vcpkg.yaml @@ -1,4 +1,4 @@ -name: macos-cxx20 +name: macos-cxx20-vcpkg on: [push] diff --git a/.github/workflows/windows-cxx20.yaml b/.github/workflows/windows-cxx20-vcpkg.yaml similarity index 98% rename from .github/workflows/windows-cxx20.yaml rename to .github/workflows/windows-cxx20-vcpkg.yaml index 266223ce..5987dd53 100644 --- a/.github/workflows/windows-cxx20.yaml +++ b/.github/workflows/windows-cxx20-vcpkg.yaml @@ -1,4 +1,4 @@ -name: windows-cxx20 +name: windows-cxx20-vcpkg on: [push] From bc7e1f81c699dc504b2c66557a68131feafff5ee Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Thu, 17 Jul 2025 21:52:41 +0200 Subject: [PATCH 03/13] Next attempt --- .github/workflows/linux-cxx20-conan.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux-cxx20-conan.yaml b/.github/workflows/linux-cxx20-conan.yaml index 372d4138..a26b02a9 100644 --- a/.github/workflows/linux-cxx20-conan.yaml +++ b/.github/workflows/linux-cxx20-conan.yaml @@ -30,7 +30,7 @@ jobs: compiler-version: 12 - compiler: gcc compiler-version: 14 - name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }}-${{ matrix.db }})" + name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }})" runs-on: ubuntu-latest steps: - name: Install Conan @@ -39,4 +39,4 @@ jobs: conan profile detect - name: Compile run: | - conan build . --build=missing -s compiler.cppstd=gnu20 + conan build .. --build=missing -s compiler.cppstd=gnu20 From dfc7fc2e33484cdab4a9307023315aabd075ec5e Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Thu, 17 Jul 2025 21:54:04 +0200 Subject: [PATCH 04/13] Run ls --- .github/workflows/linux-cxx20-conan.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux-cxx20-conan.yaml b/.github/workflows/linux-cxx20-conan.yaml index a26b02a9..b287793f 100644 --- a/.github/workflows/linux-cxx20-conan.yaml +++ b/.github/workflows/linux-cxx20-conan.yaml @@ -39,4 +39,5 @@ jobs: conan profile detect - name: Compile run: | - conan build .. --build=missing -s compiler.cppstd=gnu20 + ls + conan build . --build=missing -s compiler.cppstd=gnu20 From 2bf0faf5e668b372c8dab350de3380c6a364d554 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Thu, 17 Jul 2025 22:00:56 +0200 Subject: [PATCH 05/13] Another attempt --- .github/workflows/linux-cxx20-conan.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/linux-cxx20-conan.yaml b/.github/workflows/linux-cxx20-conan.yaml index b287793f..c0d8c3bb 100644 --- a/.github/workflows/linux-cxx20-conan.yaml +++ b/.github/workflows/linux-cxx20-conan.yaml @@ -38,6 +38,4 @@ jobs: pipx install conan conan profile detect - name: Compile - run: | - ls - conan build . --build=missing -s compiler.cppstd=gnu20 + run: conan build . --build=missing -s compiler.cppstd=gnu20 From f1aa899855691f77272b3341ecec0badd23d681b Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Thu, 17 Jul 2025 22:03:33 +0200 Subject: [PATCH 06/13] Install dependencies --- .github/workflows/linux-cxx20-conan.yaml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux-cxx20-conan.yaml b/.github/workflows/linux-cxx20-conan.yaml index c0d8c3bb..5db3e3ba 100644 --- a/.github/workflows/linux-cxx20-conan.yaml +++ b/.github/workflows/linux-cxx20-conan.yaml @@ -33,9 +33,24 @@ jobs: name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }})" runs-on: ubuntu-latest steps: + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y ninja-build pipx ${{ matrix.additional-dep }} - name: Install Conan run: | pipx install conan conan profile detect - name: Compile - run: conan build . --build=missing -s compiler.cppstd=gnu20 + run: | + if [[ "${{ matrix.compiler }}" == "llvm" ]]; then + export CC=clang-${{ matrix.compiler-version }} + export CXX=clang++-${{ matrix.compiler-version }} + elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then + export CC=gcc-${{ matrix.compiler-version }} + export CXX=g++-${{ matrix.compiler-version }} + fi + sudo ln -s $(which ccache) /usr/local/bin/$CC + sudo ln -s $(which ccache) /usr/local/bin/$CXX + $CXX --version + conan build . --build=missing -s compiler.cppstd=gnu20 From 1998a4f90ea0d1260d3ed2e8c02ef359903eae25 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Thu, 17 Jul 2025 22:06:53 +0200 Subject: [PATCH 07/13] Checkout repo --- .github/workflows/linux-cxx20-conan.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/linux-cxx20-conan.yaml b/.github/workflows/linux-cxx20-conan.yaml index 5db3e3ba..ecff4ea8 100644 --- a/.github/workflows/linux-cxx20-conan.yaml +++ b/.github/workflows/linux-cxx20-conan.yaml @@ -33,6 +33,11 @@ jobs: name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }})" runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 - name: Install dependencies run: | sudo apt update From 42194210d897d55a7b8e9f9bb60990eda74387f9 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Fri, 18 Jul 2025 21:51:40 +0200 Subject: [PATCH 08/13] Bugfix --- .github/workflows/linux-cxx20-conan.yaml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/linux-cxx20-conan.yaml b/.github/workflows/linux-cxx20-conan.yaml index ecff4ea8..88cef675 100644 --- a/.github/workflows/linux-cxx20-conan.yaml +++ b/.github/workflows/linux-cxx20-conan.yaml @@ -19,17 +19,6 @@ jobs: compiler-version: 12 - compiler: gcc compiler-version: 14 - - compiler: llvm - compiler-version: 16 - - compiler: llvm - compiler-version: 18 - - compiler: gcc - compiler-version: 11 - additional-dep: "g++-11" - - compiler: gcc - compiler-version: 12 - - compiler: gcc - compiler-version: 14 name: "${{ github.job }} (${{ matrix.compiler }}-${{ matrix.compiler-version }})" runs-on: ubuntu-latest steps: From 332ed38cc9a104505faf8df3e5e7ec5665b44262 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Fri, 18 Jul 2025 21:51:50 +0200 Subject: [PATCH 09/13] Added macOS Conan actions pipeline --- .github/workflows/macos-cxx20-conan.yaml | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/macos-cxx20-conan.yaml diff --git a/.github/workflows/macos-cxx20-conan.yaml b/.github/workflows/macos-cxx20-conan.yaml new file mode 100644 index 00000000..cd4bbf26 --- /dev/null +++ b/.github/workflows/macos-cxx20-conan.yaml @@ -0,0 +1,34 @@ +name: macos-cxx20-conan + +on: [push] + +jobs: + macos-clang: + strategy: + fail-fast: false + matrix: + include: + - os: "macos-latest" + - os: "macos-13" + name: "${{ github.job }} (${{ matrix.os }}-${{ matrix.db }})" + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + - name: Install dependencies + run: | + run: brew install ninja pipx + - name: Install Conan + run: | + pipx install conan + conan profile detect + - name: Compile + env: + CC: clang + CXX: clang++ + run: | + $CXX --version + conan build . --build=missing -s compiler.cppstd=gnu20 From 42df34f39b24907317b634ccf8131dae10eedda8 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Fri, 18 Jul 2025 21:51:53 +0200 Subject: [PATCH 10/13] fi --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f872df3..dff7bcc1 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ conan profile detect For older versions of pip, you can also use `pip` instead of `pipx`. -2. Install Conan (assuming you have Python and pipx installed): +2. Build the library: ```bash conan build . --build=missing -s compiler.cppstd=gnu20 From 70bc129e61ded26099ecbb3ddc4709000c41d2b1 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Fri, 18 Jul 2025 21:52:14 +0200 Subject: [PATCH 11/13] Added description in the Conanfile --- conanfile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conanfile.py b/conanfile.py index e49da652..d24bcf44 100644 --- a/conanfile.py +++ b/conanfile.py @@ -15,7 +15,7 @@ class SQLGenConan(ConanFile): name = "sqlgen" - description = "" + description = "sqlgen is an ORM and SQL query generator for C++-20, similar to Python's SQLAlchemy/SQLModel or Rust's Diesel." license = "MIT" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/getml/sqlgen" @@ -47,9 +47,9 @@ def configure(self): def requirements(self): self.requires("reflect-cpp/0.19.0") if self.options.with_postgres: - self.requires("libpq/17.5", transitive_headers=True) + self.requires("libpq/17.5") if self.options.with_sqlite3: - self.requires("sqlite3/3.49.1", transitive_headers=True) + self.requires("sqlite3/3.49.1") def build_requirements(self): self.tool_requires("cmake/[>=3.23 <4]") From a1fa578b9008027097c4ac74f93039eb2a9eec45 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Fri, 18 Jul 2025 22:06:38 +0200 Subject: [PATCH 12/13] Fixed typo --- .github/workflows/macos-cxx20-conan.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos-cxx20-conan.yaml b/.github/workflows/macos-cxx20-conan.yaml index cd4bbf26..b15027d0 100644 --- a/.github/workflows/macos-cxx20-conan.yaml +++ b/.github/workflows/macos-cxx20-conan.yaml @@ -10,7 +10,7 @@ jobs: include: - os: "macos-latest" - os: "macos-13" - name: "${{ github.job }} (${{ matrix.os }}-${{ matrix.db }})" + name: "${{ github.job }} (${{ matrix.os }})" runs-on: ${{ matrix.os }} steps: - name: Checkout From 3a600695bd88c6a3f9e0c42179e382a1cdf2719f Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Fri, 18 Jul 2025 22:19:04 +0200 Subject: [PATCH 13/13] Removed duplicate run --- .github/workflows/macos-cxx20-conan.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/macos-cxx20-conan.yaml b/.github/workflows/macos-cxx20-conan.yaml index b15027d0..5ee3527f 100644 --- a/.github/workflows/macos-cxx20-conan.yaml +++ b/.github/workflows/macos-cxx20-conan.yaml @@ -19,7 +19,6 @@ jobs: submodules: recursive fetch-depth: 0 - name: Install dependencies - run: | run: brew install ninja pipx - name: Install Conan run: |