Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ pub use macros::Debug;
),
on(
from_desugaring = "FormatLiteral",
note = "in format strings you may be able to use `{{:?}}` (or {{:#?}} for pretty-print) instead",
note = "in format strings you may be able to use `{{:?}}` (or `{{:#?}}` for pretty-print) instead",
label = "`{Self}` cannot be formatted with the default formatter",
),
message = "`{Self}` doesn't implement `{This}`"
Expand Down
11 changes: 4 additions & 7 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2281,9 +2281,9 @@ impl CommandLineStep for Assemble {

if builder.config.llvm_offload && !builder.config.dry_run() {
debug!("`llvm_offload` requested");
let rust_offload = builder.ensure(llvm::RustOffload { target: build_compiler.host });
let offload_install = builder.ensure(llvm::OmpOffload { target: build_compiler.host });
if let Some(_llvm_config) = builder.llvm_config(builder.config.host_target) {
let rust_offload =
builder.ensure(llvm::RustOffload { target: build_compiler.host });
let target_libdir =
builder.sysroot_target_libdir(target_compiler, target_compiler.host);
let rust_offload_dst_lib = target_libdir.join(rust_offload.rust_offload_filename());
Expand All @@ -2293,15 +2293,12 @@ impl CommandLineStep for Assemble {
FileType::NativeLibrary,
);

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

Expand Down
56 changes: 56 additions & 0 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,62 @@ impl CommandLineStep for Enzyme {
}
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Offload {
pub target: TargetSelection,
}

impl CommandLineStep for Offload {
type Output = Option<GeneratedTarball>;
const IS_HOST: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.alias("offload")
}

fn is_default_step(builder: &Builder<'_>) -> bool {
builder.config.llvm_offload
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Offload { target: run.target });
}

fn run(self, builder: &Builder<'_>) -> Self::Output {
if !builder.unstable_features() {
return None;
}

let target = self.target;

let omp_offload = builder.ensure(llvm::OmpOffload { target });
let rust_offload = builder.ensure(llvm::RustOffload { target });

if builder.config.dry_run() {
return None;
}

let target_libdir = PathBuf::from(format!("lib/rustlib/{}/lib", target.triple));

let mut tarball = Tarball::new(builder, "offload", &target.triple);
tarball.set_overlay(OverlayKind::Offload);
tarball.is_preview(true);

let omp_offload_libdir = builder.out.join(target).join("offload").join("lib");

for path in omp_offload.artifact_paths_with_symlink_targets() {
let relative = t!(path.strip_prefix(&omp_offload_libdir));
let destdir = target_libdir.join(relative.parent().unwrap());

tarball.add_file(path, destdir, FileType::NativeLibrary);
}

tarball.add_file(rust_offload.rust_offload_path(), target_libdir, FileType::NativeLibrary);

Some(tarball.generate())
}
}

/// Tarball intended for internal consumption to ease rustc/std development.
///
/// Should not be considered stable by end users.
Expand Down
56 changes: 53 additions & 3 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,25 @@ pub struct BuiltOmpOffload {
}

impl BuiltOmpOffload {
pub fn offload_paths(&self) -> Vec<PathBuf> {
self.offload.clone()
pub fn artifact_paths_with_symlink_targets(&self) -> Vec<PathBuf> {
let mut paths = self.offload.clone();

for path in &self.offload {
let mut current = path.clone();

while t!(fs::symlink_metadata(&current)).file_type().is_symlink() {
let target = t!(fs::read_link(&current));
current = current.parent().unwrap().join(target);

if paths.contains(&current) {
break;
}

paths.push(current.clone());
}
}

paths
}
}

Expand Down Expand Up @@ -1101,6 +1118,30 @@ impl CommandLineStep for OmpOffload {
files.push(out_dir.join("lib").join("libLLVMOffload").with_extension(lib_ext));
files.push(out_dir.join("lib").join("libomp").with_extension(lib_ext));
files.push(out_dir.join("lib").join("libomptarget").with_extension(lib_ext));
files.push(
out_dir.join("lib").join("amdgcn-amd-amdhsa").join("libompdevice").with_extension("a"),
);
files.push(
out_dir
.join("lib")
.join("amdgcn-amd-amdhsa")
.join("libomptarget-amdgpu")
.with_extension("bc"),
);
files.push(
out_dir
.join("lib")
.join("nvptx64-nvidia-cuda")
.join("libompdevice")
.with_extension("a"),
);
files.push(
out_dir
.join("lib")
.join("nvptx64-nvidia-cuda")
.join("libomptarget-nvptx")
.with_extension("bc"),
);

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

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

configure_cmake(builder, target, &mut cfg, true, ldflags, cflags, &[]);

// Re-use the same flags as llvm to control the level of debug information
// generated for offload.
Expand Down Expand Up @@ -1196,6 +1245,7 @@ impl CommandLineStep for OmpOffload {
cfg.define("LLVM_ENABLE_RUNTIMES", "openmp;offload");
} else {
// OpenMP provides some device libraries, so we also compile it for all gpu targets.
cfg.define("OPENMP_INSTALL_LIBDIR", Path::new("lib").join(omp_target));
cfg.define("LLVM_USE_LINKER", "lld");
cfg.define("LLVM_ENABLE_RUNTIMES", "openmp");
cfg.define("CMAKE_C_COMPILER_TARGET", omp_target);
Expand Down
53 changes: 25 additions & 28 deletions src/bootstrap/src/core/builder/cli_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,34 @@ pub(crate) fn match_paths_to_steps_and_run(
}
}

// Attempt to resolve paths to be relative to the builder source directory.
let mut paths: Vec<PathBuf> = paths
// Command-line paths are interpreted relative to the repository root
// (not the current working directory).
//
// If the user or shell passed an absolute path, try to strip off the
// repository root, to match the paths registered by command-line steps.
//
// E.g. `/home/ferris/rust/tests/ui/asm/cfg.rs` => `tests/ui/asm/cfg.rs`
let mut paths = paths
.iter()
.map(|original_path| {
let mut path = original_path.clone();

// Someone could run `x <cmd> <path>` from a different repository than the source
// directory.
// In that case, we should not try to resolve the paths relative to the working
// directory, but rather relative to the source directory.
// So we forcefully "relocate" the path to the source directory here.
if !path.is_absolute() {
path = builder.src.join(path);
}

// If the path does not exist, it may represent the name of a Step, such as `tidy` in `x test tidy`
if !path.exists() {
// Use the original path here
return original_path.clone();
}

// Make the path absolute, strip the prefix, and convert to a PathBuf.
match std::path::absolute(&path) {
Ok(p) => p.strip_prefix(&builder.src).unwrap_or(&p).to_path_buf(),
Err(e) => {
eprintln!("ERROR: {e:?}");
panic!("Due to the above error, failed to resolve path: {path:?}");
}
.map(|path| {
if path.is_absolute()
&& path.exists()
&& let Ok(relative) = path.strip_prefix(&builder.src)
{
relative
} else {
path
}
})
.collect();
.map(|p| p.to_owned())
.collect::<Vec<_>>();

// If any absolute paths couldn't be made relative, stop now and report them.
let bad_abs_paths = paths.iter().filter(|path| path.is_absolute()).collect::<Vec<_>>();
if !bad_abs_paths.is_empty() {
eprintln!("ERROR: failed to resolve absolute paths: {bad_abs_paths:#?}");
crate::exit!(1);
}

// Handle all test suite paths.
// (This is separate from the loop below to avoid having to handle multiple paths in `is_suite_path` somehow.)
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ impl<'a> Builder<'a> {
dist::LlvmBitcodeLinker,
dist::RustDev,
dist::Enzyme,
dist::Offload,
dist::Bootstrap,
dist::Extended,
// It seems that PlainSourceTarball somehow changes how some of the tools
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub(crate) enum OverlayKind {
Gcc,
LlvmBitcodeLinker,
Enzyme,
Offload,
}

impl OverlayKind {
Expand All @@ -39,6 +40,9 @@ impl OverlayKind {
&["src/llvm-project/llvm/LICENSE.TXT", "src/llvm-project/llvm/README.txt"]
}
OverlayKind::Enzyme => &["src/tools/enzyme/LICENSE", "src/tools/enzyme/Readme.md"],
OverlayKind::Offload => {
&["src/llvm-project/openmp/LICENSE.TXT", "src/llvm-project/offload/README.md"]
}
OverlayKind::Cargo => &[
"src/tools/cargo/README.md",
"src/tools/cargo/LICENSE-MIT",
Expand Down Expand Up @@ -114,6 +118,7 @@ impl OverlayKind {
OverlayKind::LlvmBitcodeLinker => builder.rust_version(),
OverlayKind::Gcc => builder.rust_version(),
OverlayKind::Enzyme => builder.rust_version(),
OverlayKind::Offload => builder.rust_version(),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ RUN ./cmake.sh
# Now build LLVM+Clang, afterwards configuring further compilations to use the
# clang/clang++ compilers.
COPY scripts/build-clang.sh /tmp/
ENV LLVM_BUILD_TARGETS=X86
ENV LLVM_BUILD_TARGETS="X86;AMDGPU;NVPTX"
RUN ./build-clang.sh
ENV CC=clang CXX=clang++

Expand All @@ -91,6 +91,7 @@ ENV RUST_CONFIGURE_ARGS="--enable-full-tools \
--set llvm.ninja=false \
--set llvm.libzstd=true \
--set build.allocator=jemalloc \
--set llvm.offload-clang-dir="/rustroot/lib/cmake/clang" \
--set rust.bootstrap-override-lld=true \
--set rust.lto=thin \
--set rust.codegen-units=1"
Expand Down
1 change: 1 addition & 0 deletions src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ python3 ../x.py build --set rust.debug=true opt-dist
build-manifest \
bootstrap \
enzyme \
offload \
rustc_codegen_gcc

# Use GCC for building GCC components, as it seems to behave badly when built with Clang
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/fmt/format-args-argument-span.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | println!("{x:?} {x} {x:?}");
| ^^^ `Option<{integer}>` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Option<{integer}>`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: in format strings you may be able to use `{:?}` (or `{:#?}` for pretty-print) instead

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

error[E0277]: `DisplayOnly` doesn't implement `Debug`
--> $DIR/format-args-argument-span.rs:18:19
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/fmt/non-source-literals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ help: the trait `std::fmt::Display` is not implemented for `NonDisplay`
|
LL | pub struct NonDisplay;
| ^^^^^^^^^^^^^^^^^^^^^
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: in format strings you may be able to use `{:?}` (or `{:#?}` for pretty-print) instead

error[E0277]: `NonDisplay` doesn't implement `std::fmt::Display`
--> $DIR/non-source-literals.rs:10:45
Expand All @@ -22,7 +22,7 @@ help: the trait `std::fmt::Display` is not implemented for `NonDisplay`
|
LL | pub struct NonDisplay;
| ^^^^^^^^^^^^^^^^^^^^^
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: in format strings you may be able to use `{:?}` (or `{:#?}` for pretty-print) instead

error[E0277]: `NonDebug` doesn't implement `Debug`
--> $DIR/non-source-literals.rs:11:42
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/macro-expansion-empty-span-147255.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | println!("{}", x_str);
| required by this formatting parameter
|
= help: the trait `std::fmt::Display` is not implemented for `()`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: in format strings you may be able to use `{:?}` (or `{:#?}` for pretty-print) instead

error: aborting due to 1 previous error

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/on-unimplemented/no-debug.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ help: the trait `std::fmt::Display` is not implemented for `Foo`
|
LL | struct Foo;
| ^^^^^^^^^^
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: in format strings you may be able to use `{:?}` (or `{:#?}` for pretty-print) instead

error[E0277]: `Bar` doesn't implement `std::fmt::Display`
--> $DIR/no-debug.rs:11:28
Expand All @@ -47,7 +47,7 @@ LL | println!("{} {}", Foo, Bar);
| required by this formatting parameter
|
= help: the trait `std::fmt::Display` is not implemented for `Bar`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: in format strings you may be able to use `{:?}` (or `{:#?}` for pretty-print) instead

error: aborting due to 4 previous errors

Expand Down
16 changes: 16 additions & 0 deletions tests/ui/structs/ice-missing-field-fn-sig-closure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// issue-link: https://github.com/rust-lang/rust/issues/160591
// A closure call with a struct literal missing a field shouldn't ICE when checking the fn sig.

trait Context {}
struct Wrapper<C: Context + 'static> {
container: &'static C,
}

fn main() {
let c = |_: Wrapper<()>| {}; //~ ERROR the trait bound `(): Context` is not satisfied
c(Wrapper { /* missing */ });
//~^ ERROR the trait bound `(): Context` is not satisfied
//~^^ ERROR missing field `container` in initializer of `Wrapper<_>`
//~^^^ ERROR the trait bound `(): Context` is not satisfied
//~^^^^ ERROR the trait bound `(): Context` is not satisfied
}
Loading
Loading