Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8ed9589
Auto merge of #143376 - dianne:guard-scope, r=matthewjasper
bors Aug 9, 2025
1c12df7
Auto merge of #144873 - cjgillot:implications, r=lqd
bors Aug 10, 2025
b1e2a44
Auto merge of #144081 - RalfJung:const-ptr-fragments, r=oli-obk
bors Aug 17, 2025
47774a7
Auto merge of #145348 - nnethercote:parse_token_tree-speedup-for-uom,…
bors Aug 20, 2025
83da87f
Allow linking a prebuilt optimized compiler-rt builtins library
Jun 24, 2025
8ab4089
Rollup merge of #143689 - pmur:murp/external-rt-optimized-compiler-bu…
Zalathar Aug 26, 2025
3482668
Rollup merge of #144885 - zachs18:ptr_guaranteed_cmp_more, r=RalfJung
Zalathar Aug 26, 2025
f77ef6c
Rollup merge of #145535 - lolbinarycat:rustdoc-invalid_html_tags-svg-…
Zalathar Aug 26, 2025
086f971
Rollup merge of #145766 - epage:rustfmt, r=calebcartwright
Zalathar Aug 26, 2025
6c85b8f
Rollup merge of #145811 - houpo-bob:master, r=samueltardieu
Zalathar Aug 26, 2025
6d67521
Rollup merge of #145814 - bjorn3:codegen_worker_fatal_error, r=petroc…
Zalathar Aug 26, 2025
2435778
Rollup merge of #145815 - jieyouxu:pr-check-timeout, r=marcoieni
Zalathar Aug 26, 2025
8fae5ff
Rollup merge of #145821 - lolbinarycat:compiletest-error-show, r=club…
Zalathar Aug 26, 2025
32cd396
Rollup merge of #145845 - Kobzol:fix-distcheck, r=jieyouxu
Zalathar Aug 26, 2025
bab8de5
Rollup merge of #145847 - madsmtm:no-xcrun-warnings, r=jieyouxu
Zalathar Aug 26, 2025
217a47f
Rollup merge of #145856 - rustbot:docs-update, r=ehuss
Zalathar Aug 26, 2025
71cd0f4
Rollup merge of #145858 - alexcrichton:update-wasm-component-ld, r=lqd
Zalathar Aug 26, 2025
c4920e1
Auto merge of #145871 - Zalathar:rollup-lag9tlg, r=Zalathar
bors Aug 26, 2025
0d825fd
Auto merge of #145874 - Kobzol:fix-dist-builds, r=jieyouxu
bors Aug 26, 2025
3a1c048
Auto merge of #144841 - cjgillot:typeck-no-attrs, r=davidtwco
bors Aug 27, 2025
6010821
Auto merge of #140737 - amandasystems:revised-constraint-search, r=lcnr
bors Aug 27, 2025
dc6978f
Auto merge of #145851 - lolbinarycat:rustdoc-optimize, r=GuillaumeGomez
bors Aug 27, 2025
9246173
Auto merge of #145877 - nikic:capture-address, r=tmiasko
bors Aug 28, 2025
a3f2743
Prepare for merging from rust-lang/rust
invalid-email-address Aug 28, 2025
ac3a4cd
Merge ref 'd36f96412516' from rust-lang/rust
invalid-email-address Aug 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler-builtins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ to be added as an explicit dependency in `Cargo.toml`.

[`compiler-rt`]: https://github.com/llvm/llvm-project/tree/1b1dc505057322f4fa1110ef4f53c44347f52986/compiler-rt

## Configuration

`compiler-builtins` can be configured with the following environment variables when the `c` feature
is enabled:

- `LLVM_COMPILER_RT_LIB`
- `RUST_COMPILER_RT_ROOT`

See `build.rs` for details.

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).
Expand Down
55 changes: 46 additions & 9 deletions compiler-builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,20 +540,28 @@ mod c {
sources.extend(&[("__emutls_get_address", "emutls.c")]);
}

// Optionally, link against a prebuilt llvm compiler-rt containing the builtins
// library. Only the builtins library is required. On many platforms, this is
// available as a library named libclang_rt.builtins.a.
let link_against_prebuilt_rt = env::var_os("LLVM_COMPILER_RT_LIB").is_some();

// When compiling the C code we require the user to tell us where the
// source code is, and this is largely done so when we're compiling as
// part of rust-lang/rust we can use the same llvm-project repository as
// rust-lang/rust.
let root = match env::var_os("RUST_COMPILER_RT_ROOT") {
Some(s) => PathBuf::from(s),
// If a prebuild libcompiler-rt is provided, set a valid
// path to simplify later logic. Nothing should be compiled.
None if link_against_prebuilt_rt => PathBuf::new(),
None => {
panic!(
"RUST_COMPILER_RT_ROOT is not set. You may need to run \
`ci/download-compiler-rt.sh`."
);
}
};
if !root.exists() {
if !link_against_prebuilt_rt && !root.exists() {
panic!("RUST_COMPILER_RT_ROOT={} does not exist", root.display());
}

Expand All @@ -569,7 +577,7 @@ mod c {
let src_dir = root.join("lib/builtins");
if target.arch == "aarch64" && target.env != "msvc" && target.os != "uefi" {
// See below for why we're building these as separate libraries.
build_aarch64_out_of_line_atomics_libraries(&src_dir, cfg);
build_aarch64_out_of_line_atomics_libraries(&src_dir, cfg, link_against_prebuilt_rt);

// Some run-time CPU feature detection is necessary, as well.
let cpu_model_src = if src_dir.join("cpu_model.c").exists() {
Expand All @@ -583,20 +591,45 @@ mod c {
let mut added_sources = HashSet::new();
for (sym, src) in sources.map.iter() {
let src = src_dir.join(src);
if added_sources.insert(src.clone()) {
if !link_against_prebuilt_rt && added_sources.insert(src.clone()) {
cfg.file(&src);
println!("cargo:rerun-if-changed={}", src.display());
}
println!("cargo:rustc-cfg={}=\"optimized-c\"", sym);
}

cfg.compile("libcompiler-rt.a");
if link_against_prebuilt_rt {
let rt_builtins_ext = PathBuf::from(env::var_os("LLVM_COMPILER_RT_LIB").unwrap());
if !rt_builtins_ext.exists() {
panic!(
"LLVM_COMPILER_RT_LIB={} does not exist",
rt_builtins_ext.display()
);
}
if let Some(dir) = rt_builtins_ext.parent() {
println!("cargo::rustc-link-search=native={}", dir.display());
}
if let Some(lib) = rt_builtins_ext.file_name() {
println!(
"cargo::rustc-link-lib=static:+verbatim={}",
lib.to_str().unwrap()
);
}
} else {
cfg.compile("libcompiler-rt.a");
}
}

fn build_aarch64_out_of_line_atomics_libraries(builtins_dir: &Path, cfg: &mut cc::Build) {
fn build_aarch64_out_of_line_atomics_libraries(
builtins_dir: &Path,
cfg: &mut cc::Build,
link_against_prebuilt_rt: bool,
) {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let outlined_atomics_file = builtins_dir.join("aarch64").join("lse.S");
println!("cargo:rerun-if-changed={}", outlined_atomics_file.display());
if !link_against_prebuilt_rt {
println!("cargo:rerun-if-changed={}", outlined_atomics_file.display());
}

cfg.include(&builtins_dir);

Expand All @@ -609,6 +642,13 @@ mod c {
for (model_number, model_name) in
&[(1, "relax"), (2, "acq"), (3, "rel"), (4, "acq_rel")]
{
let sym = format!("__aarch64_{}{}_{}", instruction_type, size, model_name);
println!("cargo:rustc-cfg={}=\"optimized-c\"", sym);

if link_against_prebuilt_rt {
continue;
}

// The original compiler-rt build system compiles the same
// source file multiple times with different compiler
// options. Here we do something slightly different: we
Expand All @@ -632,9 +672,6 @@ mod c {
.unwrap();
drop(file);
cfg.file(path);

let sym = format!("__aarch64_{}{}_{}", instruction_type, size, model_name);
println!("cargo:rustc-cfg={}=\"optimized-c\"", sym);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ffb9d94dcf4ade0d534842be3672d5e9f47e1333
d36f964125163c2e698de5559efefb8217b8b7f0
Loading