Skip to content

build: depend on a rapidjson rock that is not tied to the build host CPU - #13824

Open
nic-6443 wants to merge 2 commits into
apache:masterfrom
nic-6443:fix/portable-rapidjson-dependency
Open

build: depend on a rapidjson rock that is not tied to the build host CPU#13824
nic-6443 wants to merge 2 commits into
apache:masterfrom
nic-6443:fix/portable-rapidjson-dependency

Conversation

@nic-6443

@nic-6443 nic-6443 commented Aug 14, 2026

Copy link
Copy Markdown
Member

Description

lua-rapidjson compiles with -march=native, so rapidjson.so inherits the CPU features of whatever machine built it and dies with SIGILL on a machine that lacks them. ci/install-lua-rapidjson.sh worked around this by patching the flag out before building, but it only protects the paths that remember to call it — make deps and the luarocks CI runner do; the deb/rpm packages, the Docker images and a plain luarocks install apisix do not.

That is how #13736 happens. The rapidjson.so shipped in apache/apisix:3.17.0-ubuntu contains AVX-512 instructions (29 kmov* mask-register instructions), while the one in 3.17.0-debian stops at AVX2 — the packages are built per distribution, so each inherits the CPU of a different runner. Neither GCP E2 nor T2D exposes AVX-512, so on the reporter's machines the module dies as soon as its code runs. core.json.encode_stable requires rapidjson lazily on first use, which is why the crash needs a reachable upstream and does not depend on TLS: an unreachable endpoint fails before any body is encoded. 3.17.0 is the first release carrying this dependency.

This switches the dependency to api7-lua-rapidjson 0.7.2-0, which is the same 0.7.2 source with -march=native moved behind an off-by-default option (api7/lua-rapidjson#2). Every install path now gets a portable module through ordinary dependency resolution, so the patch script and its call sites are removed.

The module name is unchanged, so require("rapidjson") keeps working; cmake and a C++ compiler are still build requirements.

No new test accompanies this: the portability check lives in api7/lua-rapidjson's CI, which asserts the compile flags stay on the x86-64 baseline and scans the built module for instructions above it before a rock is published. A SIGILL on a CPU without AVX cannot be reproduced on a GitHub runner, and runtime behaviour of the swapped dependency is already covered by the existing ai-transport-http and ai-cache cases.

Which issue(s) this PR fixes

Fixes #13736

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible

lua-rapidjson compiles with -march=native, so rapidjson.so inherits the
CPU features of whatever machine built it and dies with SIGILL on older
ones. ci/install-lua-rapidjson.sh worked around that by patching the flag
out before building, but it only covers the paths that remember to call
it: make deps and the luarocks CI runner do, while the deb/rpm packages,
the Docker images and a plain `luarocks install apisix` do not.
apache/apisix:3.17.0-debian ships a rapidjson.so carrying 332 AVX
instructions.

Depend on api7-lua-rapidjson instead. It is the same 0.7.2 source with
-march=native turned off, so every install path gets a portable module
through ordinary dependency resolution and the patch step is no longer
needed.
@nic-6443
nic-6443 marked this pull request as ready for review August 14, 2026 07:20
Copilot AI lite review requested due to automatic review settings August 14, 2026 07:20
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. dependencies Pull requests that update a dependency file labels Aug 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates APISIX’s LuaRocks dependency on rapidjson to a portable build that is not compiled with -march=native, preventing rapidjson.so from inheriting build-host CPU features and crashing with SIGILL on older/baseline CPU models.

Changes:

  • Switches the rockspec dependency from rapidjson to api7-lua-rapidjson (portable build of the same upstream source).
  • Removes the ci/install-lua-rapidjson.sh workaround and deletes the script.
  • Simplifies make deps and the LuaRocks CI runner by relying on normal dependency resolution.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
Makefile Removes the explicit rapidjson patch/install step so make deps relies on rockspec dependency resolution.
ci/linux_apisix_current_luarocks_runner.sh Drops the workaround script invocation so CI matches real-world luarocks install/make behavior.
ci/install-lua-rapidjson.sh Deleted; workaround is no longer needed with the new dependency.
apisix-master-0.rockspec Updates dependency to api7-lua-rapidjson = 0.7.2-0 to ensure portable builds across install paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ai-proxy crashes worker with SIGILL (signal 4) on outbound HTTPS request to LLM endpoint

4 participants