Skip to content

Commit

Permalink
Merge pull request microsoft#2218 from jasjuang/llvm
Browse files Browse the repository at this point in the history
[llvm] add in clang and enable tools
  • Loading branch information
ras0219-msft authored Jan 5, 2018
2 parents 2ce964f + de98ec6 commit cf80234
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 39 deletions.
2 changes: 1 addition & 1 deletion ports/llvm/CONTROL
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Source: llvm
Version: 5.0.0-2
Version: 5.0.0-4
Description: The LLVM Compiler Infrastructure
Build-Depends: atlmfc
26 changes: 25 additions & 1 deletion ports/llvm/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ vcpkg_download_distfile(ARCHIVE
)
vcpkg_extract_source_archive(${ARCHIVE})

vcpkg_download_distfile(CLANG_ARCHIVE
URLS "http://releases.llvm.org/5.0.0/cfe-5.0.0.src.tar.xz"
FILENAME "cfe-5.0.0.src.tar.xz"
SHA512 14acdd622310122b544c952ee5b932b7006d9d8424319f0e3974f2503d40a0cec4200fdd3d813a32ce0d877bcfbb9a5bd5c36f6142b4330e6c814f113ca2efe8
)
vcpkg_extract_source_archive(${CLANG_ARCHIVE} ${SOURCE_PATH}/tools)

if(NOT EXISTS ${SOURCE_PATH}/tools/clang)
file(RENAME ${SOURCE_PATH}/tools/cfe-5.0.0.src ${SOURCE_PATH}/tools/clang)
endif()

vcpkg_apply_patches(
SOURCE_PATH ${SOURCE_PATH}
PATCHES ${CMAKE_CURRENT_LIST_DIR}/install-cmake-modules-to-share.patch
Expand All @@ -29,7 +40,7 @@ vcpkg_configure_cmake(
PREFER_NINJA
OPTIONS
-DLLVM_TARGETS_TO_BUILD=X86
-DLLVM_INCLUDE_TOOLS=OFF
-DLLVM_INCLUDE_TOOLS=ON
-DLLVM_INCLUDE_UTILS=OFF
-DLLVM_INCLUDE_EXAMPLES=OFF
-DLLVM_INCLUDE_TESTS=OFF
Expand All @@ -39,13 +50,26 @@ vcpkg_configure_cmake(

vcpkg_install_cmake()

file(GLOB EXE ${CURRENT_PACKAGES_DIR}/bin/*)
file(GLOB DEBUG_EXE ${CURRENT_PACKAGES_DIR}/debug/bin/*)
file(COPY ${EXE} DESTINATION ${CURRENT_PACKAGES_DIR}/tools/llvm)
file(COPY ${DEBUG_EXE} DESTINATION ${CURRENT_PACKAGES_DIR}/debug/tools/llvm)
file(REMOVE ${EXE})
file(REMOVE ${DEBUG_EXE})

vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/clang TARGET_PATH share/clang)
vcpkg_fixup_cmake_targets(CONFIG_PATH share/llvm)
vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/llvm)

file(REMOVE_RECURSE
${CURRENT_PACKAGES_DIR}/debug/include
${CURRENT_PACKAGES_DIR}/debug/tools
${CURRENT_PACKAGES_DIR}/debug/share
${CURRENT_PACKAGES_DIR}/debug/bin
${CURRENT_PACKAGES_DIR}/debug/msbuild-bin
${CURRENT_PACKAGES_DIR}/bin
${CURRENT_PACKAGES_DIR}/msbuild-bin
${CURRENT_PACKAGES_DIR}/tools/msbuild-bin
)

# Remove one empty include subdirectory if it is indeed empty
Expand Down
105 changes: 82 additions & 23 deletions scripts/cmake/vcpkg_build_cmake.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ function(vcpkg_build_cmake)
set(_bc_LOGFILE_ROOT "build")
endif()

set(PARALLEL_ARG)
set(NO_PARALLEL_ARG)

if(_VCPKG_CMAKE_GENERATOR MATCHES "Ninja")
set(BUILD_ARGS "-v") # verbose output
if (_bc_DISABLE_PARALLEL)
list(APPEND BUILD_ARGS "-j1")
endif()
set(NO_PARALLEL_ARG "-j1")
elseif(_VCPKG_CMAKE_GENERATOR MATCHES "Visual Studio")
set(BUILD_ARGS
"/p:VCPkgLocalAppDataDisabled=true"
"/p:UseIntelMKL=No"
)
if (NOT _bc_DISABLE_PARALLEL)
list(APPEND BUILD_ARGS "/m")
endif()
set(PARALLEL_ARG "/m")
elseif(_VCPKG_CMAKE_GENERATOR MATCHES "NMake")
# No options are currently added for nmake builds
else()
Expand All @@ -58,23 +57,83 @@ function(vcpkg_build_cmake)
set(TARGET_PARAM)
endif()

if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
message(STATUS "Build ${TARGET_TRIPLET}-rel")
vcpkg_execute_required_process(
COMMAND ${CMAKE_COMMAND} --build . --config Release ${TARGET_PARAM} -- ${BUILD_ARGS}
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
LOGNAME ${_bc_LOGFILE_ROOT}-${TARGET_TRIPLET}-rel
)
message(STATUS "Build ${TARGET_TRIPLET}-rel done")
if(_bc_DISABLE_PARALLEL)
set(PARALLEL_ARG ${NO_PARALLEL_ARG})
endif()

if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
message(STATUS "Build ${TARGET_TRIPLET}-dbg")
vcpkg_execute_required_process(
COMMAND ${CMAKE_COMMAND} --build . --config Debug ${TARGET_PARAM} -- ${BUILD_ARGS}
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg
LOGNAME ${_bc_LOGFILE_ROOT}-${TARGET_TRIPLET}-dbg
)
message(STATUS "Build ${TARGET_TRIPLET}-dbg done")
endif()
foreach(BUILDTYPE "release" "debug")
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL BUILDTYPE)
if(BUILDTYPE STREQUAL "debug")
set(SHORT_BUILDTYPE "dbg")
else()
set(SHORT_BUILDTYPE "rel")
endif()

message(STATUS "Build ${TARGET_TRIPLET}-${SHORT_BUILDTYPE}")
set(LOGPREFIX "${CURRENT_BUILDTREES_DIR}/${_bc_LOGFILE_ROOT}-${TARGET_TRIPLET}-${SHORT_BUILDTYPE}")
set(LOGS)

if(BUILDTYPE STREQUAL "release")
set(CONFIG "Release")
else()
set(CONFIG "Debug")
endif()

execute_process(
COMMAND ${CMAKE_COMMAND} --build . --config Release ${TARGET_PARAM} -- ${BUILD_ARGS} ${PARALLEL_ARG}
OUTPUT_FILE "${LOGPREFIX}-out.log"
ERROR_FILE "${LOGPREFIX}-err.log"
RESULT_VARIABLE error_code
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${SHORT_BUILDTYPE})
if(error_code)
file(READ "${LOGPREFIX}-out.log" out_contents)
file(READ "${LOGPREFIX}-err.log" err_contents)

if(out_contents)
list(APPEND LOGS "${LOGPREFIX}-out.log")
endif()
if(err_contents)
list(APPEND LOGS "${LOGPREFIX}-err.log")
endif()

if(out_contents MATCHES "LINK : fatal error LNK1102:" OR out_contents MATCHES " fatal error C1060: ")
# The linker ran out of memory during execution. We will try continuing once more, with parallelism disabled.
execute_process(
COMMAND ${CMAKE_COMMAND} --build . --config Release ${TARGET_PARAM} -- ${BUILD_ARGS} ${NO_PARALLEL_ARG}
OUTPUT_FILE "${LOGPREFIX}-out-1.log"
ERROR_FILE "${LOGPREFIX}-err-1.log"
RESULT_VARIABLE error_code
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${SHORT_BUILDTYPE})

if(error_code)
file(READ "${LOGPREFIX}-out-1.log" out_contents)
file(READ "${LOGPREFIX}-err-1.log" err_contents)

if(out_contents)
list(APPEND LOGS "${LOGPREFIX}-out-1.log")
endif()
if(err_contents)
list(APPEND LOGS "${LOGPREFIX}-err-1.log")
endif()
endif()
endif()

if(error_code)
set(STRINGIFIED_LOGS)
foreach(LOG ${LOGS})
file(TO_NATIVE_PATH "${LOG}" NATIVE_LOG)
list(APPEND STRINGIFIED_LOGS " ${NATIVE_LOG}\n")
endforeach()
set(_eb_COMMAND ${CMAKE_COMMAND} --build . --config Release ${TARGET_PARAM} -- ${BUILD_ARGS} ${NO_PARALLEL_ARG})
set(_eb_WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${SHORT_BUILDTYPE})
message(FATAL_ERROR
" Command failed: ${_eb_COMMAND}\n"
" Working Directory: ${_eb_WORKING_DIRECTORY}\n"
" See logs for more information:\n"
${STRINGIFIED_LOGS})
endif()
endif()
message(STATUS "Build ${TARGET_TRIPLET}-${SHORT_BUILDTYPE} done")
endif()
endforeach()
endfunction()
28 changes: 20 additions & 8 deletions scripts/cmake/vcpkg_execute_required_process.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,34 @@
## * [qt5](https://github.com/Microsoft/vcpkg/blob/master/ports/qt5/portfile.cmake)
function(vcpkg_execute_required_process)
cmake_parse_arguments(vcpkg_execute_required_process "" "WORKING_DIRECTORY;LOGNAME" "COMMAND" ${ARGN})
#debug_message("vcpkg_execute_required_process(${vcpkg_execute_required_process_COMMAND})")
set(LOG_OUT "${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-out.log")
set(LOG_ERR "${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-err.log")
execute_process(
COMMAND ${vcpkg_execute_required_process_COMMAND}
OUTPUT_FILE ${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-out.log
ERROR_FILE ${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-err.log
OUTPUT_FILE ${LOG_OUT}
ERROR_FILE ${LOG_ERR}
RESULT_VARIABLE error_code
WORKING_DIRECTORY ${vcpkg_execute_required_process_WORKING_DIRECTORY})
#debug_message("error_code=${error_code}")
if(error_code)
file(TO_NATIVE_PATH "${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-out.log" NATIVE_LOG_OUT)
file(TO_NATIVE_PATH "${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-err.log" NATIVE_LOG_ERR)
set(LOGS)
file(READ "${LOG_OUT}" out_contents)
file(READ "${LOG_ERR}" err_contents)
if(out_contents)
list(APPEND LOGS "${LOG_OUT}")
endif()
if(err_contents)
list(APPEND LOGS "${LOG_ERR}")
endif()
set(STRINGIFIED_LOGS)
foreach(LOG ${LOGS})
file(TO_NATIVE_PATH "${LOG}" NATIVE_LOG)
list(APPEND STRINGIFIED_LOGS " ${NATIVE_LOG}\n")
endforeach()
message(FATAL_ERROR
" Command failed: ${vcpkg_execute_required_process_COMMAND}\n"
" Working Directory: ${vcpkg_execute_required_process_WORKING_DIRECTORY}\n"
" See logs for more information:\n"
" ${NATIVE_LOG_OUT}\n"
" ${NATIVE_LOG_ERR}\n")
${STRINGIFIED_LOGS}
)
endif()
endfunction()
14 changes: 9 additions & 5 deletions scripts/cmake/vcpkg_fixup_cmake_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
#

function(vcpkg_fixup_cmake_targets)
cmake_parse_arguments(_vfct "" "CONFIG_PATH" "" ${ARGN})
cmake_parse_arguments(_vfct "" "CONFIG_PATH;TARGET_PATH" "" ${ARGN})

if(_vfct_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "vcpkg_fixup_cmake_targets was passed extra arguments: ${_vfct_UNPARSED_ARGUMENTS}")
endif()

set(DEBUG_SHARE ${CURRENT_PACKAGES_DIR}/debug/share/${PORT})
set(RELEASE_SHARE ${CURRENT_PACKAGES_DIR}/share/${PORT})
if(NOT _vfct_TARGET_PATH)
set(_vfct_TARGET_PATH share/${PORT})
endif()

set(DEBUG_SHARE ${CURRENT_PACKAGES_DIR}/debug/${_vfct_TARGET_PATH})
set(RELEASE_SHARE ${CURRENT_PACKAGES_DIR}/${_vfct_TARGET_PATH})

if(_vfct_CONFIG_PATH AND NOT RELEASE_SHARE STREQUAL "${CURRENT_PACKAGES_DIR}/${_vfct_CONFIG_PATH}")
set(DEBUG_CONFIG ${CURRENT_PACKAGES_DIR}/debug/${_vfct_CONFIG_PATH})
Expand Down Expand Up @@ -114,7 +118,7 @@ function(vcpkg_fixup_cmake_targets)
string(REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \"]+\\.exe)" "\${_IMPORT_PREFIX}/tools/${PORT}/\\1" _contents "${_contents}")
string(REPLACE "\${_IMPORT_PREFIX}/lib" "\${_IMPORT_PREFIX}/debug/lib" _contents "${_contents}")
string(REPLACE "\${_IMPORT_PREFIX}/bin" "\${_IMPORT_PREFIX}/debug/bin" _contents "${_contents}")
file(WRITE ${CURRENT_PACKAGES_DIR}/share/${PORT}/${DEBUG_TARGET_NAME} "${_contents}")
file(WRITE ${CURRENT_PACKAGES_DIR}/${_vfct_TARGET_PATH}/${DEBUG_TARGET_NAME} "${_contents}")

file(REMOVE ${DEBUG_TARGET})
endforeach()
Expand Down Expand Up @@ -148,7 +152,7 @@ function(vcpkg_fixup_cmake_targets)
file(WRITE ${MAIN_CONFIG} "${_contents}")
endforeach()

# Remove /debug/share/<port>/ if it's empty.
# Remove /debug/<target_path>/ if it's empty.
file(GLOB_RECURSE REMAINING_FILES "${DEBUG_SHARE}/*")
if(NOT REMAINING_FILES)
file(REMOVE_RECURSE ${DEBUG_SHARE})
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace vcpkg::System
nullptr,
nullptr,
FALSE,
BELOW_NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT,
IDLE_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT,
env_cstr.data(),
nullptr,
&startup_info,
Expand Down

0 comments on commit cf80234

Please sign in to comment.