Skip to content

bootstrap.py needs a lockfile to prevent concurrent invocations #143756

@lolbinarycat

Description

@lolbinarycat

Summary

cargo uses lockfiles to protect the build directory, however these only protect against parallel invocations of cargo, and bootstrap does a bunch of other file manipulations that

Command used

./x tidy & ./x tidy

Expected behaviour

One invocation acquires the lockfile, while the other blocks and waits for the lockfile to be unlocked, resuming once the first one is complete.

This is a problem because or rust-analyzer config recommends going through ./x check, which may cause build cache corruption if the user runs an ./x.py command at the same time r-a decides to do a check.

Actual behaviour

Both instances of bootstrap try to operate on the same files at the same time, causing one of them to crash.

Bootstrap configuration (bootstrap.toml)

profile = "tools"  # Includes one of the default files in src/bootstrap/defaults
change-id = 138986

rust.debuginfo-level = 1
#rust.jemalloc = true
rust.download-rustc = false
rust.deny-warnings = false
build.docs-minification = false
#build.incremental = false
build.tidy-extra-checks = "auto:py"

Operating system

Arch Linux

HEAD

78a6e13

Additional context

Build Log

extracting /home/binarycat/src/rs/rust/build/cache/2025-06-24/rustc-beta-x86_64-unknown-linux-gnu.tar.xz
extracting /home/binarycat/src/rs/rust/build/cache/2025-06-24/rust-std-beta-x86_64-unknown-linux-gnu.tar.xz
extracting /home/binarycat/src/rs/rust/build/cache/2025-06-24/cargo-beta-x86_64-unknown-linux-gnu.tar.xz
Traceback (most recent call last):
  File "/home/binarycat/src/rs/rust/x.py", line 53, in <module>
    bootstrap.main()
    ~~~~~~~~~~~~~~^^
  File "/home/binarycat/src/rs/rust/src/bootstrap/bootstrap.py", line 1372, in main
    bootstrap(args)
    ~~~~~~~~~^^^^^^
  File "/home/binarycat/src/rs/rust/src/bootstrap/bootstrap.py", line 1337, in bootstrap
    build.download_toolchain()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/binarycat/src/rs/rust/src/bootstrap/bootstrap.py", line 696, in download_toolchain
    shutil.rmtree(bootstrap_build_artifacts)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/shutil.py", line 763, in rmtree
    _rmtree_safe_fd(stack, onexc)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/shutil.py", line 704, in _rmtree_safe_fd
    onexc(func, path, err)
    ~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/shutil.py", line 658, in _rmtree_safe_fd
    os.rmdir(name, dir_fd=dirfd)
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/binarycat/src/rs/rust/build/bootstrap/debug'

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions