This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 2f9566412a fix(core): prevent docs.rs OOM on librocksdb-sys and add
sandbox CI check (#9300)
2f9566412a is described below
commit 2f9566412a66535bdbb8cc176e9a02a28d720a7b
Author: Xuanwo <[email protected]>
AuthorDate: Sat Nov 28 02:39:41 2026 +0800
fix(core): prevent docs.rs OOM on librocksdb-sys and add sandbox CI check
(#9300)
* fix(core): prevent docs.rs OOM on librocksdb-sys and add sandbox CI check
* ci: avoid cancelling Docs.rs CI from release_rust PR trigger
---
.github/scripts/check_docsrs.py | 351 +++++++++++++++++++++++++++++++++++
.github/scripts/test_check_docsrs.py | 109 +++++++++++
.github/workflows/ci_check.yml | 1 +
.github/workflows/ci_docsrs.yml | 68 +++++++
.github/workflows/nightly_tier_a.yml | 5 +
.github/workflows/release_rust.yml | 4 +
core/Cargo.toml | 4 +
core/services/rocksdb/Cargo.toml | 4 +
8 files changed, 546 insertions(+)
diff --git a/.github/scripts/check_docsrs.py b/.github/scripts/check_docsrs.py
new file mode 100755
index 0000000000..0ed7823381
--- /dev/null
+++ b/.github/scripts/check_docsrs.py
@@ -0,0 +1,351 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Simulate docs.rs builds inside the official crates-build-env Linux
sandbox."""
+
+from __future__ import annotations
+
+import argparse
+import json
+import os
+import shlex
+import shutil
+import subprocess
+import sys
+import tempfile
+import time
+import tomllib
+from dataclasses import dataclass
+from pathlib import Path
+
+DEFAULT_IMAGE = "ghcr.io/rust-lang/crates-build-env/linux:latest"
+DEFAULT_TARGET = "x86_64-unknown-linux-gnu"
+# Match docs.rs default sandbox memory limit (6 GiB = 6,442,450,944 bytes).
+DEFAULT_MEMORY_LIMIT = 6442450944
+# Match docs.rs builder concurrency (-j12).
+DEFAULT_JOBS = 12
+UNCONDITIONAL_RUSTDOC_ARGS = (
+ "--static-root-path",
+ "/-/rustdoc.static/",
+ "--extern-html-root-takes-precedence",
+)
+
+
+@dataclass(frozen=True)
+class DocsRsMetadata:
+ package_name: str
+ all_features: bool = False
+ no_default_features: bool = False
+ features: tuple[str, ...] = ()
+ rustc_args: tuple[str, ...] = ()
+ rustdoc_args: tuple[str, ...] = ()
+ cargo_args: tuple[str, ...] = ()
+
+
+def load_docsrs_metadata(manifest_path: Path) -> DocsRsMetadata:
+ with manifest_path.open("rb") as fp:
+ manifest = tomllib.load(fp)
+
+ package = manifest.get("package", {})
+ package_name = package.get("name")
+ if not isinstance(package_name, str) or not package_name:
+ raise ValueError(f"{manifest_path}: missing [package].name")
+
+ docsrs = package.get("metadata", {}).get("docs", {}).get("rs", {})
+ if not isinstance(docsrs, dict):
+ raise ValueError(f"{manifest_path}: [package.metadata.docs.rs] must be
a table")
+
+ return DocsRsMetadata(
+ package_name=package_name,
+ all_features=bool(docsrs.get("all-features", False)),
+ no_default_features=bool(docsrs.get("no-default-features", False)),
+ features=tuple(docsrs.get("features", ())),
+ rustc_args=tuple(docsrs.get("rustc-args", ())),
+ rustdoc_args=tuple(docsrs.get("rustdoc-args", ())),
+ cargo_args=tuple(docsrs.get("cargo-args", ())),
+ )
+
+
+def filter_metadata_cargo_args(args: tuple[str, ...]) -> list[str]:
+ """Match docs.rs's filtering of -Zrustdoc-scrape-examples from metadata
cargo-args."""
+ filtered: list[str] = []
+ idx = 0
+ while idx < len(args):
+ arg = args[idx]
+ if arg == "-Zrustdoc-scrape-examples":
+ idx += 1
+ continue
+ if arg == "-Z" and idx + 1 < len(args) and args[idx + 1] ==
"rustdoc-scrape-examples":
+ idx += 2
+ continue
+ filtered.append(arg)
+ idx += 1
+ return filtered
+
+
+def build_cargo_rustdoc_command(
+ *,
+ cargo_bin: str,
+ toolchain: str,
+ manifest_path: str,
+ metadata: DocsRsMetadata,
+ target: str,
+ jobs: int,
+ mode: str,
+) -> list[str]:
+ """Build the cargo rustdoc argv matching docs.rs's
CommandArgs::finish()."""
+ if mode not in ("html", "json"):
+ raise ValueError(f"unsupported mode: {mode}")
+
+ cmd = [
+ cargo_bin,
+ f"+{toolchain}",
+ "rustdoc",
+ "--manifest-path",
+ manifest_path,
+ "--lib",
+ "-Zrustdoc-map",
+ ]
+
+ if metadata.features:
+ cmd.extend(["--features", " ".join(metadata.features)])
+ if metadata.all_features:
+ cmd.append("--all-features")
+ if metadata.no_default_features:
+ cmd.append("--no-default-features")
+
+ if metadata.rustc_args:
+ rustc_array = json.dumps(list(metadata.rustc_args))
+ cmd.extend(
+ [
+ "--config",
+ f"build.rustflags={rustc_array}",
+ "-Zhost-config",
+ "-Ztarget-applies-to-host",
+ "--config",
+ f"host.rustflags={rustc_array}",
+ ]
+ )
+
+ rustdoc_flags = ["--cfg", "docsrs", *metadata.rustdoc_args]
+ if mode == "html":
+ rustdoc_flags.extend(["-Z", "unstable-options",
"--emit=html-non-static-files"])
+ else:
+ rustdoc_flags.extend(["-Z", "unstable-options", "--output-format",
"json"])
+ rustdoc_flags.extend(UNCONDITIONAL_RUSTDOC_ARGS)
+
+ cmd.extend(["--config", f"build.rustdocflags={json.dumps(rustdoc_flags)}"])
+ cmd.extend(
+ [
+ "--offline",
+ "-Zunstable-options",
+
f'--config=doc.extern-map.registries.crates-io="https://docs.rs/{{pkg_name}}/{{version}}/{target}"',
+ f"-j{jobs}",
+ "--target",
+ target,
+ ]
+ )
+
+ if mode == "html":
+ cmd.append("-Zrustdoc-scrape-examples")
+
+ cmd.extend(filter_metadata_cargo_args(metadata.cargo_args))
+ return cmd
+
+
+def build_container_script(commands: list[tuple[str, list[str]]]) -> str:
+ lines = ["set -euo pipefail"]
+ for label, argv in commands:
+ quoted = shlex.join(argv)
+ lines.append(f"echo {shlex.quote(f'==> {label}')}")
+ lines.append(f"echo {shlex.quote(f'+ {quoted}')}")
+ lines.append("t0=$(date +%s)")
+ lines.append(quoted)
+ lines.append("t1=$(date +%s)")
+ lines.append(f'echo "==> {label} succeeded in $((t1 - t0))s"')
+ lines.append(
+ 'if [ -r /sys/fs/cgroup/memory.peak ]; then '
+ 'echo "==> cgroup memory.peak: $(cat /sys/fs/cgroup/memory.peak)
bytes"; '
+ "fi"
+ )
+ return "\n".join(lines) + "\n"
+
+
+def resolve_repo_root(manifest_paths: list[Path]) -> Path:
+ script_repo_root = Path(__file__).resolve().parents[2]
+ for path in manifest_paths:
+ path.resolve().relative_to(script_repo_root)
+ return script_repo_root
+
+
+def run_fetch(toolchain: str, workspace_manifest: Path, target: str) -> None:
+ cmd = [
+ "cargo",
+ f"+{toolchain}",
+ "fetch",
+ "--locked",
+ "--manifest-path",
+ str(workspace_manifest),
+ "--target",
+ target,
+ ]
+ print(f"==> Fetching locked dependencies: {shlex.join(cmd)}", flush=True)
+ subprocess.run(cmd, check=True)
+
+
+def run_docsrs_check(args: argparse.Namespace) -> None:
+ manifest_paths = [Path(p).resolve() for p in args.manifest_path]
+ repo_root = resolve_repo_root(manifest_paths)
+
+ cargo_home = Path(os.environ.get("CARGO_HOME", Path.home() /
".cargo")).resolve()
+ rustup_home = Path(os.environ.get("RUSTUP_HOME", Path.home() /
".rustup")).resolve()
+
+ if not args.skip_fetch:
+ run_fetch(args.toolchain, repo_root / "core" / "Cargo.toml",
args.target)
+
+ commands: list[tuple[str, list[str]]] = []
+ modes = ["html", "json"] if args.check_json else ["html"]
+ for manifest_path in manifest_paths:
+ rel_manifest = manifest_path.relative_to(repo_root).as_posix()
+ container_manifest = f"/opt/rustwide/workdir/{rel_manifest}"
+ metadata = load_docsrs_metadata(manifest_path)
+ for mode in modes:
+ argv = build_cargo_rustdoc_command(
+ cargo_bin="/opt/rustwide/cargo-home/bin/cargo",
+ toolchain=args.toolchain,
+ manifest_path=container_manifest,
+ metadata=metadata,
+ target=args.target,
+ jobs=args.jobs,
+ mode=mode,
+ )
+ commands.append((f"{metadata.package_name} ({mode})", argv))
+
+ script = build_container_script(commands)
+
+ target_dir = Path(tempfile.mkdtemp(prefix="opendal-docsrs-target-"))
+ try:
+ docker_cmd = [
+ "docker",
+ "run",
+ "--rm",
+ "--user",
+ f"{os.getuid()}:{os.getgid()}",
+ "--memory",
+ str(args.memory_limit),
+ "--memory-swap",
+ str(args.memory_limit),
+ "--network",
+ "none",
+ "-v",
+ f"{repo_root}:/opt/rustwide/workdir:ro",
+ "-v",
+ f"{target_dir}:/opt/rustwide/target:rw",
+ "-v",
+ f"{cargo_home}:/opt/rustwide/cargo-home:ro",
+ "-v",
+ f"{rustup_home}:/opt/rustwide/rustup-home:ro",
+ "-e",
+ "CARGO_HOME=/opt/rustwide/cargo-home",
+ "-e",
+ "RUSTUP_HOME=/opt/rustwide/rustup-home",
+ "-e",
+ "CARGO_TARGET_DIR=/opt/rustwide/target",
+ "-e",
+ "DOCS_RS=1",
+ "-w",
+ "/opt/rustwide/workdir/core",
+ args.image,
+ "bash",
+ "-c",
+ script,
+ ]
+ started = time.monotonic()
+ print(
+ f"==> Running docs.rs sandbox check ({args.image}, "
+ f"memory={args.memory_limit} bytes, jobs={args.jobs})",
+ flush=True,
+ )
+ subprocess.run(docker_cmd, check=True)
+ elapsed = int(time.monotonic() - started)
+ print(f"==> docs.rs sandbox check passed in {elapsed}s", flush=True)
+ finally:
+ shutil.rmtree(target_dir, ignore_errors=True)
+
+
+def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
+ parser = argparse.ArgumentParser(
+ description="Simulate docs.rs builds in the official crates-build-env
Linux container."
+ )
+ parser.add_argument(
+ "--manifest-path",
+ action="append",
+ help="Path to a Cargo.toml to check (repeatable; defaults to
core/Cargo.toml).",
+ )
+ parser.add_argument(
+ "--toolchain",
+ default="nightly",
+ help="Rustup toolchain name to invoke inside the container (default:
nightly).",
+ )
+ parser.add_argument(
+ "--target",
+ default=DEFAULT_TARGET,
+ help=f"Rust target triple (default: {DEFAULT_TARGET}).",
+ )
+ parser.add_argument(
+ "--image",
+ default=DEFAULT_IMAGE,
+ help=f"Docker image matching docs.rs (default: {DEFAULT_IMAGE}).",
+ )
+ parser.add_argument(
+ "--memory-limit",
+ type=int,
+ default=DEFAULT_MEMORY_LIMIT,
+ help=f"Container memory and swap cap in bytes (default:
{DEFAULT_MEMORY_LIMIT}).",
+ )
+ parser.add_argument(
+ "--jobs",
+ type=int,
+ default=DEFAULT_JOBS,
+ help=f"Cargo -j parallelism (default: {DEFAULT_JOBS}).",
+ )
+ parser.add_argument(
+ "--no-json",
+ dest="check_json",
+ action="store_false",
+ help="Skip the rustdoc JSON pass and check HTML only.",
+ )
+ parser.add_argument(
+ "--skip-fetch",
+ action="store_true",
+ help="Skip running `cargo fetch --locked` before starting the offline
container.",
+ )
+ args = parser.parse_args(argv)
+ if not args.manifest_path:
+ args.manifest_path = ["core/Cargo.toml"]
+ return args
+
+
+def main() -> int:
+ args = parse_args()
+ run_docsrs_check(args)
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/.github/scripts/test_check_docsrs.py
b/.github/scripts/test_check_docsrs.py
new file mode 100755
index 0000000000..b4a8aceccd
--- /dev/null
+++ b/.github/scripts/test_check_docsrs.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import json
+import sys
+import tempfile
+import unittest
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parent))
+
+import check_docsrs
+
+
+class CheckDocsRsTests(unittest.TestCase):
+ def test_load_docsrs_metadata_from_core_manifests(self) -> None:
+ repo_root = Path(__file__).resolve().parents[2]
+ for rel in ("core/Cargo.toml", "core/services/rocksdb/Cargo.toml"):
+ meta = check_docsrs.load_docsrs_metadata(repo_root / rel)
+ self.assertTrue(meta.all_features)
+ self.assertIn("--config", meta.cargo_args)
+ self.assertIn('env.ROCKSDB_LIB_DIR="/usr/lib"', meta.cargo_args)
+
+ def test_filter_metadata_cargo_args_strips_scrape_examples(self) -> None:
+ args = (
+ "-Zrustdoc-scrape-examples",
+ "-Z",
+ "rustdoc-scrape-examples",
+ "--config",
+ 'env.ROCKSDB_LIB_DIR="/usr/lib"',
+ "-Zbuild-std",
+ )
+ self.assertEqual(
+ check_docsrs.filter_metadata_cargo_args(args),
+ ["--config", 'env.ROCKSDB_LIB_DIR="/usr/lib"', "-Zbuild-std"],
+ )
+
+ def test_build_cargo_rustdoc_command_matches_docsrs_order(self) -> None:
+ meta = check_docsrs.DocsRsMetadata(
+ package_name="opendal",
+ all_features=True,
+ rustc_args=("--cfg", "custom_rustc"),
+ rustdoc_args=("--cfg", "custom_doc"),
+ cargo_args=("-Zrustdoc-scrape-examples", "--config",
'env.ROCKSDB_LIB_DIR="/usr/lib"'),
+ )
+
+ html_cmd = check_docsrs.build_cargo_rustdoc_command(
+ cargo_bin="/opt/rustwide/cargo-home/bin/cargo",
+ toolchain="nightly",
+ manifest_path="/opt/rustwide/workdir/core/Cargo.toml",
+ metadata=meta,
+ target="x86_64-unknown-linux-gnu",
+ jobs=12,
+ mode="html",
+ )
+ self.assertIn("--all-features", html_cmd)
+ self.assertIn("-j12", html_cmd)
+ self.assertIn("-Zrustdoc-scrape-examples", html_cmd)
+ self.assertEqual(
+ html_cmd[-2:],
+ ["--config", 'env.ROCKSDB_LIB_DIR="/usr/lib"'],
+ )
+ rustdoc_cfg = next(a for a in html_cmd if
a.startswith("build.rustdocflags="))
+ rustdoc_flags = json.loads(rustdoc_cfg.split("=", 1)[1])
+ self.assertEqual(rustdoc_flags[:4], ["--cfg", "docsrs", "--cfg",
"custom_doc"])
+ self.assertIn("--emit=html-non-static-files", rustdoc_flags)
+
+ json_cmd = check_docsrs.build_cargo_rustdoc_command(
+ cargo_bin="/opt/rustwide/cargo-home/bin/cargo",
+ toolchain="nightly",
+ manifest_path="/opt/rustwide/workdir/core/Cargo.toml",
+ metadata=meta,
+ target="x86_64-unknown-linux-gnu",
+ jobs=12,
+ mode="json",
+ )
+ self.assertNotIn("-Zrustdoc-scrape-examples", json_cmd)
+ json_cfg = next(a for a in json_cmd if
a.startswith("build.rustdocflags="))
+ json_flags = json.loads(json_cfg.split("=", 1)[1])
+ self.assertIn("--output-format", json_flags)
+ self.assertIn("json", json_flags)
+
+ def test_load_docsrs_metadata_defaults(self) -> None:
+ with tempfile.TemporaryDirectory() as tmp:
+ manifest = Path(tmp) / "Cargo.toml"
+ manifest.write_text('[package]\nname = "demo"\nversion =
"0.1.0"\n')
+ meta = check_docsrs.load_docsrs_metadata(manifest)
+ self.assertEqual(meta.package_name, "demo")
+ self.assertFalse(meta.all_features)
+ self.assertEqual(meta.cargo_args, ())
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/.github/workflows/ci_check.yml b/.github/workflows/ci_check.yml
index d65997d276..7a275466c1 100644
--- a/.github/workflows/ci_check.yml
+++ b/.github/workflows/ci_check.yml
@@ -86,6 +86,7 @@ jobs:
run: |
python3 -m unittest discover -s .github/scripts/test_behavior -p
'test_*.py'
python3 -m unittest discover -s .github/scripts/nightly -p
'test_*.py'
+ python3 -m unittest discover -s .github/scripts -p
'test_check_docsrs.py'
typos:
runs-on: ubuntu-latest
diff --git a/.github/workflows/ci_docsrs.yml b/.github/workflows/ci_docsrs.yml
new file mode 100644
index 0000000000..0f8fb7bc62
--- /dev/null
+++ b/.github/workflows/ci_docsrs.yml
@@ -0,0 +1,68 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Docs.rs CI
+
+on:
+ pull_request:
+ branches:
+ - main
+ paths:
+ - "core/**/Cargo.toml"
+ - "core/Cargo.toml"
+ - "core/Cargo.lock"
+ - ".github/scripts/check_docsrs.py"
+ - ".github/scripts/test_check_docsrs.py"
+ - ".github/workflows/ci_docsrs.yml"
+ workflow_call:
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: ci-docsrs-${{ github.workflow }}-${{ github.ref }}-${{
github.event_name }}
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
+
+jobs:
+ check_docsrs:
+ runs-on: ubuntu-latest
+ timeout-minutes: 25
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+
+ - name: Test docs.rs checker
+ run: python3 -m unittest discover -s .github/scripts -p
"test_check_docsrs.py"
+
+ - name: Setup Rust Nightly
+ run: |
+ rustup toolchain install nightly --profile minimal --target
x86_64-unknown-linux-gnu
+ rustc +nightly --version
+ rustdoc +nightly --version
+
+ - name: Verify opendal-core package tarball
+ working-directory: core
+ run: cargo +nightly package --locked -p opendal-core
+
+ - name: Build docs in docs.rs sandbox
+ run: |
+ python3 .github/scripts/check_docsrs.py \
+ --toolchain nightly \
+ --manifest-path core/Cargo.toml \
+ --manifest-path core/services/rocksdb/Cargo.toml
diff --git a/.github/workflows/nightly_tier_a.yml
b/.github/workflows/nightly_tier_a.yml
index cdcdb4839e..97d74ce8d6 100644
--- a/.github/workflows/nightly_tier_a.yml
+++ b/.github/workflows/nightly_tier_a.yml
@@ -45,6 +45,10 @@ jobs:
if: github.event_name != 'schedule' || github.repository ==
'apache/opendal'
uses: ./.github/workflows/ci_core.yml
+ docsrs:
+ if: github.event_name != 'schedule' || github.repository ==
'apache/opendal'
+ uses: ./.github/workflows/ci_docsrs.yml
+
odev:
if: github.event_name != 'schedule' || github.repository ==
'apache/opendal'
uses: ./.github/workflows/ci_odev.yml
@@ -150,6 +154,7 @@ jobs:
needs:
- check
- core
+ - docsrs
- odev
- website
- edge_local
diff --git a/.github/workflows/release_rust.yml
b/.github/workflows/release_rust.yml
index 61743f3ab4..9f425ec5c6 100644
--- a/.github/workflows/release_rust.yml
+++ b/.github/workflows/release_rust.yml
@@ -51,6 +51,10 @@ jobs:
id: plan
run: python3 .github/scripts/release_rust/plan.py --github-output
+ docsrs:
+ if: ${{ github.event_name != 'pull_request' && (!startsWith(github.ref,
'refs/tags/') || contains(github.ref, '-')) }}
+ uses: ./.github/workflows/ci_docsrs.yml
+
publish:
if: ${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-')
}}
needs: plan
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 624ec09528..6329a779a3 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -84,6 +84,10 @@ unused_async = "warn"
[package.metadata.docs.rs]
all-features = true
+# Skip compiling RocksDB C++ from source on docs.rs: librocksdb-sys spawns
+# NUM_JOBS parallel c++ compilers and OOMs the 6.4 GB sandbox, while
+# `cargo rustdoc --lib` only runs bindgen and never links librocksdb.
+cargo-args = ["--config", 'env.ROCKSDB_LIB_DIR="/usr/lib"']
[features]
# Install facade defaults before `main`: register enabled services and, when
diff --git a/core/services/rocksdb/Cargo.toml b/core/services/rocksdb/Cargo.toml
index 4080829bc2..6c135642a0 100644
--- a/core/services/rocksdb/Cargo.toml
+++ b/core/services/rocksdb/Cargo.toml
@@ -30,6 +30,10 @@ version = { workspace = true }
[package.metadata.docs.rs]
all-features = true
+# Skip compiling RocksDB C++ from source on docs.rs: librocksdb-sys spawns
+# NUM_JOBS parallel c++ compilers near the 6.4 GB sandbox cap, while
+# `cargo rustdoc --lib` only runs bindgen and never links librocksdb.
+cargo-args = ["--config", 'env.ROCKSDB_LIB_DIR="/usr/lib"']
[dependencies]
opendal-core = { path = "../../core", version = "0.59.5", default-features =
false }