package("llhttp") set_homepage("https://github.com/nodejs/llhttp") add_configs("build_patch", {description = "Internal cache-buster for local llhttp packaging changes", default = "1", type = "string"}) set_description("Port of http_parser to llparse") set_license("MIT") add_urls("https://github.com/nodejs/llhttp/archive/refs/tags/release/$(version).tar.gz", "https://github.com/nodejs/llhttp.git") add_versions("v9.3.1", "c14a93f287d3dbd6580d08af968294f8bcc61e1e1e3c34301549d00f3cf09365") add_versions("v9.3.0", "1a2b45cb8dda7082b307d336607023aa65549d6f060da1d246b1313da22b685a") add_versions("v9.2.1", "3c163891446e529604b590f9ad097b2e98b5ef7e4d3ddcf1cf98b62ca668f23e") add_versions("v8.1.0", "9da0d23453e8e242cf3b2bc5d6fb70b1517b8a70520065fcbad6be787e86638e") add_versions("v3.0.0", "02931556e69f8d075edb5896127099e70a093c104a994a57b4d72c85b48d25b0") on_install(function (package) -- Touch the package hash with a no-op config so local packaging changes can -- force rebuilds even when the upstream llhttp version stays the same. local _BuildPatch = package:config("build_patch") io.replace("include/llhttp.h", "__wasm__", "__GNUC__", {plain = true}) io.replace("include/llhttp.h", "_WIN32", "_MSC_VER", {plain = true}) if not package:config("shared") then io.replace("include/llhttp.h", "__declspec(dllexport)", "", {plain = true}) end io.writefile("xmake.lua", [[ add_rules("mode.debug", "mode.release") target("llhttp") set_kind("$(kind)") add_files("src/*.c") add_includedirs("include") add_headerfiles("include/llhttp.h") set_symbols("debug") -- On Windows/MSVC, use embedded CodeView info for static builds so -- symbolized release/debug callstacks do not depend on a separate -- compiler PDB produced during package compilation. if is_plat("windows") and not is_kind("shared") then add_cflags("/Z7", {force = true}) end if is_plat("cross") then add_cflags("-flax-vector-conversions") end if is_kind("shared") and is_plat("windows") then local funcs = { "llhttp_init", "llhttp_settings_init", "llhttp_execute", "llhttp_finish", "llhttp_message_needs_eof", "llhttp_should_keep_alive", "llhttp_pause", "llhttp_resume", "llhttp_resume_after_upgrade", "llhttp_get_errno", "llhttp_get_error_reason", "llhttp_set_error_reason", "llhttp_get_error_pos", "llhttp_errno_name", "llhttp_method_name", "llhttp_set_lenient_headers", "llhttp_set_lenient_chunked_length" } for _, func in ipairs(funcs) do add_shflags("/export:" .. func) end end ]]) local configs = {} if package:config("shared") then configs.kind = "shared" end import("package.tools.xmake").install(package, configs) if package:config("shared") then io.replace(package:installdir("include/llhttp.h"), "__declspec(dllexport)", "__declspec(dllimport)", {plain = true}) end end) on_test(function (package) assert(package:has_cfuncs("llhttp_init", {includes = "llhttp.h"})) end)