diff --git a/compiler/rustc_builtin_macros/src/offload.rs b/compiler/rustc_builtin_macros/src/offload.rs index 006332b8c40c9..c8efdf016c99e 100644 --- a/compiler/rustc_builtin_macros/src/offload.rs +++ b/compiler/rustc_builtin_macros/src/offload.rs @@ -122,7 +122,7 @@ pub(crate) fn expand_kernel( span, ecx.path_global( span, - [sym::std, sym::unimplemented].map(|s| Ident::new(s, span)).to_vec(), + [sym::core, sym::unimplemented].map(|s| Ident::new(s, span)).to_vec(), ), Delimiter::Parenthesis, TokenStream::default(), diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 490888f87b38e..51e26d4ba5044 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -128,6 +128,18 @@ impl Linker { // any more, we can finalize it (which involves renaming it) rustc_incremental::finalize_session_directory(sess, incr_comp_session, self.crate_hash); + // The `HostMetadata` offload pass only writes the kernel manifest. + // Codegen was already skipped so there are no files to link. + if sess + .opts + .unstable_opts + .offload + .iter() + .any(|o| matches!(o, config::Offload::HostMetadata(_))) + { + return; + } + if !sess .opts .output_types diff --git a/tests/run-make/offload-host-std-device-nostd/example.rs b/tests/run-make/offload-host-std-device-nostd/example.rs new file mode 100644 index 0000000000000..03b76ae8be06f --- /dev/null +++ b/tests/run-make/offload-host-std-device-nostd/example.rs @@ -0,0 +1,22 @@ +#![feature(gpu_offload, rustc_attrs)] +#![allow(internal_features)] +#![cfg_attr(device, no_std)] +#![cfg_attr(device, no_main)] + +#[cfg(device)] +#[panic_handler] +fn panic(_: &core::panic::PanicInfo) -> ! { + loop {} +} + +#[rustc_offload_kernel] +fn kernel() {} + +#[cfg(not(device))] +fn main() { + core::offload::offload! { + kernel = kernel, + args = (), + } + println!("Hello from Host with std"); +} diff --git a/tests/run-make/offload-host-std-device-nostd/rmake.rs b/tests/run-make/offload-host-std-device-nostd/rmake.rs new file mode 100644 index 0000000000000..35f408e8b1cd0 --- /dev/null +++ b/tests/run-make/offload-host-std-device-nostd/rmake.rs @@ -0,0 +1,40 @@ +//@ needs-offload + +// Tests offload with no-std in device and std in host + +use run_make_support::{cwd, rfs, rustc}; + +fn main() { + rustc() + .input("example.rs") + .arg("-Zunstable-options") + .arg("-Zoffload=HostMetadata=example.manifest") + .arg("-Csymbol-mangling-version=v0") + .arg("-Clto=fat") + .emit("metadata") + .run(); + + rustc() + .input("example.rs") + .cfg("device") + .arg("-Zunstable-options") + .arg("-Zoffload=Device=example.manifest") + .arg("-Csymbol-mangling-version=v0") + .arg("-Clto=fat") + .arg("-Cpanic=abort") + .emit("obj") + .run(); + + rfs::write(cwd().join("device.bin"), [0u8; 8]); + + rustc() + .input("example.rs") + .arg("-Zunstable-options") + .arg(format!("-Zoffload=Host={}", cwd().join("device.bin").display())) + .arg("-Csymbol-mangling-version=v0") + .arg("-Clto=fat") + .emit("obj") + .run(); + + assert!(cwd().join("host.o").exists()); +} diff --git a/tests/ui/offload/duplicate_kernel.rs b/tests/ui/offload/duplicate_kernel.rs index da667a0c0666a..7dd8d7ee11225 100644 --- a/tests/ui/offload/duplicate_kernel.rs +++ b/tests/ui/offload/duplicate_kernel.rs @@ -5,7 +5,7 @@ // An offload kernel whose mangled symbol collides with another item in the // same crate must be rejected, just like any other symbol collision. -#![feature(core_intrinsics, rustc_attrs)] +#![feature(rustc_attrs, gpu_offload)] #![allow(internal_features)] #[allow(non_snake_case)] @@ -18,5 +18,5 @@ fn kernel(_x: f32) {} fn main() { _RNvC19collision_kernels_a6kernel(0.0); - core::intrinsics::offload::<_, _, ()>(kernel, [1, 1, 1], [1, 1, 1], 0, -1, (0.0f32,)); + core::offload::offload! { kernel = kernel, args = (0.0f32,) } } diff --git a/tests/ui/offload/non_tuple_args.rs b/tests/ui/offload/non_tuple_args.rs index 14de21b2374a2..2c63b6d6abe81 100644 --- a/tests/ui/offload/non_tuple_args.rs +++ b/tests/ui/offload/non_tuple_args.rs @@ -1,10 +1,10 @@ //@ compile-flags: -Zunstable-options -Zoffload=Device -Clto=fat -#![feature(core_intrinsics)] +#![feature(gpu_offload)] fn main() { // args_ty is not a tuple - core::intrinsics::offload::<_, _, ()>(kernel_0, [1, 1, 1], [1, 1, 1], 0, -1, 42); + core::offload::offload! { kernel = kernel_0, args = 42 } //~^ ERROR `{integer}` is not a tuple } diff --git a/tests/ui/offload/non_tuple_args.stderr b/tests/ui/offload/non_tuple_args.stderr index 90b0f16bec53e..26687d4b4bbb7 100644 --- a/tests/ui/offload/non_tuple_args.stderr +++ b/tests/ui/offload/non_tuple_args.stderr @@ -1,11 +1,12 @@ error[E0277]: `{integer}` is not a tuple - --> $DIR/non_tuple_args.rs:7:36 + --> $DIR/non_tuple_args.rs:7:5 | -LL | core::intrinsics::offload::<_, _, ()>(kernel_0, [1, 1, 1], [1, 1, 1], 0, -1, 42); - | ^ the nightly-only, unstable trait `std::marker::Tuple` is not implemented for `{integer}` +LL | core::offload::offload! { kernel = kernel_0, args = 42 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `std::marker::Tuple` is not implemented for `{integer}` | note: required by a bound in `offload` --> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL + = note: this error originates in the macro `$crate::offload` which comes from the expansion of the macro `core::offload::offload` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error