sync_vendor.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. import urllib.request
  3. vendor = {
  4. "https://github.com/nlohmann/json/releases/latest/download/json.hpp": "vendor/nlohmann/json.hpp",
  5. "https://github.com/nlohmann/json/releases/latest/download/json_fwd.hpp": "vendor/nlohmann/json_fwd.hpp",
  6. # sync manually
  7. # "https://raw.githubusercontent.com/ochafik/minja/refs/heads/main/include/minja/minja.hpp": "vendor/minja/minja.hpp",
  8. # "https://raw.githubusercontent.com/ochafik/minja/refs/heads/main/include/minja/chat-template.hpp": "vendor/minja/chat-template.hpp",
  9. "https://raw.githubusercontent.com/nothings/stb/refs/heads/master/stb_image.h": "vendor/stb/stb_image.h",
  10. # not using latest tag to avoid this issue: https://github.com/ggml-org/llama.cpp/pull/17179#discussion_r2515877926
  11. # "https://github.com/mackron/miniaudio/raw/refs/tags/0.11.23/miniaudio.h": "vendor/miniaudio/miniaudio.h",
  12. "https://github.com/mackron/miniaudio/raw/669ed3e844524fcd883231b13095baee9f6de304/miniaudio.h": "vendor/miniaudio/miniaudio.h",
  13. "https://raw.githubusercontent.com/yhirose/cpp-httplib/refs/tags/v0.28.0/httplib.h": "vendor/cpp-httplib/httplib.h",
  14. "https://raw.githubusercontent.com/sheredom/subprocess.h/b49c56e9fe214488493021017bf3954b91c7c1f5/subprocess.h": "vendor/sheredom/subprocess.h",
  15. }
  16. for url, filename in vendor.items():
  17. print(f"downloading {url} to {filename}") # noqa: NP100
  18. urllib.request.urlretrieve(url, filename)
  19. # split cpp/h files for httplib
  20. # see: https://github.com/yhirose/cpp-httplib/blob/master/split.py
  21. if 'httplib.h' in filename:
  22. border = '// ----------------------------------------------------------------------------'
  23. with open(filename, 'r') as f:
  24. content = f.read()
  25. header, implementation, footer = content.split(border, 2)
  26. fname_cpp = filename.replace('.h', '.cpp')
  27. with open(filename, 'w') as fh:
  28. fh.write(header)
  29. fh.write(footer)
  30. with open(fname_cpp, 'w') as fc:
  31. fc.write('#include "httplib.h"\n')
  32. fc.write('namespace httplib {\n')
  33. fc.write(implementation.replace('\ninline ', '\n'))
  34. fc.write('} // namespace httplib\n')