__init__.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import os
  2. from devtools.yamaker import fileutil
  3. from devtools.yamaker.modules import Switch, Linkable
  4. from devtools.yamaker.project import CMakeNinjaNixProject
  5. def post_install(self):
  6. with self.yamakes["."] as libzstd:
  7. # Unbundle xxhash.
  8. fileutil.re_sub_dir(self.dstdir, '"([^"]*/)?xxhash.h"', "<contrib/libs/xxhash/xxhash.h>")
  9. libzstd.CFLAGS.remove("-DXXH_NAMESPACE=ZSTD_")
  10. libzstd.SRCS.remove("lib/common/xxhash.c")
  11. libzstd.PEERDIR.add("contrib/libs/xxhash")
  12. os.remove(f"{self.dstdir}/lib/common/xxhash.h")
  13. os.remove(f"{self.dstdir}/lib/common/xxhash.c")
  14. # Enable runtime-dispatching for bmi2
  15. libzstd.SRCS.remove("lib/decompress/huf_decompress_amd64.S")
  16. libzstd.after(
  17. "CFLAGS",
  18. Switch(
  19. {
  20. "ARCH_X86_64 AND NOT MSVC": Linkable(
  21. CFLAGS=["-DDYNAMIC_BMI2"],
  22. SRCS=["lib/decompress/huf_decompress_amd64.S"],
  23. )
  24. }
  25. ),
  26. )
  27. with self.yamakes["programs/zstd"] as zstd:
  28. zstd.CFLAGS.remove("-DXXH_NAMESPACE=ZSTD_")
  29. # Update version stored in python binding
  30. # (we have to update two different files for py2 and py3 correspondingly)
  31. version_as_number = self.version.replace(".", "0")
  32. fileutil.re_sub_file(
  33. f"{self.ctx.arc}/contrib/python/zstandard/py2/zstd.c",
  34. r"(ZSTD_VERSION_NUMBER != )[0-9]+( \|\| ZSTD_versionNumber\(\) != )[0-9]+",
  35. r"\g<1>{v}\g<2>{v}".format(v=version_as_number),
  36. )
  37. fileutil.re_sub_file(
  38. f"{self.ctx.arc}/contrib/python/zstandard/py3/c-ext/backend_c.c",
  39. r"unsigned our_hardcoded_version = [0-9]+;",
  40. rf"unsigned our_hardcoded_version = {version_as_number};",
  41. )
  42. zstd = CMakeNinjaNixProject(
  43. owners=["g:cpp-contrib"],
  44. arcdir="contrib/libs/zstd",
  45. nixattr="zstd",
  46. build_subdir="build_",
  47. install_targets=["zstd", "programs/zstd"],
  48. put={
  49. "zstd": ".",
  50. "Program zstd": "programs/zstd",
  51. },
  52. disable_includes=[
  53. # our zstd is built without other codecs support
  54. "lz4.h",
  55. "lz4frame.h",
  56. "lzma.h",
  57. "zlib.h",
  58. ],
  59. inclink={
  60. # list of public headers, obtained from `dpkg -L libzstd-dev`
  61. "include": [
  62. "lib/zstd_errors.h",
  63. "lib/zdict.h",
  64. "lib/zstd.h",
  65. ],
  66. },
  67. post_install=post_install,
  68. )