Skip to content

Commit e64c8a6

Browse files
committed
Auto merge of #160908 - jhpratt:rollup-a7bBwHd, r=jhpratt
Rollup of 4 pull requests Successful merges: - #159064 (Add offload support to the dist-x86_64-linux CI job) - #160746 (add regression tests for the fn sig ice) - #160855 (bootstrap: Simplify absolute path handling) - #160898 (Put `{:#?}` into backticks)
2 parents a04c7a0 + 7e9daa7 commit e64c8a6

21 files changed

Lines changed: 293 additions & 55 deletions

library/core/src/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ pub use macros::Debug;
11761176
),
11771177
on(
11781178
from_desugaring = "FormatLiteral",
1179-
note = "in format strings you may be able to use `{{:?}}` (or {{:#?}} for pretty-print) instead",
1179+
note = "in format strings you may be able to use `{{:?}}` (or `{{:#?}}` for pretty-print) instead",
11801180
label = "`{Self}` cannot be formatted with the default formatter",
11811181
),
11821182
message = "`{Self}` doesn't implement `{This}`"

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,9 +2281,9 @@ impl CommandLineStep for Assemble {
22812281

22822282
if builder.config.llvm_offload && !builder.config.dry_run() {
22832283
debug!("`llvm_offload` requested");
2284-
let rust_offload = builder.ensure(llvm::RustOffload { target: build_compiler.host });
2285-
let offload_install = builder.ensure(llvm::OmpOffload { target: build_compiler.host });
22862284
if let Some(_llvm_config) = builder.llvm_config(builder.config.host_target) {
2285+
let rust_offload =
2286+
builder.ensure(llvm::RustOffload { target: build_compiler.host });
22872287
let target_libdir =
22882288
builder.sysroot_target_libdir(target_compiler, target_compiler.host);
22892289
let rust_offload_dst_lib = target_libdir.join(rust_offload.rust_offload_filename());
@@ -2293,15 +2293,12 @@ impl CommandLineStep for Assemble {
22932293
FileType::NativeLibrary,
22942294
);
22952295

2296-
for p in offload_install.offload_paths() {
2296+
let omp_offload = builder.ensure(llvm::OmpOffload { target: build_compiler.host });
2297+
for p in omp_offload.artifact_paths_with_symlink_targets() {
22972298
let libname = p.file_name().unwrap();
22982299
let dst_lib = target_libdir.join(libname);
22992300
builder.resolve_symlink_and_copy(&p, &dst_lib);
23002301
}
2301-
// FIXME(offload): Add amdgcn-amd-amdhsa and nvptx64-nvidia-cuda folder
2302-
// This one is slightly more tricky, since we have the same file twice, in two
2303-
// subfolders for amdgcn and nvptx64. We'll likely find two more in the future, once
2304-
// Intel and Spir-V support lands in offload.
23052302
}
23062303
}
23072304

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,62 @@ impl CommandLineStep for Enzyme {
28132813
}
28142814
}
28152815

2816+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
2817+
pub struct Offload {
2818+
pub target: TargetSelection,
2819+
}
2820+
2821+
impl CommandLineStep for Offload {
2822+
type Output = Option<GeneratedTarball>;
2823+
const IS_HOST: bool = true;
2824+
2825+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2826+
run.alias("offload")
2827+
}
2828+
2829+
fn is_default_step(builder: &Builder<'_>) -> bool {
2830+
builder.config.llvm_offload
2831+
}
2832+
2833+
fn make_run(run: RunConfig<'_>) {
2834+
run.builder.ensure(Offload { target: run.target });
2835+
}
2836+
2837+
fn run(self, builder: &Builder<'_>) -> Self::Output {
2838+
if !builder.unstable_features() {
2839+
return None;
2840+
}
2841+
2842+
let target = self.target;
2843+
2844+
let omp_offload = builder.ensure(llvm::OmpOffload { target });
2845+
let rust_offload = builder.ensure(llvm::RustOffload { target });
2846+
2847+
if builder.config.dry_run() {
2848+
return None;
2849+
}
2850+
2851+
let target_libdir = PathBuf::from(format!("lib/rustlib/{}/lib", target.triple));
2852+
2853+
let mut tarball = Tarball::new(builder, "offload", &target.triple);
2854+
tarball.set_overlay(OverlayKind::Offload);
2855+
tarball.is_preview(true);
2856+
2857+
let omp_offload_libdir = builder.out.join(target).join("offload").join("lib");
2858+
2859+
for path in omp_offload.artifact_paths_with_symlink_targets() {
2860+
let relative = t!(path.strip_prefix(&omp_offload_libdir));
2861+
let destdir = target_libdir.join(relative.parent().unwrap());
2862+
2863+
tarball.add_file(path, destdir, FileType::NativeLibrary);
2864+
}
2865+
2866+
tarball.add_file(rust_offload.rust_offload_path(), target_libdir, FileType::NativeLibrary);
2867+
2868+
Some(tarball.generate())
2869+
}
2870+
}
2871+
28162872
/// Tarball intended for internal consumption to ease rustc/std development.
28172873
///
28182874
/// Should not be considered stable by end users.

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,25 @@ pub struct BuiltOmpOffload {
10461046
}
10471047

10481048
impl BuiltOmpOffload {
1049-
pub fn offload_paths(&self) -> Vec<PathBuf> {
1050-
self.offload.clone()
1049+
pub fn artifact_paths_with_symlink_targets(&self) -> Vec<PathBuf> {
1050+
let mut paths = self.offload.clone();
1051+
1052+
for path in &self.offload {
1053+
let mut current = path.clone();
1054+
1055+
while t!(fs::symlink_metadata(&current)).file_type().is_symlink() {
1056+
let target = t!(fs::read_link(&current));
1057+
current = current.parent().unwrap().join(target);
1058+
1059+
if paths.contains(&current) {
1060+
break;
1061+
}
1062+
1063+
paths.push(current.clone());
1064+
}
1065+
}
1066+
1067+
paths
10511068
}
10521069
}
10531070

@@ -1101,6 +1118,30 @@ impl CommandLineStep for OmpOffload {
11011118
files.push(out_dir.join("lib").join("libLLVMOffload").with_extension(lib_ext));
11021119
files.push(out_dir.join("lib").join("libomp").with_extension(lib_ext));
11031120
files.push(out_dir.join("lib").join("libomptarget").with_extension(lib_ext));
1121+
files.push(
1122+
out_dir.join("lib").join("amdgcn-amd-amdhsa").join("libompdevice").with_extension("a"),
1123+
);
1124+
files.push(
1125+
out_dir
1126+
.join("lib")
1127+
.join("amdgcn-amd-amdhsa")
1128+
.join("libomptarget-amdgpu")
1129+
.with_extension("bc"),
1130+
);
1131+
files.push(
1132+
out_dir
1133+
.join("lib")
1134+
.join("nvptx64-nvidia-cuda")
1135+
.join("libompdevice")
1136+
.with_extension("a"),
1137+
);
1138+
files.push(
1139+
out_dir
1140+
.join("lib")
1141+
.join("nvptx64-nvidia-cuda")
1142+
.join("libomptarget-nvptx")
1143+
.with_extension("bc"),
1144+
);
11041145

11051146
// Offload/OpenMP are just subfolders of LLVM, so we can use the LLVM sha.
11061147
static STAMP_HASH_MEMO: OnceLock<String> = OnceLock::new();
@@ -1167,7 +1208,15 @@ impl CommandLineStep for OmpOffload {
11671208
cflags.push_all(format!(" -I {inc_dir}"));
11681209
}
11691210

1170-
configure_cmake(builder, target, &mut cfg, true, LdFlags::default(), cflags, &[]);
1211+
// Logic copied from `configure_llvm`
1212+
// ThinLTO is only available when building with LLVM, enabling LLD is required.
1213+
// Apple's linker ld64 supports ThinLTO out of the box though, so don't use LLD on Darwin.
1214+
let mut ldflags = LdFlags::default();
1215+
if builder.config.llvm_thin_lto && !target.contains("apple") {
1216+
ldflags.push_all("-fuse-ld=lld");
1217+
}
1218+
1219+
configure_cmake(builder, target, &mut cfg, true, ldflags, cflags, &[]);
11711220

11721221
// Re-use the same flags as llvm to control the level of debug information
11731222
// generated for offload.
@@ -1196,6 +1245,7 @@ impl CommandLineStep for OmpOffload {
11961245
cfg.define("LLVM_ENABLE_RUNTIMES", "openmp;offload");
11971246
} else {
11981247
// OpenMP provides some device libraries, so we also compile it for all gpu targets.
1248+
cfg.define("OPENMP_INSTALL_LIBDIR", Path::new("lib").join(omp_target));
11991249
cfg.define("LLVM_USE_LINKER", "lld");
12001250
cfg.define("LLVM_ENABLE_RUNTIMES", "openmp");
12011251
cfg.define("CMAKE_C_COMPILER_TARGET", omp_target);

src/bootstrap/src/core/builder/cli_paths.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,34 @@ pub(crate) fn match_paths_to_steps_and_run(
7676
}
7777
}
7878

79-
// Attempt to resolve paths to be relative to the builder source directory.
80-
let mut paths: Vec<PathBuf> = paths
79+
// Command-line paths are interpreted relative to the repository root
80+
// (not the current working directory).
81+
//
82+
// If the user or shell passed an absolute path, try to strip off the
83+
// repository root, to match the paths registered by command-line steps.
84+
//
85+
// E.g. `/home/ferris/rust/tests/ui/asm/cfg.rs` => `tests/ui/asm/cfg.rs`
86+
let mut paths = paths
8187
.iter()
82-
.map(|original_path| {
83-
let mut path = original_path.clone();
84-
85-
// Someone could run `x <cmd> <path>` from a different repository than the source
86-
// directory.
87-
// In that case, we should not try to resolve the paths relative to the working
88-
// directory, but rather relative to the source directory.
89-
// So we forcefully "relocate" the path to the source directory here.
90-
if !path.is_absolute() {
91-
path = builder.src.join(path);
92-
}
93-
94-
// If the path does not exist, it may represent the name of a Step, such as `tidy` in `x test tidy`
95-
if !path.exists() {
96-
// Use the original path here
97-
return original_path.clone();
98-
}
99-
100-
// Make the path absolute, strip the prefix, and convert to a PathBuf.
101-
match std::path::absolute(&path) {
102-
Ok(p) => p.strip_prefix(&builder.src).unwrap_or(&p).to_path_buf(),
103-
Err(e) => {
104-
eprintln!("ERROR: {e:?}");
105-
panic!("Due to the above error, failed to resolve path: {path:?}");
106-
}
88+
.map(|path| {
89+
if path.is_absolute()
90+
&& path.exists()
91+
&& let Ok(relative) = path.strip_prefix(&builder.src)
92+
{
93+
relative
94+
} else {
95+
path
10796
}
10897
})
109-
.collect();
98+
.map(|p| p.to_owned())
99+
.collect::<Vec<_>>();
100+
101+
// If any absolute paths couldn't be made relative, stop now and report them.
102+
let bad_abs_paths = paths.iter().filter(|path| path.is_absolute()).collect::<Vec<_>>();
103+
if !bad_abs_paths.is_empty() {
104+
eprintln!("ERROR: failed to resolve absolute paths: {bad_abs_paths:#?}");
105+
crate::exit!(1);
106+
}
110107

111108
// Handle all test suite paths.
112109
// (This is separate from the loop below to avoid having to handle multiple paths in `is_suite_path` somehow.)

src/bootstrap/src/core/builder/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,7 @@ impl<'a> Builder<'a> {
10201020
dist::LlvmBitcodeLinker,
10211021
dist::RustDev,
10221022
dist::Enzyme,
1023+
dist::Offload,
10231024
dist::Bootstrap,
10241025
dist::Extended,
10251026
// It seems that PlainSourceTarball somehow changes how some of the tools

src/bootstrap/src/utils/tarball.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub(crate) enum OverlayKind {
2929
Gcc,
3030
LlvmBitcodeLinker,
3131
Enzyme,
32+
Offload,
3233
}
3334

3435
impl OverlayKind {
@@ -39,6 +40,9 @@ impl OverlayKind {
3940
&["src/llvm-project/llvm/LICENSE.TXT", "src/llvm-project/llvm/README.txt"]
4041
}
4142
OverlayKind::Enzyme => &["src/tools/enzyme/LICENSE", "src/tools/enzyme/Readme.md"],
43+
OverlayKind::Offload => {
44+
&["src/llvm-project/openmp/LICENSE.TXT", "src/llvm-project/offload/README.md"]
45+
}
4246
OverlayKind::Cargo => &[
4347
"src/tools/cargo/README.md",
4448
"src/tools/cargo/LICENSE-MIT",
@@ -114,6 +118,7 @@ impl OverlayKind {
114118
OverlayKind::LlvmBitcodeLinker => builder.rust_version(),
115119
OverlayKind::Gcc => builder.rust_version(),
116120
OverlayKind::Enzyme => builder.rust_version(),
121+
OverlayKind::Offload => builder.rust_version(),
117122
}
118123
}
119124
}

src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ RUN ./cmake.sh
6565
# Now build LLVM+Clang, afterwards configuring further compilations to use the
6666
# clang/clang++ compilers.
6767
COPY scripts/build-clang.sh /tmp/
68-
ENV LLVM_BUILD_TARGETS=X86
68+
ENV LLVM_BUILD_TARGETS="X86;AMDGPU;NVPTX"
6969
RUN ./build-clang.sh
7070
ENV CC=clang CXX=clang++
7171

@@ -91,6 +91,7 @@ ENV RUST_CONFIGURE_ARGS="--enable-full-tools \
9191
--set llvm.ninja=false \
9292
--set llvm.libzstd=true \
9393
--set build.allocator=jemalloc \
94+
--set llvm.offload-clang-dir="/rustroot/lib/cmake/clang" \
9495
--set rust.bootstrap-override-lld=true \
9596
--set rust.lto=thin \
9697
--set rust.codegen-units=1"

src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ python3 ../x.py build --set rust.debug=true opt-dist
1010
build-manifest \
1111
bootstrap \
1212
enzyme \
13+
offload \
1314
rustc_codegen_gcc
1415

1516
# Use GCC for building GCC components, as it seems to behave badly when built with Clang

tests/ui/fmt/format-args-argument-span.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | println!("{x:?} {x} {x:?}");
55
| ^^^ `Option<{integer}>` cannot be formatted with the default formatter
66
|
77
= help: the trait `std::fmt::Display` is not implemented for `Option<{integer}>`
8-
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
8+
= note: in format strings you may be able to use `{:?}` (or `{:#?}` for pretty-print) instead
99

1010
error[E0277]: `Option<{integer}>` doesn't implement `std::fmt::Display`
1111
--> $DIR/format-args-argument-span.rs:15:37
@@ -16,7 +16,7 @@ LL | println!("{x:?} {x} {x:?}", x = Some(1));
1616
| required by this formatting parameter
1717
|
1818
= help: the trait `std::fmt::Display` is not implemented for `Option<{integer}>`
19-
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
19+
= note: in format strings you may be able to use `{:?}` (or `{:#?}` for pretty-print) instead
2020

2121
error[E0277]: `DisplayOnly` doesn't implement `Debug`
2222
--> $DIR/format-args-argument-span.rs:18:19

0 commit comments

Comments
 (0)