2
0

xmake.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package("datatype99")
  2. set_kind("library", { headeronly = true })
  3. set_homepage("https://github.com/Hirrolot/datatype99")
  4. set_description("Algebraic data types for C99")
  5. set_license("MIT")
  6. add_urls("https://github.com/Hirrolot/datatype99/archive/refs/tags/v$(version).tar.gz",
  7. "https://github.com/Hirrolot/datatype99.git")
  8. add_versions("1.6.3", "0ddc138eac8db19fa22c482d9a2ec107ff622fd7ce61bb0b1eefb4d8f522e01e")
  9. add_versions("1.6.4", "f8488decc7ab035e3af77ee62e64fc678d5cb57831457f7270efe003e63d6f09")
  10. add_versions("1.6.5", "f38c077afdb91b7d754321be5d3c4a43ed5420c1ad51514d1de20023960f9a8e")
  11. add_deps("metalang99")
  12. on_install(function(package)
  13. os.cp("*.h", package:installdir("include"))
  14. end)
  15. on_test(function(package)
  16. assert(package:check_csnippets({test = [[
  17. #include <assert.h>
  18. datatype(
  19. BinaryTree,
  20. (Leaf, int),
  21. (Node, BinaryTree *, int, BinaryTree *)
  22. );
  23. int sum(const BinaryTree *tree) {
  24. match(*tree) {
  25. of(Leaf, x) return *x;
  26. of(Node, lhs, x, rhs) return sum(*lhs) + *x + sum(*rhs);
  27. }
  28. return -1;
  29. }
  30. void test() {
  31. BinaryTree leaf5 = Leaf(5);
  32. BinaryTree leaf7 = Leaf(7);
  33. BinaryTree node = Node(&leaf5, 123, &leaf7);
  34. assert(sum(&node) == 135);
  35. }
  36. ]]}, { configs = { languages = "c11" }, includes = "datatype99.h" }))
  37. end)