@@ -1227,12 +1227,26 @@ packageSYCLBIN(SYCLBIN::BundleState State,
12271227 return *OutFileOrErr;
12281228}
12291229
1230+ Error copyFileToFinalExecutable (StringRef File, const ArgList &Args) {
1231+ if (Verbose || DryRun) {
1232+ llvm::Triple Triple (Args.getLastArgValue (OPT_host_triple_EQ,
1233+ sys::getDefaultTargetTriple ()));
1234+ StringRef CopyCommand = Triple.isOSWindows () ? " copy" : " cp" ;
1235+ llvm::errs () << " \" " << CopyCommand << " \" " << File << " "
1236+ << ExecutableName << " \n " ;
1237+ }
1238+ // TODO: check if copy can be replaced by rename.
1239+ if (std::error_code EC = sys::fs::copy_file (File, ExecutableName))
1240+ return createFileError (ExecutableName, EC);
1241+ return Error::success ();
1242+ }
1243+
12301244Error mergeSYCLBIN (ArrayRef<StringRef> Files, const ArgList &Args) {
12311245 // Fast path for the general case where there's only one file. In this case we
12321246 // do not need to parse it and can instead simply copy it.
12331247 if (Files.size () == 1 ) {
1234- if (std::error_code EC = sys::fs::copy_file (Files[0 ], ExecutableName ))
1235- return createFileError (ExecutableName, EC );
1248+ if (Error Err = copyFileToFinalExecutable (Files[0 ], Args ))
1249+ reportError ( std::move (Err) );
12361250 return Error::success ();
12371251 }
12381252 // TODO: Merge SYCLBIN files here and write to ExecutableName output.
@@ -2227,7 +2241,7 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
22272241
22282242 // Store the offloading image for each linked output file.
22292243 for (OffloadKind Kind = OFK_OpenMP; Kind != OFK_LAST;
2230- Kind = static_cast <OffloadKind>((uint16_t )(Kind) << 1 )) {
2244+ Kind = static_cast <OffloadKind>((uint16_t )(Kind) << 1 )) {
22312245 if ((ActiveOffloadKindMask & Kind) == 0 )
22322246 continue ;
22332247 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileOrErr =
@@ -2789,6 +2803,14 @@ int main(int Argc, char **Argv) {
27892803 if (OutputSYCLBIN) {
27902804 if (Error Err = sycl::mergeSYCLBIN (*FilesOrErr, Args))
27912805 reportError (std::move (Err));
2806+ } else if (Args.hasArg (OPT_sycl_device_link)) {
2807+ // Skip host linker if --sycl-device-link option is set.
2808+ // Just copy the output of device linking and wrapping action.
2809+ if (FilesOrErr->size () != 1 )
2810+ reportError (
2811+ createStringError (" Expect single output from the device linker." ));
2812+ if (Error Err = sycl::copyFileToFinalExecutable ((*FilesOrErr)[0 ], Args))
2813+ reportError (std::move (Err));
27922814 } else {
27932815 // Run the host linking job with the rendered arguments.
27942816 if (Error Err = runLinker (*FilesOrErr, Args))
0 commit comments