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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ deps/

.DS_Store
android-toolchain-arm/
cc-toolchain/
4 changes: 4 additions & 0 deletions Build/android_toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ $1/build/tools/make-standalone-toolchain.sh \
--install-dir=$TOOLCHAIN \
--platform=$ANDROID_TARGET --force

# use system python
rm $TOOLCHAIN/bin/python

# keep cmake from using system ranlib
cp android-toolchain-arm/bin/arm-linux-androideabi-ranlib android-toolchain-arm/bin/ranlib
122 changes: 122 additions & 0 deletions Build/compile_clang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/bash
#-------------------------------------------------------------------------------------------------------
# Copyright (C) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
#-------------------------------------------------------------------------------------------------------

LLVM_VERSION="3.9.1"

CC_URL="git://sourceware.org/git/binutils-gdb.git\nhttp://llvm.org/releases/${LLVM_VERSION}/\n"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo -e "\n----------------------------------------------------------------"
echo -e "\nThis script will download LLVM/CLANG and LLVM Gold Bintools from\n${CC_URL}\n"
echo "These software are licensed to you by its publisher(s), not Microsoft."
echo "Microsoft is not responsible for the software."
echo "Your installation and use of the software is subject to the publisher’s terms available here:"
echo -e "http://llvm.org/docs/DeveloperPolicy.html#license\nhttp://llvm.org/docs/GoldPlugin.html#licensing\n"
echo -e "----------------------------------------------------------------\n"
echo "If you don't agree, press Ctrl+C to terminate"
read -t 10 -p "Hit ENTER to continue (or wait 10 seconds)"

echo -e "\nThis will take some time... [and free memory 2GB+]\n"

ROOT=${PWD}/cc-toolchain/
GOLD_PLUGIN=""

if [ ! -d ./cc-toolchain/src/llvm/projects/compiler-rt ]; then
rm -rf cc-toolchain
mkdir cc-toolchain
cd cc-toolchain
mkdir src
mkdir bin
cd src

apt-get -v >/dev/null 2>&1
if [ $? == 0 ]; then # debian
sudo apt-get install -y apt-file texinfo texi2html csh gawk automake libtool libtool-bin bison flex libncurses5-dev
if [ $? != 0 ]; then
exit 1
fi
else
yum -v >/dev/null 2>&1
if [ $? == 0 ]; then # redhat
yum install -y texinfo texi2html csh gawk automake libtool libtool-bin bison flex ncurses-devel
else
echo "This script requires (texinfo texi2html csh gawk automake libtool libtool-bin bison flex ncurses-devel)"
echo "Automated installation of these requirements is supported with apt-get and yum only."
echo ""
echo "If you don't have these packages are installed, press Ctrl+C to terminate"
read -t 10 -p "Hit ENTER to continue (or wait 10 seconds)"
fi
fi

mkdir lto_utils
cd lto_utils
echo "Downloading LLVM Gold Plugin"
git clone --depth 1 git://sourceware.org/git/binutils-gdb.git binutils >/dev/null 2>&1
mkdir binutils_compile; cd binutils_compile
../binutils/configure --enable-gold --enable-plugins --disable-werror --prefix="${ROOT}/build"
make -j2
make install
if [ $? != 0 ]; then
exit 1
fi

echo -e "\n\n\n\n"
cd "${ROOT}/src/"

echo "Downloading LLVM ${LLVM_VERSION}"
wget –quiet "http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz" >/dev/null 2>&1
tar -xf "llvm-${LLVM_VERSION}.src.tar.xz"
if [ $? == 0 ]; then
rm "llvm-${LLVM_VERSION}.src.tar.xz"
mv "llvm-${LLVM_VERSION}.src" llvm
else
exit 1
fi

cd llvm/tools/
echo "Downloading Clang ${LLVM_VERSION}"
wget –quiet "http://llvm.org/releases/${LLVM_VERSION}/cfe-${LLVM_VERSION}.src.tar.xz" >/dev/null 2>&1
tar -xf "cfe-${LLVM_VERSION}.src.tar.xz"
if [ $? == 0 ]; then
mv "cfe-${LLVM_VERSION}.src" clang
rm "cfe-${LLVM_VERSION}.src.tar.xz"
else
exit 1
fi

mkdir -p ../projects/
cd ../projects/
echo "Downloading Compiler-RT ${LLVM_VERSION}"
wget –quiet "http://llvm.org/releases/${LLVM_VERSION}/compiler-rt-${LLVM_VERSION}.src.tar.xz" >/dev/null 2>&1
tar -xf "compiler-rt-${LLVM_VERSION}.src.tar.xz"
if [ $? == 0 ]; then
mv "compiler-rt-${LLVM_VERSION}.src" compiler-rt
rm "compiler-rt-${LLVM_VERSION}.src.tar.xz"
else
exit 1
fi
fi

GOLD_PLUGIN=-DLLVM_BINUTILS_INCDIR="${ROOT}/src/lto_utils/binutils/include"

mkdir -p "${ROOT}/build"
cd "${ROOT}/src/llvm"
mkdir -p build_
cd build_

cmake ../ -DCMAKE_INSTALL_PREFIX="${ROOT}/build" -DCMAKE_BUILD_TYPE=Release ${GOLD_PLUGIN}

if [ $? != 0 ]; then
cd ..
rm -rf build_
mkdir build_
exit 1
fi

make -j4 install

if [ $? == 0 ]; then
echo -e "Done!\n./build.sh args are given below;\n\n"
echo "--cxx=${ROOT}/build/bin/clang++ --cc=${ROOT}/build/bin/clang"
fi
66 changes: 50 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ if(STATIC_LIBRARY_SH)
set(STATIC_LIBRARY 1)
endif()

if(CC_TARGETS_AMD64_SH)
set(CC_TARGETS_AMD64 1)
endif()

if(CC_TARGETS_X86_SH)
set(CC_TARGETS_X86 1)
set(CMAKE_SYSTEM_PROCESSOR "i386")
endif()

if(CC_TARGETS_ARM_SH)
if (CC_TARGETS_ARM_SH OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(CC_TARGETS_ARM 1)
add_definitions(-D_ARM_=1)
set(CMAKE_SYSTEM_PROCESSOR "armv7l")
else()
if(CC_TARGETS_AMD64_SH)
set(CC_TARGETS_AMD64 1)
endif()

if(CC_TARGETS_X86_SH)
set(CC_TARGETS_X86 1)
set(CMAKE_SYSTEM_PROCESSOR "i386")
endif()
endif()

unset(CC_TARGETS_ARM_SH CACHE)
Expand Down Expand Up @@ -62,6 +62,23 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CC_TARGET_OS_OSX 1)
endif()

if (ENABLE_CC_XPLAT_TRACE_SH)
unset(ENABLE_CC_XPLAT_TRACE_SH CACHE)
set(ENABLE_CC_XPLAT_TRACE 1)
if (CC_TARGET_OS_ANDROID)
add_definitions(-DTRACE_OUTPUT_TO_LOGCAT=1)
else()
add_definitions(-DTRACE_OUTPUT_TARGET_FILE=1)
endif()
add_definitions(-DENABLE_CC_XPLAT_TRACE=1)
add_compile_options(-finstrument-functions)
add_compile_options(-g)
add_compile_options(-ggdb)
if(NOT STATIC_LIBRARY)
message(FATAL_ERROR "Trace option is available only for --static builds")
endif()
endif()

if(CC_EMBED_ICU_SH)
unset(CC_EMBED_ICU_SH CACHE)
set(CC_EMBED_ICU 1)
Expand Down Expand Up @@ -289,12 +306,27 @@ if(CLR_CMAKE_PLATFORM_XPLAT)
endif()
endif(CLR_CMAKE_PLATFORM_XPLAT)

if(ENABLE_FULL_LTO_SH)
unset(DENABLE_FULL_LTO_SH CACHE)
add_compile_options(-flto)
elseif(ENABLE_THIN_LTO_SH)
unset(ENABLE_THIN_LTO_SH CACHE)
add_compile_options(-flto=thin)
if (ENABLE_FULL_LTO_SH OR ENABLE_THIN_LTO_SH)
if (CC_TARGET_OS_LINUX)
set(CC_LTO_ENABLED
-fuse-ld=gold
-Xlinker -plugin=${CHAKRACORE_BINARY_DIR}/../../cc-toolchain/build/lib/LLVMgold.so
)
endif()

if (ENABLE_FULL_LTO_SH)
unset(DENABLE_FULL_LTO_SH CACHE)
add_compile_options(-flto)
if (CC_LTO_ENABLED)
set(CC_LTO_ENABLED "${CC_LTO_ENABLED} -flto")
endif()
elseif (ENABLE_THIN_LTO_SH)
unset(ENABLE_THIN_LTO_SH CACHE)
add_compile_options(-flto=thin)
if (CC_LTO_ENABLED)
set(CC_LTO_ENABLED "${CC_LTO_ENABLED} -flto=thin")
endif()
endif()
endif()

if(CMAKE_BUILD_TYPE STREQUAL Debug)
Expand All @@ -312,6 +344,8 @@ endif(CMAKE_BUILD_TYPE STREQUAL Debug)

if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
add_compile_options(-O3)
else()
add_compile_options(-O0)
endif(NOT CMAKE_BUILD_TYPE STREQUAL Debug)

if(IS_64BIT_BUILD)
Expand Down
7 changes: 6 additions & 1 deletion bin/ChakraCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ set(lib_target "${lib_target}"
if(CC_TARGET_OS_ANDROID OR CC_TARGET_OS_LINUX)
set(lib_target "${lib_target}"
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
# reduce link time memory usage
-Xlinker --no-keep-memory
)
elseif(CC_TARGET_OS_OSX)
if(CC_TARGETS_X86)
Expand All @@ -62,7 +64,10 @@ elseif(CC_TARGET_OS_OSX)
endif()
endif()

target_link_libraries (ChakraCore ${lib_target})
target_link_libraries (ChakraCore
${lib_target}
${CC_LTO_ENABLED}
)

if(NOT CC_XCODE_PROJECT)
set(CC_LIB_EXT "so")
Expand Down
1 change: 1 addition & 0 deletions bin/GCStress/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(lib_target "${lib_target}"
Chakra.Pal
Chakra.Jsrt
${LINKER_END_GROUP}
${CC_LTO_ENABLED}
)

target_link_libraries (GCStress ${lib_target})
7 changes: 6 additions & 1 deletion bin/ch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ endif()
if(CC_TARGET_OS_ANDROID OR CC_TARGET_OS_LINUX)
set(lib_target "${lib_target}"
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/ch.version
# reduce link time memory usage
-Xlinker --no-keep-memory
)
elseif(CC_TARGET_OS_OSX)
if(CC_TARGETS_X86)
Expand All @@ -97,7 +99,10 @@ elseif(CC_TARGET_OS_OSX)
endif()


target_link_libraries (ch ${lib_target})
target_link_libraries (ch
${lib_target}
${CC_LTO_ENABLED}
)

if(NOT CC_XCODE_PROJECT)
# Add a post build event to the ch target
Expand Down
11 changes: 2 additions & 9 deletions bin/ch/ChakraRtInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,8 @@ bool ChakraRTInterface::LoadChakraDll(ArgInfo* argInfo, HINSTANCE *outLibrary)
#ifndef CHAKRA_STATIC_LIBRARY
HINSTANCE library = nullptr;

char filename[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];

char modulename[_MAX_PATH];
GetModuleFileNameA(NULL, modulename, _MAX_PATH);
_splitpath_s(modulename, drive, _MAX_DRIVE, dir, _MAX_DIR, nullptr, 0, nullptr, 0);
_makepath_s(filename, drive, dir, chakraDllName, nullptr);
LPCSTR dllName = filename;
char dllName[_MAX_PATH];
GetBinaryPathWithFileNameA(dllName, _MAX_PATH, chakraDllName);

library = LoadChakraCore(dllName);
*outLibrary = library;
Expand Down
Loading