From 4ac243d6b011d36ee589db3e04bc0a714d64a3c1 Mon Sep 17 00:00:00 2001 From: SirAlienTheGreat Date: Mon, 4 Aug 2025 11:17:06 -0600 Subject: [PATCH 1/8] Create 0000-include-clang-in-llem-tools.md --- text/0000-include-clang-in-llem-tools.md | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 text/0000-include-clang-in-llem-tools.md diff --git a/text/0000-include-clang-in-llem-tools.md b/text/0000-include-clang-in-llem-tools.md new file mode 100644 index 00000000000..770fc6b68d4 --- /dev/null +++ b/text/0000-include-clang-in-llem-tools.md @@ -0,0 +1,55 @@ +- Feature Name: +- Start Date: 2025-08-04 +- RFC PR: [rust-lang/rfcs#0000]() +- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) + +# Summary +[summary]: #summary + +Include a version of `clang` and `clang++` compiled against rust LLVM in the `llvm-tools` component in nightly. + +# Motivation +[motivation]: #motivation + +Allowing user-access to the LLVM pipeline allows for many user-built features, such as cross-language inlining. However, LLVM version mismatching between tools can lead to frustrating problems. Including `clang` and `clang++` in `llvm-tools` allows users to use only the tools that rust ships with, ensuring consistent versioning. + +## Background + +`clang` and `clang++` are LLVM-based C and C++ compilers mentioned in [official documentation](https://dev-doc.rust-lang.org/beta/rustc/linker-plugin-lto.html) +```bash +# Compile the Rust staticlib +RUSTFLAGS="-Clinker-plugin-lto" cargo build --release +# Compile the C code with `-flto=thin` +clang -c -O2 -flto=thin -o cmain.o ./cmain.c +# Link everything, making sure that we use an appropriate linker +clang -flto=thin -fuse-ld=lld -L . -l"name-of-your-rust-lib" -o main -O2 ./cmain.o +``` +Unfortunately, this example does not always work, because it calls system `clang`, which may use a different version of LLVM than Rust. Additionally, even at the same version, there is a potential for problems from mixing base LLVM tools with the Rust fork of LLVM. + +Rustup has the ability to install a component called `llvm-tools`, which exposes the llvm tools used by Rust, including `llvm-link` and `llc` - notably, it does not contain a build of `clang` or `clang++` + +## Conclusion + +Builds of `clang` and `clang++` should be added to the `llvm-tools` component to enable version matching when working with base LLVM tools + +# Drawbacks +[drawbacks]: #drawbacks + +This will increase compile times and require more storage on devices with the `llvm-tools` component installed + +It may also drive more people to use manual compilation processes, which may cause fragmentation or be at odds with the Rust vision + +# Rationale and alternatives +[rationale-and-alternatives]: #rationale-and-alternatives + +Users can opt for system `clang` and `clang++` when building projects with LLVM, however there is no guarantee that users will have an appropriate version of the system tools, or that the Rust fork of LLVM won't contain any breaking changes. + +# Prior art +[prior-art]: #prior-art + +This may help in the goal [Expose experimental LLVM features for GPU offloading](https://rust-lang.github.io/rust-project-goals/2025h1/GPU-Offload.html), as raw LLVM access is particularly useful for GPU compilation libraries. + +# Unresolved questions +[unresolved-questions]: #unresolved-questions + +Should `clang` and `clang++` be part of the `llvm-tools` component or added as their own component? From 07d66ac6300cd455bda1b0571fb6583f356414e8 Mon Sep 17 00:00:00 2001 From: SirAlienTheGreat Date: Mon, 4 Aug 2025 11:17:52 -0600 Subject: [PATCH 2/8] fix typo --- ...clang-in-llem-tools.md => 0000-include-clang-in-llvm-tools.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename text/{0000-include-clang-in-llem-tools.md => 0000-include-clang-in-llvm-tools.md} (100%) diff --git a/text/0000-include-clang-in-llem-tools.md b/text/0000-include-clang-in-llvm-tools.md similarity index 100% rename from text/0000-include-clang-in-llem-tools.md rename to text/0000-include-clang-in-llvm-tools.md From ad38a7fd124c8020b114b694bf32f8397a9e251a Mon Sep 17 00:00:00 2001 From: SirAlienTheGreat Date: Mon, 4 Aug 2025 13:06:29 -0600 Subject: [PATCH 3/8] revisions --- text/0000-include-clang-in-llvm-tools.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/text/0000-include-clang-in-llvm-tools.md b/text/0000-include-clang-in-llvm-tools.md index 770fc6b68d4..d904785f764 100644 --- a/text/0000-include-clang-in-llvm-tools.md +++ b/text/0000-include-clang-in-llvm-tools.md @@ -1,4 +1,4 @@ -- Feature Name: +- Feature Name: Include Clang in llvm-tools - Start Date: 2025-08-04 - RFC PR: [rust-lang/rfcs#0000]() - Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) @@ -13,9 +13,11 @@ Include a version of `clang` and `clang++` compiled against rust LLVM in the `ll Allowing user-access to the LLVM pipeline allows for many user-built features, such as cross-language inlining. However, LLVM version mismatching between tools can lead to frustrating problems. Including `clang` and `clang++` in `llvm-tools` allows users to use only the tools that rust ships with, ensuring consistent versioning. +In future versions of Rust, including a compiler with Rustup could also improve ergonomics for FFI crates, as it could avoid depending on system compilers. See how [Zed's implementation](https://actually.fyi/posts/zig-makes-rust-cross-compilation-just-work/) led to easy cross-compiles in rust to Macos. + ## Background -`clang` and `clang++` are LLVM-based C and C++ compilers mentioned in [official documentation](https://dev-doc.rust-lang.org/beta/rustc/linker-plugin-lto.html) +`clang` and `clang++` are LLVM-based C and C++ compilers mentioned in [official documentation](https://doc.rust-lang.org/rustc/linker-plugin-lto.html) ```bash # Compile the Rust staticlib RUSTFLAGS="-Clinker-plugin-lto" cargo build --release @@ -26,7 +28,7 @@ clang -flto=thin -fuse-ld=lld -L . -l"name-of-your-rust-lib" -o main -O2 ./cmain ``` Unfortunately, this example does not always work, because it calls system `clang`, which may use a different version of LLVM than Rust. Additionally, even at the same version, there is a potential for problems from mixing base LLVM tools with the Rust fork of LLVM. -Rustup has the ability to install a component called `llvm-tools`, which exposes the llvm tools used by Rust, including `llvm-link` and `llc` - notably, it does not contain a build of `clang` or `clang++` +Rustup has the ability to install a component called `llvm-tools`, which exposes the llvm tools used by Rust, including `llvm-link` and `llc` - notably, it does not contain a build of `clang` or `clang++`. ## Conclusion @@ -49,6 +51,10 @@ Users can opt for system `clang` and `clang++` when building projects with LLVM, This may help in the goal [Expose experimental LLVM features for GPU offloading](https://rust-lang.github.io/rust-project-goals/2025h1/GPU-Offload.html), as raw LLVM access is particularly useful for GPU compilation libraries. +This was mentioned in [Shipping clang as a rustup component](https://github.com/rust-lang/rust/issues/56371) + +See also the issues for [`llvm-dis`, `llc` and `opt`](https://github.com/rust-lang/rust/issues/55890) + # Unresolved questions [unresolved-questions]: #unresolved-questions From 1d9f2b67a21ceefa35870259f26d38ccc00dde42 Mon Sep 17 00:00:00 2001 From: SirAlienTheGreat Date: Mon, 4 Aug 2025 14:49:44 -0600 Subject: [PATCH 4/8] punctuation --- text/0000-include-clang-in-llvm-tools.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/text/0000-include-clang-in-llvm-tools.md b/text/0000-include-clang-in-llvm-tools.md index d904785f764..c4b8da941dc 100644 --- a/text/0000-include-clang-in-llvm-tools.md +++ b/text/0000-include-clang-in-llvm-tools.md @@ -6,7 +6,7 @@ # Summary [summary]: #summary -Include a version of `clang` and `clang++` compiled against rust LLVM in the `llvm-tools` component in nightly. +Include a version of `clang` and `clang++` compiled against Rust LLVM in the `llvm-tools` component in nightly. # Motivation [motivation]: #motivation @@ -17,7 +17,7 @@ In future versions of Rust, including a compiler with Rustup could also improve ## Background -`clang` and `clang++` are LLVM-based C and C++ compilers mentioned in [official documentation](https://doc.rust-lang.org/rustc/linker-plugin-lto.html) +`clang` and `clang++` are LLVM-based C and C++ compilers mentioned in [official documentation](https://doc.rust-lang.org/rustc/linker-plugin-lto.html): ```bash # Compile the Rust staticlib RUSTFLAGS="-Clinker-plugin-lto" cargo build --release @@ -32,14 +32,14 @@ Rustup has the ability to install a component called `llvm-tools`, which exposes ## Conclusion -Builds of `clang` and `clang++` should be added to the `llvm-tools` component to enable version matching when working with base LLVM tools +Builds of `clang` and `clang++` should be added to the `llvm-tools` component to enable version matching when working with base LLVM tools. # Drawbacks [drawbacks]: #drawbacks -This will increase compile times and require more storage on devices with the `llvm-tools` component installed +This will increase compile times and require more storage on devices with the `llvm-tools` component installed. -It may also drive more people to use manual compilation processes, which may cause fragmentation or be at odds with the Rust vision +It may also drive more people to use manual compilation processes, which may cause fragmentation or be at odds with the Rust vision. # Rationale and alternatives [rationale-and-alternatives]: #rationale-and-alternatives From 44d0dce9936f21d37eefc3e61ee7ec2b1b054368 Mon Sep 17 00:00:00 2001 From: SirAlienTheGreat Date: Mon, 4 Aug 2025 20:46:58 -0600 Subject: [PATCH 5/8] capitalization --- text/0000-include-clang-in-llvm-tools.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/text/0000-include-clang-in-llvm-tools.md b/text/0000-include-clang-in-llvm-tools.md index c4b8da941dc..f5fa2d12d24 100644 --- a/text/0000-include-clang-in-llvm-tools.md +++ b/text/0000-include-clang-in-llvm-tools.md @@ -11,7 +11,7 @@ Include a version of `clang` and `clang++` compiled against Rust LLVM in the `ll # Motivation [motivation]: #motivation -Allowing user-access to the LLVM pipeline allows for many user-built features, such as cross-language inlining. However, LLVM version mismatching between tools can lead to frustrating problems. Including `clang` and `clang++` in `llvm-tools` allows users to use only the tools that rust ships with, ensuring consistent versioning. +Allowing user-access to the LLVM pipeline allows for many user-built features, such as cross-language inlining. However, LLVM version mismatching between tools can lead to frustrating problems. Including `clang` and `clang++` in `llvm-tools` allows users to use only the tools that Rust ships with, ensuring consistent versioning. In future versions of Rust, including a compiler with Rustup could also improve ergonomics for FFI crates, as it could avoid depending on system compilers. See how [Zed's implementation](https://actually.fyi/posts/zig-makes-rust-cross-compilation-just-work/) led to easy cross-compiles in rust to Macos. @@ -51,7 +51,7 @@ Users can opt for system `clang` and `clang++` when building projects with LLVM, This may help in the goal [Expose experimental LLVM features for GPU offloading](https://rust-lang.github.io/rust-project-goals/2025h1/GPU-Offload.html), as raw LLVM access is particularly useful for GPU compilation libraries. -This was mentioned in [Shipping clang as a rustup component](https://github.com/rust-lang/rust/issues/56371) +This was mentioned in [Shipping clang as a Rustup component](https://github.com/rust-lang/rust/issues/56371) See also the issues for [`llvm-dis`, `llc` and `opt`](https://github.com/rust-lang/rust/issues/55890) From fc8f2520a889a915079c4e7ae2a4b5f3aab7c526 Mon Sep 17 00:00:00 2001 From: SirAlienTheGreat Date: Mon, 4 Aug 2025 20:47:46 -0600 Subject: [PATCH 6/8] typo --- text/0000-include-clang-in-llvm-tools.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0000-include-clang-in-llvm-tools.md b/text/0000-include-clang-in-llvm-tools.md index f5fa2d12d24..643a070c301 100644 --- a/text/0000-include-clang-in-llvm-tools.md +++ b/text/0000-include-clang-in-llvm-tools.md @@ -13,7 +13,7 @@ Include a version of `clang` and `clang++` compiled against Rust LLVM in the `ll Allowing user-access to the LLVM pipeline allows for many user-built features, such as cross-language inlining. However, LLVM version mismatching between tools can lead to frustrating problems. Including `clang` and `clang++` in `llvm-tools` allows users to use only the tools that Rust ships with, ensuring consistent versioning. -In future versions of Rust, including a compiler with Rustup could also improve ergonomics for FFI crates, as it could avoid depending on system compilers. See how [Zed's implementation](https://actually.fyi/posts/zig-makes-rust-cross-compilation-just-work/) led to easy cross-compiles in rust to Macos. +In future versions of Rust, including a compiler with Rustup could also improve ergonomics for FFI crates, as it could avoid depending on system compilers. See how [Zig's implementation](https://actually.fyi/posts/zig-makes-rust-cross-compilation-just-work/) led to easy cross-compiles in rust to Macos. ## Background From 0f5c50d80e1b4f47c244a8715c103b5d59d3dad2 Mon Sep 17 00:00:00 2001 From: SirAlienTheGreat <79958059+SirAlienTheGreat@users.noreply.github.com> Date: Wed, 6 Aug 2025 16:09:51 -0600 Subject: [PATCH 7/8] include RFC PR number --- text/0000-include-clang-in-llvm-tools.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0000-include-clang-in-llvm-tools.md b/text/0000-include-clang-in-llvm-tools.md index 643a070c301..4ce7c7ec07d 100644 --- a/text/0000-include-clang-in-llvm-tools.md +++ b/text/0000-include-clang-in-llvm-tools.md @@ -1,6 +1,6 @@ - Feature Name: Include Clang in llvm-tools - Start Date: 2025-08-04 -- RFC PR: [rust-lang/rfcs#0000]() +- RFC PR: [rust-lang/rfcs#3847]() - Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000) # Summary From f8322239b2f40c4def5d5aeee9869071373f7433 Mon Sep 17 00:00:00 2001 From: SirAlienTheGreat Date: Thu, 7 Aug 2025 13:54:13 -0600 Subject: [PATCH 8/8] Stability Guarantee --- text/0000-include-clang-in-llvm-tools.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/text/0000-include-clang-in-llvm-tools.md b/text/0000-include-clang-in-llvm-tools.md index 4ce7c7ec07d..78178b37289 100644 --- a/text/0000-include-clang-in-llvm-tools.md +++ b/text/0000-include-clang-in-llvm-tools.md @@ -13,7 +13,7 @@ Include a version of `clang` and `clang++` compiled against Rust LLVM in the `ll Allowing user-access to the LLVM pipeline allows for many user-built features, such as cross-language inlining. However, LLVM version mismatching between tools can lead to frustrating problems. Including `clang` and `clang++` in `llvm-tools` allows users to use only the tools that Rust ships with, ensuring consistent versioning. -In future versions of Rust, including a compiler with Rustup could also improve ergonomics for FFI crates, as it could avoid depending on system compilers. See how [Zig's implementation](https://actually.fyi/posts/zig-makes-rust-cross-compilation-just-work/) led to easy cross-compiles in rust to Macos. +In future versions of Rust, including a compiler with Rustup could also improve ergonomics for FFI crates, as it could avoid depending on system compilers. See how [Zig's implementation](https://actually.fyi/posts/zig-makes-rust-cross-compilation-just-work/) led to easy cross-compiles in Rust to Macos. ## Background @@ -30,6 +30,10 @@ Unfortunately, this example does not always work, because it calls system `clang Rustup has the ability to install a component called `llvm-tools`, which exposes the llvm tools used by Rust, including `llvm-link` and `llc` - notably, it does not contain a build of `clang` or `clang++`. +## Stability Guarantee + +The only stability guarantee is that the versions of `clang` and `clang++` will have the same LLVM version as Rust and the other LLVM tools. It is not guaranteed that `clang` and `clang++` will never break their own interfaces. + ## Conclusion Builds of `clang` and `clang++` should be added to the `llvm-tools` component to enable version matching when working with base LLVM tools.