xmake.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package("sqlgen")
  2. set_homepage("https://github.com/getml/sqlgen")
  3. set_description("sqlgen is an ORM and SQL query generator for C++-20, similar to Python's SQLAlchemy/SQLModel or Rust's Diesel.")
  4. set_license("MIT")
  5. add_urls("https://github.com/getml/sqlgen/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/getml/sqlgen.git")
  7. add_versions("v0.6.0", "a872fdcbca290f0dd0e57905e032d676b0c1911b307573e9183d6fa5f37c21f2")
  8. add_versions("v0.2.0", "c093036ebdf2aaf1003b2d1623713b97106ed43b1d39dc3d4f38e381f371799e")
  9. add_patches("0.6.0", "patches/0.6.0/cmake.patch", "d118f07af7392d2268e0530cf90f1f36aa0a7836391a2950d24829ad0950d3c9")
  10. add_patches("0.2.0", "patches/0.2.0/cmake.patch", "e9819b9a8a2c8f8a5b6c553eac3bb10fc65856aa9af451f83e2dbf55ca6c66c0")
  11. add_deps("cmake", "reflect-cpp")
  12. add_configs("mysql", {description = "Enable MySQL Support", default = false, type = "boolean", readonly = true})
  13. add_configs("postgres", {description = "Enable PostgreSQL Support", default = true, type = "boolean"})
  14. add_configs("sqlite", {description = "Enable SQLite Support", default = true, type = "boolean"})
  15. add_configs("duckdb", {description = "Enable DuckDB Support", default = true, type = "boolean"})
  16. if is_plat("windows") then
  17. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  18. end
  19. on_load(function (package)
  20. if package:config("mysql") then
  21. package:add("deps", "mariadb-connector-c")
  22. end
  23. if package:config("postgres") then
  24. package:add("deps", "libpq")
  25. end
  26. if package:config("sqlite") then
  27. package:add("deps", "sqlite3")
  28. end
  29. if package:config("duckdb") then
  30. package:add("deps", "duckdb >=1.4.2")
  31. end
  32. end)
  33. on_check(function (package)
  34. if package:config("postgres") then
  35. assert(not package:is_arch("arm64"), "package(sqlgen) deps(libpq): does not support arm64")
  36. end
  37. if package:config("duckdb") then
  38. assert(package:version():ge("0.5.0"), "package(sqlgen) deps(duckdb): only version >= 0.5.0 supports DuckDB")
  39. assert(package:is_plat("linux", "macosx"), "package(sqlgen) deps(duckdb): only supports macOS and Linux")
  40. end
  41. end)
  42. on_install("windows", "macosx", "linux", "bsd", function (package)
  43. local configs = {
  44. "-DSQLGEN_USE_VCPKG=OFF",
  45. }
  46. table.insert(configs, "-DSQLGEN_MYSQL=" .. (package:config("mysql") and "ON" or "OFF"))
  47. table.insert(configs, "-DSQLGEN_POSTGRES=" .. (package:config("postgres") and "ON" or "OFF"))
  48. table.insert(configs, "-DSQLGEN_SQLITE3=" .. (package:config("sqlite") and "ON" or "OFF"))
  49. table.insert(configs, "-DSQLGEN_DUCKDB=" .. (package:config("duckdb") and "ON" or "OFF"))
  50. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  51. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  52. import("package.tools.cmake").install(package, configs)
  53. end)
  54. on_test(function (package)
  55. if package:config("postgres") then
  56. assert(package:check_cxxsnippets({test = [[
  57. #include <sqlgen/postgres.hpp>
  58. const auto credentials = sqlgen::postgres::Credentials{
  59. .user = "username",
  60. .password = "password",
  61. .host = "localhost",
  62. .dbname = "mydb",
  63. .port = 5432
  64. };
  65. const auto conn = sqlgen::postgres::connect(credentials);
  66. ]]}, {configs = {languages = "c++20"}}))
  67. end
  68. if package:config("sqlite") then
  69. assert(package:check_cxxsnippets({test = [[
  70. #include <sqlgen/sqlite.hpp>
  71. struct User {
  72. std::string name;
  73. int age;
  74. };
  75. void test() {
  76. const auto conn = sqlgen::sqlite::connect("test.db");
  77. const auto user = User{.name = "John", .age = 30};
  78. sqlgen::write(conn, user);
  79. }
  80. ]]}, {configs = {languages = "c++20"}}))
  81. end
  82. if package:config("mysql") then
  83. assert(package:check_cxxsnippets({test = [[
  84. #include <sqlgen/mysql.hpp>
  85. const auto creds = sqlgen::mysql::Credentials{
  86. .host = "localhost",
  87. .user = "myuser",
  88. .password = "mypassword",
  89. .dbname = "mydatabase"
  90. };
  91. const auto conn = sqlgen::mysql::connect(creds);
  92. ]]}, {configs = {languages = "c++20"}}))
  93. end
  94. if package:config("duckdb") then
  95. assert(package:check_cxxsnippets({test = [[
  96. #include <sqlgen/duckdb.hpp>
  97. struct User {
  98. std::string name;
  99. int age;
  100. };
  101. void test() {
  102. const auto conn = sqlgen::duckdb::connect("test.db");
  103. const auto user = User{.name = "John", .age = 30};
  104. sqlgen::write(conn, user);
  105. }
  106. ]]}, {configs = {languages = "c++20"}}))
  107. end
  108. end)