sync_vendor.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. "https://raw.githubusercontent.com/nothings/stb/refs/heads/master/stb_image.h": "vendor/stb/stb_image.h",
  7. # not using latest tag to avoid this issue: https://github.com/ggml-org/llama.cpp/pull/17179#discussion_r2515877926
  8. # "https://github.com/mackron/miniaudio/raw/refs/tags/0.11.23/miniaudio.h": "vendor/miniaudio/miniaudio.h",
  9. "https://github.com/mackron/miniaudio/raw/669ed3e844524fcd883231b13095baee9f6de304/miniaudio.h": "vendor/miniaudio/miniaudio.h",
  10. "https://raw.githubusercontent.com/yhirose/cpp-httplib/refs/tags/v0.30.1/httplib.h": "vendor/cpp-httplib/httplib.h",
  11. "https://raw.githubusercontent.com/yhirose/cpp-httplib/refs/tags/v0.30.1/LICENSE": "vendor/cpp-httplib/LICENSE",
  12. "https://raw.githubusercontent.com/sheredom/subprocess.h/b49c56e9fe214488493021017bf3954b91c7c1f5/subprocess.h": "vendor/sheredom/subprocess.h",
  13. }
  14. for url, filename in vendor.items():
  15. print(f"downloading {url} to {filename}") # noqa: NP100
  16. urllib.request.urlretrieve(url, filename)
  17. # split cpp/h files for httplib
  18. # see: https://github.com/yhirose/cpp-httplib/blob/master/split.py
  19. if 'httplib.h' in filename:
  20. border = '// ----------------------------------------------------------------------------'
  21. with open(filename, 'r') as f:
  22. content = f.read()
  23. header, implementation, footer = content.split(border, 2)
  24. fname_cpp = filename.replace('.h', '.cpp')
  25. with open(filename, 'w') as fh:
  26. fh.write(header)
  27. fh.write(footer)
  28. with open(fname_cpp, 'w') as fc:
  29. fc.write('#include "httplib.h"\n')
  30. fc.write('namespace httplib {\n')
  31. fc.write(implementation.replace('\ninline ', '\n'))
  32. fc.write('} // namespace httplib\n')