Skip to content

bootstrap: x.py dist rustc-src should keep LLVM's siphash #145121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

lambdageek
Copy link
Contributor

@lambdageek lambdageek commented Aug 8, 2025

Fixes #145117

@rustbot
Copy link
Collaborator

rustbot commented Aug 8, 2025

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 8, 2025
@rustbot

This comment has been minimized.

@lambdageek lambdageek force-pushed the dist-must-keep-llvm-third-party-siphash branch from 4e6df5a to d078184 Compare August 8, 2025 17:57
@rustbot

This comment has been minimized.

@lambdageek lambdageek force-pushed the dist-must-keep-llvm-third-party-siphash branch from d078184 to a27a7ec Compare August 8, 2025 17:58
@rust-log-analyzer

This comment has been minimized.

@lambdageek lambdageek force-pushed the dist-must-keep-llvm-third-party-siphash branch from a27a7ec to f208a45 Compare August 8, 2025 18:09
@rust-log-analyzer

This comment has been minimized.

@lambdageek lambdageek force-pushed the dist-must-keep-llvm-third-party-siphash branch from f208a45 to f05b20a Compare August 8, 2025 19:01
@lambdageek lambdageek force-pushed the dist-must-keep-llvm-third-party-siphash branch from f05b20a to cba5918 Compare August 8, 2025 19:12
@Kobzol
Copy link
Member

Kobzol commented Aug 8, 2025

Thanks for taking a look! I think that something like this makes sense, yeah. I wonder why distcheck didn't catch this though.. 🤔 Ah, because it only checks plain source tarball and src, and not rustc-src.. we have too many source tarballs.

r? @Kobzol

@rustbot rustbot assigned Kobzol and unassigned jieyouxu Aug 8, 2025
@lambdageek
Copy link
Contributor Author

@Kobzol rustc-src is the plain source tarball, isn't it?

run.alias("rustc-src").default_condition(builder.config.rust_dist_src)

@lambdageek
Copy link
Contributor Author

does distcheck build LLVM? Could it be using the cached one?

@Kobzol
Copy link
Member

Kobzol commented Aug 8, 2025

Right, the naming confused me yet again, sorry. Hmm, then that's weird, as distcheck should do some simple build after extracing the source tarball.. I'll have to investigate that.

@Kobzol
Copy link
Member

Kobzol commented Aug 8, 2025

it shouldn't be using cached LLVM.

@lambdageek
Copy link
Contributor Author

lambdageek commented Aug 8, 2025

So here's a suspicious thing that happens when I do x.py test distcheck locally on an x86_64-unknown-linux-gnu with master:

running: cd "/home/aleksey/hacking/upstream-rust/build/tmp/distcheck/build/x86_64-unknown-linux-gnu/llvm/build" && CMAKE_PREFIX_PATH="" DESTDIR="" LC_ALL="C" "cmake" "/home/aleksey/hacking/upstream-rust/src/llvm-project/llvm" "-G" "Ninja" "-DLLVM_ENABLE_ASSERTIONS=OFF" "-DLLVM_UNREACHABLE_OPTIMIZE=OFF" "-DLLVM_ENABLE_PLUGINS=OFF" "-DLLVM_TARGETS_TO_BUILD=AArch64;AMDGPU;ARM;BPF;Hexagon;LoongArch;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR;M68k;CSKY;Xtensa" "-DLLVM_INCLUDE_EXAMPLES=OFF" "-DLLVM_INCLUDE_DOCS=OFF" "-DLLVM_INCLUDE_BENCHMARKS=OFF" "-DLLVM_INCLUDE_TESTS=OFF" "-DLLVM_ENABLE_LIBEDIT=OFF" "-DLLVM_ENABLE_BINDINGS=OFF" "-DLLVM_ENABLE_Z3_SOLVER=OFF" "-DLLVM_PARALLEL_COMPILE_JOBS=16" "-DLLVM_TARGET_ARCH=x86_64" "-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu" "-DLLVM_ENABLE_WARNINGS=OFF" "-DLLVM_INSTALL_UTILS=ON" "-DLLVM_ENABLE_ZLIB=ON" "-DLLVM_ENABLE_LIBXML2=OFF" "-DLLVM_VERSION_SUFFIX=-rust-1.91.0-nightly" "-DCMAKE_INSTALL_MESSAGE=LAZY" "-DCMAKE_C_COMPILER=cc" "-DCMAKE_CXX_COMPILER=c++" "-DCMAKE_ASM_COMPILER=cc" "-DCMAKE_C_FLAGS=-ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_FLAGS=-ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_SHARED_LINKER_FLAGS=" "-DCMAKE_MODULE_LINKER_FLAGS=" "-DCMAKE_EXE_LINKER_FLAGS=" "-DLLVM_ENABLE_ZSTD=OFF" "-DCMAKE_INSTALL_PREFIX=/home/aleksey/hacking/upstream-rust/build/tmp/distcheck/build/x86_64-unknown-linux-gnu/llvm" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_BUILD_TYPE=Release"

we're in the <git_root>/build/tmp/distcheck/build/... directory, so it's the build that distcheck invokes,
but we're calling cmake on <git_root>/src/llvm-project/llvm not on the llvm from the tarball.

Here's my bootstrap.toml
# Use different pre-set defaults than the global defaults.
#
# See `src/bootstrap/defaults` for more information.
# Note that this has no default value (x.py uses the defaults in `bootstrap.example.toml`).
profile = 'dist'

[llvm]
download-ci-llvm = false
targets = "AArch64;X86"

[gcc]

[build]

# Arguments passed to the `./configure` script, used during distcheck. You
# probably won't fill this in but rather it's filled in by the `./configure`
# script. Useful for debugging.
configure-args = []

[install]

[rust]
download-rustc = false

[dist]
vendor = false
compression-formats = ["gz"]

[target.x86_64-unknown-linux-gnu]

(and I also modify distcheck not to pass --enable-vendor; it's just to speed things up a bit; but i'll try a pristine tree, soon, too)

@lambdageek
Copy link
Contributor Author

lambdageek commented Aug 8, 2025

Yeah you can see the same thing on CI

for example this build the raw log has this:

2025-08-08T21:21:12.0222503Z running: cd "/checkout/obj/build/tmp/distcheck/build/x86_64-unknown-linux-gnu/llvm/build" && CMAKE_PREFIX_PATH="" DESTDIR="" LC_ALL="C" "cmake" "/checkout/src/llvm-project/llvm" "-G" "Ninja" "-DLLVM_ENABLE_ASSERTIONS=ON" "-DLLVM_UNREACHABLE_OPTIMIZE=OFF" "-DLLVM_ENABLE_PLUGINS=OFF" "-DLLVM_TARGETS_TO_BUILD=AArch64;AMDGPU;ARM;BPF;Hexagon;LoongArch;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR;M68k;CSKY;Xtensa" "-DLLVM_INCLUDE_EXAMPLES=OFF" "-DLLVM_INCLUDE_DOCS=OFF" "-DLLVM_INCLUDE_BENCHMARKS=OFF" "-DLLVM_INCLUDE_TESTS=OFF" "-DLLVM_ENABLE_LIBEDIT=OFF" "-DLLVM_ENABLE_BINDINGS=OFF" "-DLLVM_ENABLE_Z3_SOLVER=OFF" "-DLLVM_PARALLEL_COMPILE_JOBS=4" "-DLLVM_TARGET_ARCH=x86_64" "-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu" "-DLLVM_ENABLE_WARNINGS=OFF" "-DLLVM_INSTALL_UTILS=ON" "-DLLVM_ENABLE_ZLIB=ON" "-DLLVM_ENABLE_LIBXML2=OFF" "-DLLVM_VERSION_SUFFIX=-rust-1.91.0-nightly" "-DCMAKE_INSTALL_MESSAGE=LAZY" "-DCMAKE_C_COMPILER_LAUNCHER=sccache" "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache" "-DCMAKE_C_COMPILER=cc" "-DCMAKE_CXX_COMPILER=c++" "-DCMAKE_ASM_COMPILER=cc" "-DCMAKE_C_FLAGS=-ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_FLAGS=-ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_SHARED_LINKER_FLAGS= -Wl,-Bsymbolic -static-libstdc++" "-DCMAKE_MODULE_LINKER_FLAGS= -Wl,-Bsymbolic -static-libstdc++" "-DCMAKE_EXE_LINKER_FLAGS= -Wl,-Bsymbolic -static-libstdc++" "-DLLVM_ENABLE_ZSTD=OFF" "-DCMAKE_INSTALL_PREFIX=/checkout/obj/build/tmp/distcheck/build/x86_64-unknown-linux-gnu/llvm" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_BUILD_TYPE=Release"

we're in the tmp/distcheck build but the sources we're compiling are /checkout/src/llvm-project/llvm not build/tmp/distcheck/src/llvm-project

@lambdageek
Copy link
Contributor Author

lambdageek commented Aug 9, 2025

Ok, it's happening because distcheck just invokes make check which runs .../build/tmp/distcheck/src/bootstrap/bootstrap.py test --stage 2

when the inner bootstrap runs, it calls compute_src_directory where flags_src is None

if let Some(src) = compute_src_directory(flags_src, &config.exec_ctx) {
config.src = src;
}

And compute_src_directory ends up executing git rev-parse --show-cdup with cwd in .../build/tmp/distcheck so it ends up setting src to the outer git checkout, not the current extracted tarball. From there, all the git_info for the submodules ends up finding them in the outer git checkout.

I tried a naive change to add --src $(CFG_SRC_DIR) here:

BOOTSTRAP := $(CFG_PYTHON) $(CFG_SRC_DIR)src/bootstrap/bootstrap.py

but then .../bootstrap.py --src ... test --stage 2 fails when it runs the tidy check:

Commit SHA of the src/gcc submodule (``) does not match the required GCC version of the GCC codegen backend (`04ce66d8c918de9273bd7101638ad8724edf5e21`).
Make sure to set the src/gcc submodule to commit 04ce66d8c918de9273bd7101638ad8724edf5e21.
The GCC codegen backend commit is configured at /home/aleksey/hacking/upstream-rust/build/tmp/distcheck/compiler/rustc_codegen_gcc/libgccjit.version.

Which makes sense because we specifically exclude src/gcc from the plain tarball.

And at this point I'm stuck. I can't tell if there's some way to configure tidy not to do the gcc_submodule check or maybe the plain tarball should include some breadcrumb that the tidy check could look for


Update yeah if i comment out the tidy gcc_submodule check, and pass --src in Makefile.in, I can get distcheck to do the right thing:

running: cd "/home/aleksey/hacking/upstream-rust/build/tmp/distcheck/build/x86_64-unknown-linux-gnu/llvm/build" && CMAKE_PREFIX_PATH="" DESTDIR="" LC_ALL="C" "cmake" "/home/aleksey/hacking/upstream-rust/build/tmp/distcheck/src/llvm-project/llvm ..."

Update2:

@Kobzol I went ahead and added the distcheck fix here too:

  1. pass --src in Makefile.in
  2. teach tidy gcc_submodule to look for the src/gcc/notice.txt that we create in the tarball

Does that sound right?

I am not sure if passing --src in the Makefile is ok. It probably affects a lot more than just distcheck. Maybe some less invasive change would be better? Is there some way to directly invoke bootstrap.py without going through the Makefile?

@rustbot rustbot added the A-tidy Area: The tidy tool label Aug 9, 2025
@lambdageek lambdageek force-pushed the dist-must-keep-llvm-third-party-siphash branch from b9676c2 to ea85921 Compare August 9, 2025 02:00
@Kobzol
Copy link
Member

Kobzol commented Aug 9, 2025

Thanks a lot for investigating this! ❤️ It seems like distcheck is due for a big overhaul.. I would probably modify it so that it extracts itself to some temporary directory, and then invoke the build from there, to minimize the chances that it will pick up something unrelated from the source checkout. And also we should pass --set llvm.download-ci-llvm = false to it explicitly, and not read configure_args from the external environment.

Let's avoid any changes to distcheck and tidy in this PR, and just fix the LLVM build.

@lambdageek
Copy link
Contributor Author

lambdageek commented Aug 9, 2025

@Kobzol Ok, sounds good. I reverted the distcheck and tidy changes in this PR, and created a new issue about distcheck: #145183

@lambdageek
Copy link
Contributor Author

lambdageek commented Aug 9, 2025

@Kobzol I'm somewhat unhappy with all the "foo/bar", "foo\\bar" duplication all over the filter. I assume this is to avoid doing allocations. Is this filter on the hot path? What if instead of &[&str] we had LazyLock<Vec<&Path>> for all the interesting constants?

@Kobzol
Copy link
Member

Kobzol commented Aug 10, 2025

It's called for every path, so I imagine it might be hot, yeah. But probably there's a much better way of implementing this.. Anyway, we can resolve that in a separate PR. Thank you for investigating this! I can't reproduce the original issue on Linux, but the directory is now there in the archive, so hopefully it should help on macOS.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Aug 10, 2025

📌 Commit cba5918 has been approved by Kobzol

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 10, 2025
bors added a commit that referenced this pull request Aug 10, 2025
Rollup of 7 pull requests

Successful merges:

 - #144553 (Rehome 32 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`)
 - #145064 (Add regression test for `saturating_sub` bounds check issue)
 - #145121 (bootstrap: `x.py dist rustc-src` should keep LLVM's siphash)
 - #145150 (Replace unsafe `security_attributes` function with safe `inherit_handle` alternative)
 - #145152 (Use `eq_ignore_ascii_case` to avoid heap alloc in `detect_confuse_type`)
 - #145200 (mbe: Fix typo in attribute tracing)
 - #145222 (Fix typo with paren rustc_llvm/build.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 92bdf9e into rust-lang:master Aug 10, 2025
20 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 10, 2025
rust-timer added a commit that referenced this pull request Aug 10, 2025
Rollup merge of #145121 - lambdageek:dist-must-keep-llvm-third-party-siphash, r=Kobzol

bootstrap: `x.py dist rustc-src` should keep LLVM's siphash

Fixes #145117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tidy Area: The tidy tool S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

x.py dist rustc-src does not include llvm-project/third-party/siphash
6 participants