Skip to content

[SYCL] Add MAJOR_VERSION to the name of the sycl library on Win #6745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2022
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
4 changes: 4 additions & 0 deletions clang/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ if(WIN32)
set(system_libs version)
endif()

# This must be in sync with llvm/sycl/CMakeLists.txt.
SET_SOURCE_FILES_PROPERTIES( ToolChains/MSVC.cpp ToolChains/Clang.cpp
PROPERTIES COMPILE_DEFINITIONS SYCL_MAJOR_VERSION="5" )

add_clang_library(clangDriver
Action.cpp
Compilation.cpp
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8144,9 +8144,9 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
if (Args.hasArg(options::OPT_fsycl) &&
!Args.hasArg(options::OPT_nolibsycl)) {
if (RTOptionID == options::OPT__SLASH_MDd)
CmdArgs.push_back("--dependent-lib=sycld");
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION "d");
else
CmdArgs.push_back("--dependent-lib=sycl");
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION);
CmdArgs.push_back("--dependent-lib=sycl-devicelib-host");
}
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/MSVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
TC.getDriver().Dir + "/../lib"));
if (Args.hasArg(options::OPT_g_Flag))
CmdArgs.push_back("-defaultlib:sycld.lib");
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION "d.lib");
else
CmdArgs.push_back("-defaultlib:sycl.lib");
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION ".lib");
CmdArgs.push_back("-defaultlib:sycl-devicelib-host.lib");
}

Expand Down
24 changes: 12 additions & 12 deletions clang/test/Driver/sycl-offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,35 +639,35 @@
// CHECK-LD-NOSTDLIB: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD-NOSTDLIB-NOT: "-lsycl"

/// Check for default linking of sycl.lib with -fsycl usage
/// Check for default linking of syclN.lib with -fsycl usage
// RUN: %clang -fsycl -target x86_64-unknown-windows-msvc %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL %s
// RUN: %clang_cl -fsycl %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-CL %s
// CHECK-LINK-SYCL-CL: "--dependent-lib=sycl"
// CHECK-LINK-SYCL-CL-NOT: "-defaultlib:sycl.lib"
// CHECK-LINK-SYCL: "-defaultlib:sycl.lib"
// CHECK-LINK-SYCL-CL: "--dependent-lib=sycl{{[0-9]*}}"
// CHECK-LINK-SYCL-CL-NOT: "-defaultlib:sycl{{[0-9]*}}.lib"
// CHECK-LINK-SYCL: "-defaultlib:sycl{{[0-9]*}}.lib"

/// Check no SYCL runtime is linked with -nolibsycl
// RUN: %clang -fsycl -nolibsycl -target x86_64-unknown-windows-msvc %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-NOLIBSYCL %s
// RUN: %clang_cl -fsycl -nolibsycl %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-NOLIBSYCL-CL %s
// CHECK-LINK-NOLIBSYCL-CL-NOT: "--dependent-lib=sycl"
// CHECK-LINK-NOLIBSYCL-CL-NOT: "--dependent-lib=sycl{{[0-9]*}}"
// CHECK-LINK-NOLIBSYCL: "{{.*}}link{{(.exe)?}}"
// CHECK-LINK-NOLIBSYCL-NOT: "-defaultlib:sycl.lib"
// CHECK-LINK-NOLIBSYCL-NOT: "-defaultlib:sycl{{[0-9]*}}.lib"

/// Check SYCL runtime is linked despite -nostdlib on Windows, this is
/// necessary for the Windows Clang CMake to work
// RUN: %clang -fsycl -nostdlib -target x86_64-unknown-windows-msvc %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-NOSTDLIB %s
// RUN: %clang_cl -fsycl -nostdlib %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-NOSTDLIB-CL %s
// CHECK-LINK-NOSTDLIB-CL: "--dependent-lib=sycl"
// CHECK-LINK-NOSTDLIB-CL: "--dependent-lib=sycl{{[0-9]*}}"
// CHECK-LINK-NOSTDLIB: "{{.*}}link{{(.exe)?}}"
// CHECK-LINK-NOSTDLIB: "-defaultlib:sycl.lib"
// CHECK-LINK-NOSTDLIB: "-defaultlib:sycl{{[0-9]*}}.lib"

/// Check sycld.lib is chosen with /MDd or -g
// RUN: %clang -fsycl -g -target x86_64-unknown-windows-msvc %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
// RUN: %clang_cl -fsycl /MDd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG-CL %s
// CHECK-LINK-SYCL-DEBUG-CL: "--dependent-lib=sycld"
// CHECK-LINK-SYCL-DEBUG-CL-NOT: "-defaultlib:sycld.lib"
// CHECK-LINK-SYCL-DEBUG: "-defaultlib:sycld.lib"
// CHECK-LINK-SYCL-DEBUG-NOT: "--dependent-lib=sycld"
// CHECK-LINK-SYCL-DEBUG-CL: "--dependent-lib=sycl{{[0-9]*}}d"
// CHECK-LINK-SYCL-DEBUG-CL-NOT: "-defaultlib:sycl{{[0-9]*}}d.lib"
// CHECK-LINK-SYCL-DEBUG: "-defaultlib:sycl{{[0-9]*}}d.lib"
// CHECK-LINK-SYCL-DEBUG-NOT: "--dependent-lib=sycl{{[0-9]*}}d"

/// Check "-spirv-allow-unknown-intrinsics=llvm.genx." option is emitted for llvm-spirv tool
// RUN: %clangxx %s -fsycl -### 2>&1 | FileCheck %s --check-prefix=CHK-ALLOW-INTRIN
Expand Down
13 changes: 10 additions & 3 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ include(AddSYCLExecutable)
include(AddSYCL)
include(SYCLUtils)

# The change in SYCL_MAJOR_VERSION must be accompanied with the same update in
# llvm/clang/lib/Driver/CMakeLists.txt.
set(SYCL_MAJOR_VERSION 5)
set(SYCL_MINOR_VERSION 7)
set(SYCL_PATCH_VERSION 0)
Expand Down Expand Up @@ -201,9 +203,14 @@ install(DIRECTORY "${sycl_inc_dir}/CL" DESTINATION ${SYCL_INCLUDE_DIR}/sycl COMP
install(DIRECTORY "${sycl_inc_dir}/std" DESTINATION ${SYCL_INCLUDE_DIR} COMPONENT sycl-headers)
install(DIRECTORY ${BOOST_MP11_DESTINATION_DIR} DESTINATION ${SYCL_INCLUDE_DIR}/sycl/detail COMPONENT boost_mp11-headers)

set(SYCL_RT_LIBS sycl)
if (MSVC)
list(APPEND SYCL_RT_LIBS sycld)
if (WIN32)
set(SYCL_RT_LIBS sycl${SYCL_MAJOR_VERSION})
# Do we really support non-MSVC ABI on WIN?
if (MSVC)
list(APPEND SYCL_RT_LIBS sycl${SYCL_MAJOR_VERSION}d)
endif()
else()
set(SYCL_RT_LIBS sycl)
endif()

# This function allows building multiple libraries with the same options.
Expand Down
23 changes: 16 additions & 7 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ if (SYCL_ENABLE_XPTI_TRACING)
include_directories(${LLVM_EXTERNAL_XPTI_SOURCE_DIR}/include)
endif()

function(add_sycl_rt_library LIB_NAME)
function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
# Add an optional argument so we can get the library name to
# link with for Windows Debug version
cmake_parse_arguments(ARG "" "XPTI_LIB" "COMPILE_OPTIONS;SOURCES" ${ARGN})

set(LIB_OBJ_NAME ${LIB_NAME}_object)

add_library(${LIB_OBJ_NAME} OBJECT ${ARG_SOURCES})
add_library(${LIB_NAME} SHARED
$<TARGET_OBJECTS:${LIB_OBJ_NAME}>
Expand Down Expand Up @@ -201,18 +199,29 @@ if (MSVC)
endforeach()

if (SYCL_ENABLE_XPTI_TRACING)
add_sycl_rt_library(sycld XPTI_LIB xptid COMPILE_OPTIONS "/MDd" SOURCES ${SYCL_SOURCES})
add_sycl_rt_library(sycl${SYCL_MAJOR_VERSION}d sycld_object XPTI_LIB xptid COMPILE_OPTIONS "/MDd" SOURCES ${SYCL_SOURCES})
else()
add_sycl_rt_library(sycld COMPILE_OPTIONS "/MDd" SOURCES ${SYCL_SOURCES})
add_sycl_rt_library(sycl${SYCL_MAJOR_VERSION}d sycld_object COMPILE_OPTIONS "/MDd" SOURCES ${SYCL_SOURCES})
endif()
add_library(sycld ALIAS sycl${SYCL_MAJOR_VERSION}d)

set(SYCL_EXTRA_OPTS "/MD")
endif()

if (WIN32)
set(LIB_NAME "sycl${SYCL_MAJOR_VERSION}")
else()
set(LIB_NAME "sycl")
endif()

if (SYCL_ENABLE_XPTI_TRACING)
add_sycl_rt_library(sycl XPTI_LIB xpti COMPILE_OPTIONS ${SYCL_EXTRA_OPTS} SOURCES ${SYCL_SOURCES})
add_sycl_rt_library(${LIB_NAME} sycl_object XPTI_LIB xpti COMPILE_OPTIONS ${SYCL_EXTRA_OPTS} SOURCES ${SYCL_SOURCES})
else()
add_sycl_rt_library(sycl COMPILE_OPTIONS ${SYCL_EXTRA_OPTS} SOURCES ${SYCL_SOURCES})
add_sycl_rt_library(${LIB_NAME} sycl_object COMPILE_OPTIONS ${SYCL_EXTRA_OPTS} SOURCES ${SYCL_SOURCES})
endif()

if (WIN32)
add_library(sycl ALIAS ${LIB_NAME})
endif()

install(TARGETS ${SYCL_RT_LIBS}
Expand Down