rust-lang/rust · critical · Exception

Failed to locate libstd (in {rustlibs_dir})

Error message

Failed to locate libstd (in {rustlibs_dir})

What it means

Raised by TestEnvironment.run() when glob.glob for libstd-*.so in rustlibs_dir() returns nothing. libstd is a required shared library that must be packaged alongside the test binary on Fuchsia (see MANIFEST_TEMPLATE at line 657). Its absence means the Rust build did not produce the expected target libraries.

Source

Thrown at src/ci/docker/scripts/fuchsia-test-runner.py:692

        Args:
        args: The command-line arguments to this command.
        Returns:
        The return code of the test (0 for success, else failure).

        To run a test, this function will:
        - Create, compile, archive, and publish a test package
        - Run the test package on the emulator
        - Forward the test's stdout and stderr as this script's stdout and stderr
        """

        bin_path = Path(args.bin_path).absolute()

        # Find libstd and libtest
        libstd_paths = glob.glob(os.path.join(self.rustlibs_dir(), "libstd-*.so"))
        libtest_paths = glob.glob(os.path.join(self.rustlibs_dir(), "libtest-*.so"))

        if not libstd_paths:
            raise Exception(f"Failed to locate libstd (in {self.rustlibs_dir()})")

        base_name = os.path.basename(os.path.dirname(args.bin_path))
        exe_name = base_name.lower().replace(".", "_")
        build_id = self.build_id(bin_path)
        package_name = f"{exe_name}_{build_id}"

        package_dir = self.packages_dir.joinpath(package_name)
        package_dir.mkdir(parents=True, exist_ok=True)
        meta_dir = package_dir.joinpath("meta")
        meta_dir.mkdir(parents=True, exist_ok=True)
        meta_package_path = meta_dir.joinpath("package")
        cml_path = meta_dir.joinpath(f"{package_name}.cml")
        cm_path = meta_dir.joinpath(f"{package_name}.cm")
        manifest_path = package_dir.joinpath(f"{package_name}.manifest")

        shared_libs = args.shared_libs[: args.n]
        arguments = args.shared_libs[args.n :]

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Confirm the file exists: `ls {rust_build_dir}/host/stage2/lib/rustlib/{target}/lib/libstd-*.so`.
  2. Complete the Rust build for the Fuchsia target up to stage2 (e.g. `x.py build --stage 2 library` with the right target).
  3. Verify the --rust-build and --target values given to 'start' match the actual build output layout.
  4. If libstd is now statically linked for this target, update the runner to treat libstd as optional (as was already done for libtest at lines 798-803).

Example fix

// before
$ fuchsia-test-runner.py run <n> <bin> <libs...>
# Exception: Failed to locate libstd (in .../host/stage2/lib/rustlib/aarch64-unknown-fuchsia/lib)

// after - build stage2 for the target first
$ ./x.py build --stage 2 --target aarch64-unknown-fuchsia library
$ fuchsia-test-runner.py run <n> <bin> <libs...>
Defensive patterns

Strategy: validation

Validate before calling

import glob, os

rustlibs = os.path.join(rust_build_dir, "host", "stage2", "lib", "rustlib", target, "lib")
libstd = glob.glob(os.path.join(rustlibs, "libstd-*.so"))
if not libstd:
    raise SystemExit(
        f"libstd-*.so not found in {rustlibs}; build stage2 for {target} first "
        "(`./x.py build --stage 2 --target <t> library`)."
    )
# safe to call run()
env.run(args)

Type guard

null

Try / catch

try:
    test_env.run(args)
except Exception as e:
    if "Failed to locate libstd" in str(e):
        logging.error("Rust build incomplete for target %s; run x.py build --stage 2.", env.target)
    raise

Prevention

When it happens

Trigger: The 'run' subcommand is invoked (fuchsia-test-runner.py:691) and glob at line 688 finds zero files matching {rust_build_dir}/host/stage2/lib/rustlib/{target}/lib/libstd-*.so.

Common situations: The Rust build was not completed to stage2 for the Fuchsia target; --rust-build passed to 'start' points at the wrong build directory; --target does not match the triple actually built; only a host build exists without the target's rustlib; the build used static libstd so no .so was emitted (schema/build-system change).

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/7f02264f2750b7a2. Report an issue: GitHub.